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
{{ message }}
Repository navigation
Comparing the difference between 2 RemoteReferences #1113
I have 2 RemoteReferences "refs/remotes/origin/main" and "refs/remotes/origin/debian". Comparing commits of those 2 RemoteReferences results in no difference. However, if I checkout the 2 branches main and debian and compare them, there are differences. Is this expected behavior? Does it mean that I should never rely on RemoteReferences for comparing differences of branches?
Could you show the code involving GitPython so I get an idea how you are trying to do it?
Diffing can be tricky, but is believed to be working. In the meantime, you can debug GitPython to learn which git commands are actually invoked.
Would you mind finding all the pieces in the referenced file and put it here in a single code block? Ideally that would be executable while in the repository mentioned in the issue itself.
The referenced file is a Jupyter/Lab notebook which is executable if you have Jupyter/Lab (a Python library) installed. It has code (both Python and Shell commands), output and comments all in one place so that it is easy to understand. Please let me know if you are unfamiliar with Jupyter/Lab notebook and still prefer a single code block here.
I can't execute and won't get into executing Jupyter Notebooks, but will take a look at code posted here. If that's not possible, Stackoverflow might be a better place to ask for help.
#!/usr/bin/env python3
import tempfile
import subprocess as sp
import git
from git import Repo
url = "https://github.com/dclong/docker-ubuntu_b.git"
dir_local = tempfile.mkdtemp()
repo = git.Repo.clone_from(url, dir_local, branch="main")
ref_main = next(ref for ref in repo.refs if ref.name == "origin/main")
ref_debian = next(ref for ref in repo.refs if ref.name == "origin/debian")
diffs = ref_main.commit.diff(ref_debian.commit)
# check whether there are any diff
print("origin/main vs origin/debian using GitPython:")
for diff in diffs:
print(diff.diff)
print("origin/main vs origin/debian using git diff:")
sp.run(f"git -C {dir_local} diff origin/main..origin/debian", shell=True, check=True)
The above Python code reproduces the issue. Coping and paste the code into a Python script, run it and you will see the issue. Basically, GitPython doesn't detect any difference between origin/main and origin/debian of the repo while git diff does.
Thanks for posting - I can reproduce the issue now.
Here is a 'fixed' version of the script above, note the lack of .diff when printing.
#!/usr/bin/env python3importtempfileimportsubprocessasspimportgitfromgitimportRepourl="https://github.com/dclong/docker-ubuntu_b.git"dir_local=tempfile.mkdtemp()
repo=git.Repo.clone_from(url, dir_local, branch="main")
ref_main=next(refforrefinrepo.refsifref.name=="origin/main")
ref_debian=next(refforrefinrepo.refsifref.name=="origin/debian")
diffs=ref_main.commit.diff(ref_debian.commit)
# check whether there are any diff print("origin/main vs origin/debian using GitPython:")
print(diffs) # ⬅ also shows that there is indeed a diff as expected.fordiffindiffs:
print(diff) # ⬅ note the lack of '.diff' - where was that coming from?print("origin/main vs origin/debian using git diff:")
sp.run(f"git -C {dir_local} diff origin/main..origin/debian", shell=True, check=True)
Activity
dclong commentedon Jan 24, 2021
I tried git command and it does show difference when I run
git diff origin/main..origin/debian. This makes me believe that there's a bug in GitPython.The repository I'm using is https://github.com/dclong/docker-ubuntu_b.
Byron commentedon Jan 25, 2021
Could you show the code involving GitPython so I get an idea how you are trying to do it?
Diffing can be tricky, but is believed to be working. In the meantime, you can debug GitPython to learn which git commands are actually invoked.
dclong commentedon Jan 25, 2021
@Byron Please refer to https://github.com/dclong/reproduce_GitPython_issue/blob/master/GitPython.ipynb.
Byron commentedon Jan 25, 2021
Would you mind finding all the pieces in the referenced file and put it here in a single code block? Ideally that would be executable while in the repository mentioned in the issue itself.
dclong commentedon Jan 25, 2021
The referenced file is a Jupyter/Lab notebook which is executable if you have Jupyter/Lab (a Python library) installed. It has code (both Python and Shell commands), output and comments all in one place so that it is easy to understand. Please let me know if you are unfamiliar with Jupyter/Lab notebook and still prefer a single code block here.
Byron commentedon Jan 26, 2021
I can't execute and won't get into executing Jupyter Notebooks, but will take a look at code posted here. If that's not possible, Stackoverflow might be a better place to ask for help.
dclong commentedon Jan 26, 2021
dclong commentedon Jan 26, 2021
The above Python code reproduces the issue. Coping and paste the code into a Python script, run it and you will see the issue. Basically, GitPython doesn't detect any difference between origin/main and origin/debian of the repo while
git diffdoes.Byron commentedon Jan 27, 2021
Thanks for posting - I can reproduce the issue now.
Here is a 'fixed' version of the script above, note the lack of
.diffwhen printing.And the (cleaned) output is…
…which is indeed the file in question.
Even though I am closing this issue, please feel free to post follow-up questions in the comments if there is a need.