-
Notifications
You must be signed in to change notification settings - Fork 392
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
Correctly handle process substitution in bash #666
Comments
See this https://superuser.com/questions/1059781/what-exactly-is-in-bash-and-in-zsh as an explanation of process substition |
Hi @edi9999 - Note that git itself doesn't handle diffs of process substitutions (and these are implemented via named pipes, and thus can't be part of a git repository anyways) : $ git --no-pager diff <(printf "1\n2\n3\n") <(printf "1\n4\n3\n")
diff --git 1/dev/fd/63 2/dev/fd/62
index cad0470..0d8155b 120000
--- 1/dev/fd/63
+++ 2/dev/fd/62
@@ -1 +1 @@
-pipe:[3364850]
\ No newline at end of file
+pipe:[3364852]
\ No newline at end of file Hence, I don't think it's a delta issue, right ? But, you can still achieve your goal with $ diff <(printf "1\n2\n3\n") <(printf "1\n4\n3\n") | delta 😉 |
Hi @edi9999, to expand slightly on @Kr1ss-XD's answer: firstly, So, one thing we could do, perhaps, would be to enquire in the appropriate git development forum as to whether that patch is appropriate and correct, or study the problem ourselves. Another thing we could do is add an option for users to go back to what delta was doing previously, i.e. calling |
The patch seems so simple on the git repository that it looks like it would not really do any harm in my humble opinion. One reason delta could overcome this would be to detect this case and create temporary files from the file descriptors in this case, and call git diff on the temporary files in that case (created in /tmp/delta_XXXXX with a random suffix and deleted after the diff is done) |
My current workaround is to use temporary files like @edi9999 mentions, something like this (the full version is in a script used in my dotfiles): # git-diff doesn't work with process substitution [1] so we're copying the
# pipe to a temporary file.
# [1] https://github.com/dandavison/delta/issues/666
_git_diff() {
local tmpdir
tmpdir="$(mktemp -d -t 'git_diff.XXXXXX')"
# NOTE: The path variable in trap must be expanded here because it may not
# be defined when the trap is ran.
# shellcheck disable=SC2064
trap "rm -rf -- '${tmpdir}' &> /dev/null || true" EXIT ERR INT HUP TERM
local f files=()
for ((i = 1; i <= $#; i++)); do
f="${!i}"
if [[ -p "${f}" ]]; then
local tmpfile="${tmpdir}/arg_${i}"
cat -- "${f}" >| "${tmpfile}"
files+=("${tmpfile}")
else
files+=("${f}")
fi
done
git diff --no-index --color "${files[@]}"
}
_git_diff "$@" | delta |
Hi,
I would expect the following script to show the diff successfully :
However, it shows, on my terminal at least :
If I run
or
It works as expected.
The text was updated successfully, but these errors were encountered: