8000 Filtering logs with filename fails if the file is altered in the first commit in the repository. · Issue #191 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content
Filtering logs with filename fails if the file is altered in the first commit in the repository. #191
Closed
@tasdomas

Description

@tasdomas

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

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0