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
Add a /gitdiff
API
#482
Merged
Merged
Add a /gitdiff
API
#482
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
477f525
Add a server API to perform git diff
690161e
Ensure backwards compatibility when remote=None
5c23333
Improve documentation
7ccc993
Add reserved field for special refs
ef13feb
Resolve base correctly if file is deleted; Add more docs
8f7a91a
Unit test for server extension API
979b7ea
Adjust git api entry code
vidartf 94100ab
Minro cleanup
vidartf 7bb0928
Handle empty blobs correctly
19c5c65
Tweak comments/docstrings
vidartf 8973fc6
Minor cleanup
vidartf fc3bc8b
Undo mistaken overwrite of var
vidartf a9135d2
Add missing quotes
vidartf bf1fc75
Dedupe curdir property (DRY)
vidartf File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue here while performing the diff between two Git refs, where a file was added. The Base always points to the "Working Tree" version, whereas it should be empty, so when the client computes the diff on top of the base it shows an incorrect result. I attempted to fix this in the commit ef13feb.
I'll try and have a stab at fixing this over your commitsSee 7bb0928.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand this issue. In the docs you link in the commit (https://gitpython.readthedocs.io/en/stable/reference.html#git.diff.Diff), it says that for added/deleted files the
path
will beNone
. We check if thepath
isNone
at the start of the function. According to the docs, if the path is notNone
and theblob
is, then we are diffing against the working tree.Would you mind sharing a minimal reproducible sample? I don't really understand the screenshot..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vidartf
Repro setup:
print('Simple Diff Committed
=>print('Simple Diff in Working Tree)
Repro output:
So the issue is about the "base" output being returned incorrectly if we're trying to diff a commit in the history where a file has been added/
[1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've documented the values for path, blob, and ref_name for 3 cases https://gist.github.com/jaipreet-s/396da4a2c13f476dec393e480b4e8b20#file-ref-blob-path-values
None
ineaf1741
since the file was first added inb82e191
. ref_name is the Git ref in both cases.6ee0
for HEAD. For Working, ref_name as well as blob is None.Diffable.Index
and blob is58d9d9
So, the issue is coming from the fact that
blob
can beNone
both in the Working Tree and if file is added/removed in a Git ref. But only the Working Tree will have theref_name
as None.That is why in 7bb0928 I've checked if
ref_name
is theWorkingTree
explicitly and only then use the content from the Working Tree.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see now on the GitPython repo there is an issue about this gitpython-developers/GitPython#749 .