Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@tasdomas

Description

@tasdomas
Issue body actions

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 workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.