Skip to content

Git blame behavior when file is not added to git #178

@MarkRx

Description

@MarkRx

Version

7.3.0.202506031305-r, 5.6.0.201912101111-r

Operating System

Windows

Bug description

If a file is within the git workspace but not added to git then git blame with the CLI will throw an error:

$ git status
On branch master
Untracked files:
(use "git add ..." to include in what will be committed)
foo.txt

nothing added to commit but untracked files present (use "git add" to track)

$ git blame foo.txt
fatal: no such path 'foo.txt' in HEAD

JGit returns null in this case. Perhaps this should be an exception?

import java.io.File

import org.eclipse.jgit.lib.RepositoryBuilder
import org.eclipse.jgit.api.Git

def repo = new RepositoryBuilder().setWorkTree(new File("$projectDir")).setMustExist(true).build()

def git = new Git(repo)
def blameCommand = git.blame()
blameCommand.setFilePath("foo.txt")
def res = blameCommand.call()

println(res)

Actual behavior

In jgit 5.5.1.201910021850-r a BlameResult was returned with a the file showing up as new
In jgit 5.6.0.201912101111-r and above the behavior changed and null is returned

Expected behavior

Either

  1. An exception is thrown (since git CLI treats this as an error)
  2. The meaning of a null result is explicitly documented

Relevant log output

Other information

No response

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