Skip to content

Git diff pathspec missing -- #1931

@kitserve

Description

@kitserve

I've been hitting an issue where:

repo = git.Repo('path/to/repo')
for commit in repo.iter_commits():
	if len(commit.parents) == 0:
		previous_commit = None
	else:
		previous_commit = commit.parents[0].tree
	for file in commit.stats.files:
		status = repo.git.diff('--name-status', previous_commit, file)

keeps blowing up with an exception along the lines of:

git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git diff --name-status fea6f08304c7e01f3dae87947901eee1fcba55eb example.txt
  stderr: 'fatal: ambiguous argument 'example.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]''

I've had to work around it with a raw command that includes the -- argument like:

status = repo.git.diff('--name-status', previous_commit.hexsha, '--', file)

This seems related to #1061. Looking at

args.append("--")

it seems there the code is attempting to add the -- argument before the pathspec, but it's not working. I'm not sure if this is me doing something wrong or a genuine bug, but either way I think I either the documentation or the code needs updating to address this issue.

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