Beispiel #1
0
func gitFixture(tree *fixtures.Tree) (res *git.Git, err error) {
	res = &git.Git{lists.NewMapper(tree.CWD, tree.CWD)}
	if _, err = res.Run("init"); err != nil {
		return
	}
	if _, err = res.Run("add", "-A"); err != nil {
		return
	}
	if _, err = res.Run("commit", "-m", "master1"); err != nil {
		return
	}
	if _, err = res.Run("checkout", "-b", "other"); err != nil {
		return
	}
	os.MkdirAll(filepath.Join(tree.CWD, "in-other"), 0755)
	fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "in-other", "blob.bin"), 1670)
	fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "one", "file-one.bin"), 170)
	fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "two", "file-four with spaces.bin"), 170)
	if _, err = res.Run("add", "-A"); err != nil {
		return
	}
	if _, err = res.Run("commit", "-m", "other1"); err != nil {
		return
	}
	if _, err = res.Run("checkout", "master"); err != nil {
		return
	}
	return
}
Beispiel #2
0
func Test_Git_DiffFiles(t *testing.T) {
	tree := fixtures.NewTree("Git_DiffFiles", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()
	g, err := gitFixture(tree)
	assert.NoError(t, err)

	fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "in-other", "blob.bin"), 10)
	fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "two", "file-four with spaces.bin"), 110)
	dirty, err := g.DiffFiles(
		filepath.Join("in-other", "blob.bin"),
		filepath.Join("two", "file-four with spaces.bin"),
	)
	assert.NoError(t, err)
	assert.Equal(t, []string{"two/file-four with spaces.bin"}, dirty)
}
Beispiel #3
0
func Test_Git_Divert1(t *testing.T) {

	tree := fixtures.NewTree("Git_divert", "")
	assert.NoError(t, tree.Populate())
	defer tree.Squash()

	g, err := gitFixture(tree)
	assert.NoError(t, err)

	//	logx.SetLevel(logx.TRACE)

	// get blobmap for further checks
	mod, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	names := lists.NewFileList().ListDir(tree.CWD)
	mans1, err := mod.FeedManifests(true, true, true, names...)
	assert.NoError(t, err)

	// Run divert on "in-other" and "one"
	divert := git.NewDivert(g)
	spec, err := divert.PrepareBegin("other", "in-other", "one", "two/file-four with spaces.bin")
	assert.NoError(t, err)
	err = divert.Begin(spec)
	assert.NoError(t, err)

	// Make two blobs and collect their manifests
	bn1 := filepath.Join(tree.CWD, "in-other", "blob.bin")
	bn2 := filepath.Join(tree.CWD, "one", "file-one.bin")
	fixtures.MakeNamedBLOB(bn1, 110)
	fixtures.MakeNamedBLOB(bn2, 200)

	oMan1, err := fixtures.NewShadowFromFile(bn1)
	assert.NoError(t, err)
	oMan2, err := fixtures.NewShadowFromFile(bn2)
	assert.NoError(t, err)

	// commit
	spec1, err := divert.ReadSpec()
	assert.NoError(t, err)

	err = divert.Commit(spec1, "from-master")
	assert.NoError(t, err)

	err = divert.Cleanup(spec1)
	assert.NoError(t, err)

	err = divert.CleanSpec()
	assert.NoError(t, err)

	// Final checks
	branch, _, err := g.GetBranches()
	assert.NoError(t, err)
	assert.Equal(t, "master", branch)

	// check master files
	names = lists.NewFileList().ListDir(tree.CWD)
	mans2, err := mod.FeedManifests(true, true, true, names...)
	assert.NoError(t, err)
	assert.EqualValues(t, mans1, mans2)

	// check stored branch
	err = g.Checkout("other")
	assert.NoError(t, err)

	oMan1p, err := fixtures.NewShadowFromFile(bn1)
	assert.NoError(t, err)
	assert.EqualValues(t, oMan1, oMan1p)

	oMan2p, err := fixtures.NewShadowFromFile(bn2)
	assert.NoError(t, err)
	assert.EqualValues(t, oMan2, oMan2p)
}