Skip to content
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

🚀 delta does not recognize Git's copy detection #392

Closed
phil-blain opened this issue Nov 20, 2020 · 5 comments · Fixed by #403
Closed

🚀 delta does not recognize Git's copy detection #392

phil-blain opened this issue Nov 20, 2020 · 5 comments · Fixed by #403

Comments

@phil-blain
Copy link
Contributor

Git has special flags and configuration variables for git log, git show, git diff, git diff-tree, git diff-index, git diff-tree, and git format-patch to detect copies as well as renames.

These add "copy from"/"copy to" lines in the diff header when Git detects a new file is in fact copied from an existing file. Currently delta shows these as renames, which is confusing. It would be nice if they would show up correctly as copies.

An example from the same issue for diff-so-fancy:

@ scottchiefbaker this setting tells git how to display renamed (same or similar content, new name, old file is missing) and copied (same or similar content, new name, old file present) files. By default git only detects renames, any copy is shown as new file. diff.renames copies works also for second case.

To illustrate this one can create dummy repository as

git init
echo "hurr-durr" > first_file
git add .
git commit -m "first"

After that copy and stage (or commit) some file:

cp first_file copied_file
git add .

And inspect this change:

❯ git --no-pager diff --staged
diff --git a/copied_file b/copied_file
new file mode 100644
index 0000000..d7b6a5e
--- /dev/null
+++ b/copied_file
@@ -0,0 +1 @@
+hurr-durr

/tmp/copy-example master*
❯ git --no-pager diff -C --staged  # -C has the same meaning
diff --git a/first_file b/copied_file
similarity index 100%
copy from first_file
copy to copied_file

I hope this narrowed down example helps better than original ones.
Looks like fancy just doesn't know how to parse copy from/to headers in diff.

Relevant parts of the Git documentation:

@dandavison
Copy link
Owner

Hi @phil-blain, thanks for this, I didn't know about the feature.

dandavison added a commit that referenced this issue Nov 21, 2020
dandavison added a commit that referenced this issue Nov 23, 2020
dandavison added a commit that referenced this issue Nov 23, 2020
dandavison added a commit that referenced this issue Nov 23, 2020
@dandavison
Copy link
Owner

This is fixed in master (not released yet). It's going to look like below (with the unicode arrow for consistency with the "rename" case). In case you'd prefer a text label other than copied:, there is a set of options for that (file-copied-label, file-added-label etc). If you'd like to test it before release that is of course always very helpful, and delta is easy to build from source.

(I wonder why I needed --find-copies-harder in your example while you did not!...)

image

@phil-blain
Copy link
Contributor Author

Hi @dandavison !

I really admire your responsiveness! I tested by building delta from master, and it works correctly for both the example above (which by the way is not by me but was taken from the diff-so-fancy issue) and with the internal repo I was reviewing on Friday (for which delta 0.4.4 incorrectly shows "renamed" when used with git log -p -C -C).

I also have to add --find-copies-harder (or an additional -C flag), for both cases. I think it's normal: according to the documentation, since the original file is not touched, by default Git does not look for copies for efficiency unless --find-copies-harder is also given.

I did not think of it on Friday, but delta would be even more excellent if the similarity index (in percent) was indicated in parenthesis on the header line, for both renamed and copied files, something like this:

$ GIT_PAGER=../delta/target/release/delta git diff --cached -C -C

copied: first_file ⟶   copied_file (100%)
─────────────────────────────────────────────────────────────────

A final note, I noticed that the Linux binary release linked from the Installation section of the README links to the tarball for the x86_64-unknown-linux-musl platform - maybe linking to x86_64-unknown-linux-gnu would make more sense as this is the most common Linux platform ?

Cheers!

@dandavison
Copy link
Owner

if the similarity index (in percent) was indicated in parenthesis on the header line, for both renamed and copied files,

Yes, good call. I like that idea. #406

maybe linking to x86_64-unknown-linux-gnu would make more sense as this is the most common Linux platform ?

Thanks! 2309db4

@dandavison
Copy link
Owner

This is released now (v0.4.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants