You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
@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?
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)
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.
The text was updated successfully, but these errors were encountered: