Closed
Description
If Repository.Log
is run with the FileName
option, and the file is added as the first commit in the repository, the commit affecting that file will not be processed.
The following snippet reproduces the issue:
package main
import (
"fmt"
"path/filepath"
"io/ioutil"
git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
)
func main() {
dir, _ := ioutil.TempDir("", "repo")
repo, _ := git.PlainInit(dir, false)
w, err := repo.Worktree()
if err != nil {
panic(err)
}
// If uncommented, the log result for file a.txt will be non-empty.
/*
ioutil.WriteFile(filepath.Join(dir, "b.txt"), []byte("abcd"), 0644)
w.Add("b.txt")
w.Commit("pre-initial commit", &git.CommitOptions{})
*/
ioutil.WriteFile(filepath.Join(dir, "a.txt"), []byte("abcd"), 0644)
w.Add("a.txt")
w.Commit("initial commit", &git.CommitOptions{})
pth := "a.txt"
commits, err := repo.Log(&git.LogOptions{FileName: &pth, All: true})
if err != nil {
panic(err)
}
err = commits.ForEach(func(c *object.Commit) error {
fmt.Println(c.Hash.String()) // This will not be called.
return nil
})
if err != nil {
panic(err)
}
}
Metadata
Metadata
Assignees
Labels
Something isn't workingSomething isn't workingGood for newcomersGood for newcomersExtra attention is neededExtra attention is needed