Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Worktree if support add deleted files #1268

Open
magicalcosmos opened this issue Dec 25, 2019 · 2 comments
Open

Worktree if support add deleted files #1268

magicalcosmos opened this issue Dec 25, 2019 · 2 comments

Comments

@magicalcosmos
Copy link

Hi there,

I removed files by os.RemoveAll and then add, but that's didn't work, the code as belows:

//remove local files
os.RemoveAll(path) 

// add files, prepare commit and push
repo, err := git.PlainOpen(repository)
if err != nil {
	log.Logger.Debug("fail to init repository", zap.Error(err))
	return err
}
wt, _:= repo.Worktree()
_, err = wt.Add(".")
if err != nil {
	return err
}

What's wrong with that code, any suggestions?

@aRestless
Copy link

I think I just ran into the same issue. The problem is the implementation of Worktree.doAddDirectory: https://github.com/src-d/go-git/blob/master/worktree_status.go#L299

Add only iterates through files existing on the file system. It will therefore not stage any removed files.

@indeedhat
Copy link

I have come across the same problem, until this is fixed i have come up with the following dirty hack solution

cmd := exec.Command("git", "add", ".")
cmd.Dir = workTree.Filesystem.Root()
err = cmd.Run()

Its not pretty but it works

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants