8000 git blame panic: contents and commits have different length · Issue #603 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content
git blame panic: contents and commits have different length #603
@williamfzc

Description

@williamfzc
func TestAA(t *testing.T) {
	abs, _ := filepath.Abs("F:\\workspace\\github\\go-git")
	repo, err := git.PlainOpen(abs)
	if err != nil {
		panic(err)
	}
	head, err := repo.Head()
	if err != nil {
		panic(err)
	}
	targetCommit, err := repo.CommitObject(head.Hash())
	if err != nil {
		panic(err)
	}

	_, err = git.Blame(targetCommit, "remote.go")
	if err != nil {
                // PANIC!!!
		panic(err)
	}
}

panic happened when calling git.Blame

panic: contents and commits have different length [recovered]
	panic: contents and commits have different length

It will happened also in work_tree_test.go.
Looks like it can not handle extra empty line at the end of file.

In git blame:

image

But actually:

image

Tested on Windows and WSL.

guess

func newLines(contents []string, commits []*object.Commit) ([]*Line, error) {
	lcontents := len(contents)
	lcommits := len(commits)

	if lcontents != lcommits {
		fmt.Printf("c vs c: %d, %d", lcontents, lcommits)
...

Output:

=== RUN   TestAA
c vs c: 1430, 1397--- FAIL: TestAA (1.97s)

lcommits seems not correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0