delta icon indicating copy to clipboard operation
delta copied to clipboard

delta eats first character of absolute file pathπŸ›

Open salmankhilji opened this issue 3 years ago β€’ 3 comments

delta eats first character of absolute file paths, thereby making them look like relative paths.

Repro Steps

  1. seq 1 >fileA
  2. seq 2 >/tmp/fileB
  3. Invoke delta as follows:
$ delta fileA /tmp/fileB

fileA ⟢   tmp/fileB
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

───┐
1: β”‚
β”€β”€β”€β”˜
1
2

Observed Behavior

Observe the following within the header:

fileA ⟢   tmp/fileB

Notice that the leading / is missing.

Expected Behavior

fileA ⟢   /tmp/fileB
$ delta --version
delta 0.12.1

salmankhilji avatar Mar 16 '22 05:03 salmankhilji

Hi @salmankhilji, thanks again! I hadn't noticed that. And that's a bit unfortunate: delta a b uses git diff under the hood, but git diff produces identical output on the relative and absolute paths:

$ git -P diff --no-index /tmp/a /tmp/b
diff --git a/tmp/a b/tmp/b
index 7898192..6178079 100644
--- a/tmp/a
+++ b/tmp/b
@@ -1 +1 @@
-a
+b
$ delta <(git -P diff --no-index tmp/a tmp/b) <(git -P diff --no-index /tmp/a /tmp/b); echo $?
0

I was hoping that the solution might be git diff --no-prefix but in fact, it seems to be git that is stripping the leading /:

$ git -P diff --no-prefix --no-index /tmp/a /tmp/b
diff --git tmp/a tmp/b
index 7898192..6178079 100644
--- tmp/a
+++ tmp/b
@@ -1 +1 @@
-a
+b

Any ideas how we should solve this? (Maybe delta will have to "fix" git's output, since delta knows the original paths?)

dandavison avatar Mar 16 '22 13:03 dandavison

Here's a quick attempt at fixing it: https://github.com/dandavison/delta/pull/1016

dandavison avatar Mar 16 '22 13:03 dandavison

Any ideas how we should solve this? (Maybe delta will have to "fix" git's output, since delta knows the original paths?)

Not knowing Rust, I can not comment on the proposed changes to address this issue. At a high-level, it appears that yes, patching git's output would be the way to do. We, however, have to be careful as not to break pipe mode where delta may have been invoked without filenames, reading its input from stdin.

BTW, this is not a must fix IMHO. If its risky to fix, you may also choose to leave it as-is. At least delta is being consistent with git, which is much more widely used .

salmankhilji avatar Mar 17 '22 01:03 salmankhilji