Skip to content

plumbing: object, Make first commit visible on logs filtered with filename. Fixes #191 #1036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plumbing/object/commit_walker_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func (c *commitPathIter) hasFileChange(changes Changes, parent *Commit) bool {

// filename matches, now check if source iterator contains all commits (from all refs)
if c.checkParent {
if parent != nil && isParentHash(parent.Hash, c.currentCommit) {
// Check if parent is beyond the initial commit
if parent == nil || isParentHash(parent.Hash, c.currentCommit) {
return true
}
continue
Expand Down
26 changes: 26 additions & 0 deletions plumbing/object/commit_walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,29 @@ func (s *CommitWalkerSuite) TestCommitBSFIteratorWithIgnore(c *C) {
c.Assert(commit.Hash.String(), Equals, expected[i])
}
}

func (s *CommitWalkerSuite) TestCommitPathIteratorInitialCommit(c *C) {
commit := s.commit(c, plumbing.NewHash(s.Fixture.Head))

fileName := "LICENSE"

var commits []*Commit
NewCommitPathIterFromIter(
func(path string) bool { return path == fileName },
NewCommitIterCTime(commit, nil, nil),
true,
).ForEach(func(c *Commit) error {
commits = append(commits, c)
return nil
})

expected := []string{
"b029517f6300c2da0f4b651b8642506cd6aaf45d",
}

c.Assert(commits, HasLen, len(expected))

for i, commit := range commits {
c.Assert(commit.Hash.String(), Equals, expected[i])
}
}