Skip to content

Diff shows a_path even though the file is added #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ishepard opened this issue Apr 20, 2018 · 3 comments
Open

Diff shows a_path even though the file is added #749

ishepard opened this issue Apr 20, 2018 · 3 comments

Comments

@ishepard
Copy link
Contributor

ishepard commented Apr 20, 2018

When a file is added, I think that a_path should be None and b_path should be equal to the name of the added file. This is the case when we create a diff setting create_patch=True. However, since by default this is False, diff returns a_path and b_path equals to the name of the added file. If you want to test it:

mkdir test
cd test
git init
touch asd.txt
git add asd.txt
git commit -m "add asd"
cd ..
import git
repo = git.Repo('test/')
diffs = repo.head.commit.diff(git.NULL_TREE)
for diff in diffs:
    print(diff.a_path)
    print(diff.b_path)
    print(diff.change_type)

this will return the following output:

asd.txt
asd.txt
A

how is it possible that, if the file is added, a_path is not None?

PS: this works also if the previous commit is not NULL_TREE, already tried.

@Byron
Copy link
Member

Byron commented Jun 5, 2018

Thanks a lot for letting us know, I just reproduced the issue!
This is not the first issue discovered related to the diffing logic/code.

@vidartf
Copy link

vidartf commented Aug 2, 2019

Note that this behavior is currently contrary to the documentation: https://gitpython.readthedocs.io/en/stable/reference.html#git.diff.Diff This lead to quite a bit of confusion for us when trying to use this function.

@Byron
Copy link
Member

Byron commented Aug 12, 2019

@vidartf Thanks for letting me know! Maybe you can find the time to provide a PR adjusting the docs so that it becomes what you would have wanted to see. Generally, the diff implementation is confusing to many, and I am not quite sure if it's the API itself, the docs, or an incorrect implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants