Skip to content

When diffing index 'HEAD', can't get 'A' change_type but 'D' #531

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
KMilhan opened this issue Oct 14, 2016 · 3 comments
Closed

When diffing index 'HEAD', can't get 'A' change_type but 'D' #531

KMilhan opened this issue Oct 14, 2016 · 3 comments

Comments

@KMilhan
Copy link

KMilhan commented Oct 14, 2016

So, this issue is about

git diff HEAD

I tried several times doing repo.index.diff('HEAD') on modified or on added files. On modified files it worked like charm. But on new files, gitPython doesn't return diff with change_type=='A' but 'D'.

I tried on gitpython 2.0.8 with python3 on Linux, and 2.0.9.dev(pyPI ver) on Windows 7. Resulted same.

here's what i did

milhankim@LGESELMil:~/sandbox/docker$ touch add_test && git add add_test && ipython3
Python 3.5.2+ (default, Sep 22 2016, 12:18:14) 

In [1]: import git

In [2]: repo = git.Repo('.')

In [3]: repo.index.diff('HEAD')
Out[3]: [<git.diff.Diff at 0x7ffbd021a268>]

In [4]: repo.index.diff('HEAD')[0].change_type
Out[4]: 'D'

In [5]: repo.index.diff('HEAD')[0].new_file
Out[5]: False

In [6]: repo.index.diff('HEAD')[0].deleted_file
Out[6]: True

milhankim@LGESELMil:~/sandbox/docker$ git diff HEAD
diff --git a/add_test b/add_test
new file mode 100644
index 0000000..e69de29
@Byron
Copy link
Member

Byron commented Oct 16, 2016

To me it seems like the order is merely inverted. What does it say if you invert the arguments, like so:

r.head.commit.diff(git.IndexFile.Index)

@KMilhan
Copy link
Author

KMilhan commented Oct 17, 2016

Thank you for quick response Byron.

Like you said, inverting the order worked for me.

In [3]: repo.head.commit.diff(git.IndexFile.Index)
Out[3]: [<git.diff.Diff at 0x7f9caa2a71e0>]

In [4]: repo.head.commit.diff(git.IndexFile.Index)[0].change_type
Out[4]: 'A'

I'm closing this issue because it's not a bug

It turned out that I trusted my intuition more than gitPython's intention. :(
I guess I'll be writing a simple function to shorten that.

@nantiferov
Copy link

Just to help anyone having the same problem, reverting order means to add R=True to diff function, like repo.index.diff("HEAD", R=True)

Found in another issue #882 (comment)

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

No branches or pull requests

3 participants