difftool: create a tmpdir path without repeated slashes

The paths generated by difftool are passed to user-facing diff tools.
Using paths with repeated slashes in them is a cosmetic blemish that
is exposed to users and can be avoided.

Use a strbuf to create the buffer used for the dir-diff tmpdir.
Strip trailing slashes from the value read from TMPDIR to avoid
repeated slashes in the generated paths.

Adjust the error handling to avoid leaking strbufs and to avoid
returning -1 to cmd_main().

Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
David Aguilar
2021-09-30 18:37:53 -07:00
committed by Junio C Hamano
parent 77bd616367
commit 4ac9f15492
2 changed files with 31 additions and 26 deletions

View File

@ -453,6 +453,13 @@ run_dir_diff_test 'difftool --dir-diff' '
grep "^file$" output
'
run_dir_diff_test 'difftool --dir-diff avoids repeated slashes in TMPDIR' '
TMPDIR="${TMPDIR:-/tmp}////" \
git difftool --dir-diff $symlinks --extcmd echo branch >output &&
grep -v // output >actual &&
test_line_count = 1 actual
'
run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output &&
grep "^sub$" output &&