This repository was archived by the owner on Sep 11, 2020. It is now read-only.
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
Description
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
.