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

Worktree.Add results in "invalid object" in (classical) git commit #427

Closed
osklyar opened this issue Jun 14, 2017 · 2 comments
Closed

Worktree.Add results in "invalid object" in (classical) git commit #427

osklyar opened this issue Jun 14, 2017 · 2 comments
Labels

Comments

@osklyar
Copy link

osklyar commented Jun 14, 2017

I am working on a CLI tool that uses go-git to wrap git operations. Among other I have the following code that implements the add operation (error handling removed here for simplicity):

func simpleAdd(target string, re *regexp.Regexp, w io.Writer) error {
	repo, err := git.PlainOpen(target)
	wt, err := repo.Worktree()
	status, err := wt.Status()
	for p, s := range status {
		if s.Worktree != git.Unmodified && re.Match([]byte(p)) {
			_, err := wt.Add(p)
			fmt.Fprintf(w, "➜ added %c %s\n", s.Worktree, p)
		}
	}
	return nil
}

Invoking this method using the CLI tool followed by git commit using the classical git tool results in the following error:

#  geat git:(master) ✗ geat status
➜ in . the state is modified on branch master (origin: [email protected]:silvertern/geat)
  unstaged:
    M Gopkg.toml

#  geat git:(master) ✗ geat add Gopkg.toml 
➜ added M Gopkg.toml
#  geat git:(master) ✗ geat status
➜ in . the state is modified on branch master (origin: [email protected]:silvertern/geat)
  staged:
    M Gopkg.toml

#  geat git:(master) ✗ git commit -m "Updates go-git revision"
error: invalid object 100644 fe4aec059f97826820d4bf7f4208b7d2f76ee906 for 'Gopkg.toml'
error: invalid object 100644 fe4aec059f97826820d4bf7f4208b7d2f76ee906 for 'Gopkg.toml'
error: Error building trees

Am I doing anything wrong in the above Add code?

To reproduce have any git repo with a change then do:

mkdir -p ${GOPATH}/src/github.com/silvertern
cd ${GOPATH}/src/github.com/silvertern
git clone https://github.com/silvertern/geat
cd geat
dep ensure # latest dep from master
go install

now cd to your repo with a change and do geat add . followed by git commit.

@mcuadros mcuadros added the bug label Jun 18, 2017
@mcuadros
Copy link
Contributor

Yep, I confirm the issue, Worktree.Add is bad implemented, should add the object to the storage, but this is being done at Worktree.Commit. I will do a PR in a few days.

@osklyar
Copy link
Author

osklyar commented Jun 18, 2017

@mcuadros Brilliant, can't wait for it :)

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

No branches or pull requests

2 participants