Skip to content

Commit 80f5a16

Browse files
phil-blaingitster
authored andcommitted
mergetool--lib: fix '--tool-help' to correctly show available tools
Commit 83bbf9b (mergetool--lib: improve support for vimdiff-style tool variants, 2020-07-29) introduced a regression in the output of `git mergetool --tool-help` and `git difftool --tool-help` [1]. In function 'show_tool_names' in git-mergetool--lib.sh, we loop over the supported mergetools and their variants and accumulate them in the variable 'variants', separating them with a literal '\n'. The code then uses 'echo $variants' to turn these '\n' into newlines, but this behaviour is not portable, it just happens to work in some shells, like dash(1)'s 'echo' builtin. For shells in which 'echo' does not turn '\n' into newlines, the end result is that the only tools that are shown are the existing variants (except the last variant alphabetically), since the variants are separated by actual newlines in '$variants' because of the several 'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants. Fix this bug by embedding an actual line feed into `variants` in show_tool_names(). While at it, replace `sort | uniq` by `sort -u`. To prevent future regressions, add a simple test that checks that a few known tools are correctly shown (let's avoid counting the total number of tools to lessen the maintenance burden when new tools are added or if '--tool-help' learns additional logic, like hiding tools depending on the current platform). [1] https://lore.kernel.org/git/CADtb9DyozjgAsdFYL8fFBEWmq7iz4=prZYVUdH9W-J5CKVS4OA@mail.gmail.com/ Reported-by: Philippe Blain <[email protected]> Based-on-patch-by: Johannes Sixt <[email protected]> Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1186897 commit 80f5a16

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

git-mergetool--lib.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ show_tool_names () {
4646
while read scriptname
4747
do
4848
setup_tool "$scriptname" 2>/dev/null
49-
variants="$variants$(list_tool_variants)\n"
49+
# We need an actual line feed here
50+
variants="$variants
51+
$(list_tool_variants)"
5052
done
51-
variants="$(echo "$variants" | sort | uniq)"
53+
variants="$(echo "$variants" | sort -u)"
5254

5355
for toolname in $variants
5456
do

t/t7610-mergetool.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,15 @@ test_expect_success 'mergetool -Oorder-file is honored' '
802802
test_cmp expect actual
803803
'
804804

805+
test_expect_success 'mergetool --tool-help shows recognized tools' '
806+
# Check a few known tools are correctly shown
807+
git mergetool --tool-help >mergetools &&
808+
grep vimdiff mergetools &&
809+
grep vimdiff3 mergetools &&
810+
grep gvimdiff2 mergetools &&
811+
grep araxis mergetools &&
812+
grep xxdiff mergetools &&
813+
grep meld mergetools
814+
'
815+
805816
test_done

0 commit comments

Comments
 (0)