-
-
Notifications
You must be signed in to change notification settings - Fork 932
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
If diff.external
is set, diffing via API fails silently as external tool isn't understood
#1828
Comments
create_patch=True
when comparison includes index or working tree always returns empty listcreate_patch=True
when diff includes index or working tree always returns empty list
Can you give instructions to get the repository to the state where those statements produce those results? I've tried to reproduce this on Ubuntu and Windows, and so far I've been unable to get an empty list with For example, on Ubuntu 22.04 LTS with git 2.34.1 using Python 3.12.1 with GitPython 3.1.42 installed in a virtual environment, in a repository consisting of a single commit of a one-line file to which a second line is appended and staged and a third line is appended and not staged, all the calls you showed gave one-element results, with no zero-element results:
So my guess is that this may only happen under particular conditions, such as when a repository has a particular combination of committed, staged, and unstaged changes, or maybe only with particular versions of Git, of Python, etc. |
Hi, thank you so much for the answer! I am using Python 3.8 and git version 2.39.3 (Apple Git-145) on Macbook Air M2 Here are steps to reproduce: mkdir investigate-1828
git --version
# git version 2.39.3 (Apple Git-145)
cd investigate-1828/
git init .
# Initialized empty Git repository in /Users/cantaslicukur/investigate-1828/.git/
echo .venv >.gitignore
git add .
git status
# On branch main
#
# No commits yet
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
# new file: .gitignore
git commit -m 'Initial commit'
# [main (root-commit) 480924f] Initial commit
# 1 file changed, 1 insertion(+)
# create mode 100644 .gitignore
echo __pycache__/ >>.gitignore
git add .
echo '# third line' >>.gitignore
git show
# commit 480924f1dda82f54472d28809db33451deed18ea (HEAD -> main)
# Author: Can Taşlıçukur <can.taslicukur@ozu.edu.tr>
# Date: Mon Feb 19 17:47:03 2024 +0300
#
# Initial commit
#
# diff --git a/.gitignore b/.gitignore
# new file mode 100644
# index 0000000..1d17dae
# --- /dev/null
# +++ b/.gitignore
# @@ -0,0 +1 @@
python --version
# Python 3.8.18
python -m venv .venv
. .venv/bin/activate
pip install GitPython
# Collecting GitPython
# Downloading GitPython-3.1.42-py3-none-any.whl (195 kB)
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 195.4/195.4 kB 2.4 MB/s eta 0:00:00
# Collecting gitdb<5,>=4.0.1
# Downloading gitdb-4.0.11-py3-none-any.whl (62 kB)
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 kB 3.2 MB/s eta 0:00:00
# Collecting smmap<6,>=3.0.1
# Downloading smmap-5.0.1-py3-none-any.whl (24 kB)
# Installing collected packages: smmap, gitdb, GitPython
# Successfully installed GitPython-3.1.42 gitdb-4.0.11 smmap-5.0.1
# [notice] A new release of pip is available: 23.0.1 -> 24.0
# [notice] To update, run: pip install --upgrade pip
python
# Python 3.8.18 | packaged by conda-forge | (default, Dec 23 2023, 17:25:47)
# [Clang 16.0.6 ] on darwin
# Type "help", "copyright", "credits" or "license" for more information.
>>> from git import Repo
>>>
>>> repo = Repo(".")
>>> print(repo.index.diff("HEAD"))
[<git.diff.Diff object at 0x1013a0f70>]
>>> print(repo.index.diff("HEAD", create_patch=True))
[]
>>>
>>> print(repo.index.diff(None))
[<git.diff.Diff object at 0x1013a0e50>]
>>> print(repo.index.diff(None, create_patch=True))
[]
>>> print(repo.head.commit.diff(None, create_patch=True))
[]
>>> print(repo.head.commit.diff(None))
[<git.diff.Diff object at 0x1013a0ca0>]
>>>
>>> print(repo.head.commit.diff())
[<git.diff.Diff object at 0x1013a0dc0>]
>>> print(repo.head.commit.diff(create_patch=True))
[] Update: I have tried running the steps above with Python 3.12.2 and git version 2.43.2 (installed via brew). I get the same results :( |
All right! I found the issue! Good news, it is my fault :D I just remembered that I use difftastic and in my
I have deleted this from my |
Great to hear it's resolved! If you are interested, you could submit a PR with a fix, so such workarounds aren't required anymore. It should be quite easy to override this setting using environment variables when launching the |
create_patch=True
when diff includes index or working tree always returns empty listdiff.external
is set, diffing via API fails silently as external tool isn't understood
GitPython version: 3.1.42.
prints
R=True
workaround mentioned in #852 does not help either:This also happens when I try to diff tree against index or working tree
returns
It looks like using
create_patch=True
when comparison includes index or working tree always returns empty list. So right now only way to reliably usecreate_patch=True
is to diff tree against tree.Originally posted by @can-taslicukur in #852 (comment)
The text was updated successfully, but these errors were encountered: