Beispiel #1
0
func (c *GitDivertBeginCmd) Run(args ...string) (err error) {
	logx.Debugf("beginning covert op %s", args)

	if len(args) == 0 {
		err = fmt.Errorf("no branch")
		return
	}

	branch := args[0]
	names := args[1:]

	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}
	divert := git.NewDivert(mod.Git)
	var spec git.DivertSpec
	if spec, err = divert.PrepareBegin(branch, names...); err != nil {
		return
	}

	if err = divert.Begin(spec); err == nil {
		return
	}

	return
}
Beispiel #2
0
func (c *GitDivertFinishCmd) Run(args ...string) (err error) {
	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}

	divert := git.NewDivert(mod.Git)
	isInProgress, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if !isInProgress {
		err = fmt.Errorf("diversion is not in progress")
	}

	spec, err := divert.ReadSpec()
	if err != nil {
		return
	}
	if err = divert.Commit(spec, c.Message); err != nil {
		return
	}

	err = divert.Cleanup(spec)

	return
}
Beispiel #3
0
func (c *GitCleanCmd) Run(args ...string) (err error) {
	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)

	var name string
	if len(args) > 0 {
		name = args[0]
	}

	// check divert
	divert := git.NewDivert(mod.Git)
	isInProgress, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if isInProgress {
		var spec git.DivertSpec
		if spec, err = divert.ReadSpec(); err != nil {
			return
		}
		var exists bool
		for _, n := range spec.TargetFiles {
			if n == name {
				exists = true
				break
			}
		}
		if !exists {
			err = fmt.Errorf("wan't clean non-target file %s while divert in progress", name)
			return
		}
	}

	s, err := mod.GetManifest(name, c.Stdin)
	if err != nil {
		return
	}

	logx.Debugf("%s %s", name, s.ID)

	if c.Id {
		fmt.Fprintf(c.Stdout, "%s", s.ID)
	} else {
		err = s.Serialize(c.Stdout)
	}
	return
}
Beispiel #4
0
func (c *GitPreCommitCmd) Run(args ...string) (err error) {
	var filenames []string
	var mod *model.Model
	if mod, err = model.New(c.WD, true, c.ChunkSize, c.PoolSize); err != nil {
		return
	}

	// In divert we need restrict check by target filenames
	divert := git.NewDivert(mod.Git)
	isInDivert, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if isInDivert {
		var spec git.DivertSpec
		if spec, err = divert.ReadSpec(); err != nil {
			return
		}
		filenames = spec.TargetFiles
	}

	isDirty, dirty, err := mod.Check(filenames...)
	if err != nil {
		return
	}
	if isDirty {
		err = fmt.Errorf("dirty files in working tree %s", dirty)
		return
	}

	feedR, err := mod.Git.Diff(filenames...)
	if err != nil {
		return
	}

	blobs, err := mod.Git.ManifestsFromDiff(feedR)
	if err != nil {
		return
	}

	trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize)
	err = trans.Upload(blobs)

	return
}
Beispiel #5
0
func (c *GitDivertStatusCmd) Run(args ...string) (err error) {
	mod, err := model.New(c.WD, true, c.ChunkSize, c.PoolSize)
	if err != nil {
		return
	}

	divert := git.NewDivert(mod.Git)
	isInProgress, err := divert.IsInProgress()
	if err != nil {
		return
	}
	if !isInProgress {
		fmt.Fprintln(c.Stdout, "divert not in progress")
	}
	spec, err := divert.ReadSpec()
	if err != nil {
		return
	}
	fmt.Fprintln(c.Stdout, "DIVERT IN PROGRESS")
	fmt.Fprintln(c.Stdout, spec)

	return
}
Beispiel #6
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)
}