-
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? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
I tried git command and it does show difference when I run The repository I'm using is https://github.com/dclong/docker-ubuntu_b. |
Beta Was this translation helpful? Give feedback.
-
Could you show the code involving GitPython so I get an idea how you are trying to do it? |
Beta Was this translation helpful? Give feedback.
-
@Byron Please refer to https://github.com/dclong/reproduce_GitPython_issue/blob/master/GitPython.ipynb. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Thanks for posting - I can reproduce the issue now. Here is a 'fixed' version of the script above, note the lack of #!/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:")
print(diffs) # ⬅ also shows that there is indeed a diff as expected.
for diff in diffs:
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) 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. |
Beta Was this translation helpful? Give feedback.
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.