Skip to content

repo.index.diff( head ) show new file as deleted #423

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

Closed
barry-scott opened this issue May 5, 2016 · 4 comments
Closed

repo.index.diff( head ) show new file as deleted #423

barry-scott opened this issue May 5, 2016 · 4 comments
Assignees
Labels

Comments

@barry-scott
Copy link
Contributor

My goal is to use GitPython to get the same information that git status will return.

I'm using the examples from the Tutorial.

I have a test repo with the following status:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD ..." to unstage)

    new file:   World.txt

Untracked files:
(use "git add ..." to include in what will be committed)

I run this python using GitPython 2.0.2:

r = git.Repo( '/home/barry/wc/git/testrepo-a' )
print( 'Diff HEAD' )
for diff in r.index.diff( r.head.commit ):
for name in dir(diff):
if name[0] not in '_N':
print( ' %s: %r' % (name, getattr( diff, name )) )

And see this output:
Diff HEAD
a_blob: <git.Blob "df6ee5136ef5fd4a4ebdfef1ffce74bd0a71b514">
a_mode: 33188
a_path: 'World.txt'
b_blob: None
b_mode: 0
b_path: 'World.txt'
deleted_file: True
diff: ''
new_file: False
rename_from: None
rename_to: None
renamed: False

It seems that the diff in backwards: Iwould expect to see new_file: True. not deleted_file: True.

Where as a repo.index.diff( None ) seems to get old vs. new right.

@barry-scott
Copy link
Contributor Author

I think I understand why this is happening.

 repo.index.diff( HEAD ) is index(new) vs. HEAD(old)

but

repo.index.diff( None ) is index(old) vs. WorkingCopy(new)

Hence the meaning of new_file/deleted_file will reverse.

Might be worth pointing this out in the docs.

@Byron Byron self-assigned this May 19, 2016
@Byron Byron added the wont fix label May 19, 2016
@Byron
Copy link
Member

Byron commented May 19, 2016

Thanks for letting me know ! I did just try it myself, and could only come to the conclusion that it behaves as intended.
When comparing the index (with a new file) to the commit, it looks like the new file was removed. If you do it the other way around, as in repo.head.commit.diff(), which is equivalent to repo.head.commit.diff(git.Diffable.Index), which will show the new file as added.

However, I'd be happy to learn how you would improve the respective part of the documentation in order to make clearer what to expect.

Please note that I am closing the issue in the meanwhile as I believe a separate PR or issue is better suited to track possible documentation changes.

@Byron Byron closed this as completed May 19, 2016
@dudicoco
Copy link

@Byron just came across this weird behaviour myself. Using repo.head.commit.diff() does not show the change the other way around for me. Any suggestions?

Thanks

@dudicoco
Copy link

Managed to solve this:

diff = repo.commit('origin/HEAD').diff('HEAD')

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

No branches or pull requests

3 participants