Skip to content
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

Filtering logs with filename fails if the file is altered in the first commit in the repository. #191

Closed
tasdomas opened this issue Oct 21, 2020 · 1 comment · Fixed by #1036
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@tasdomas
Copy link

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)
	}
}
Copy link

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Dec 14, 2023
@pjbgf pjbgf added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed and removed stale Issues/PRs that are marked for closure due to inactivity labels Dec 15, 2023
onee-only added a commit to onee-only/go-git that referenced this issue Mar 1, 2024
onee-only added a commit to onee-only/go-git that referenced this issue Mar 5, 2024
pjbgf added a commit that referenced this issue Mar 6, 2024
plumbing: object, Make first commit visible on logs filtered with filename. Fixes #191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
2 participants