Skip to content

Commit 9f3d54d

Browse files
davvidgitster
authored andcommitted
difftool: Use eval to expand '--extcmd' expressions
It was not possible to pass quoted commands to '--extcmd'. By using 'eval' we ensure that expressions with spaces and quotes are supported. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f47f1e2 commit 9f3d54d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

git-difftool--helper.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ launch_merge_tool () {
4848
fi
4949

5050
if use_ext_cmd; then
51-
$GIT_DIFFTOOL_EXTCMD "$LOCAL" "$REMOTE"
51+
eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
5252
else
5353
run_merge_tool "$merge_tool"
5454
fi
55-
5655
}
5756

5857
if ! use_ext_cmd; then

t/t7800-difftool.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,21 @@ test_expect_success 'difftool --extcmd cat' '
235235
test_expect_success 'difftool -x cat' '
236236
diff=$(git difftool --no-prompt -x cat branch) &&
237237
test "$diff" = branch"$LF"master
238+
'
239+
240+
test_expect_success 'difftool --extcmd echo arg1' '
241+
diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch)
242+
test "$diff" = file
243+
'
238244

245+
test_expect_success 'difftool --extcmd cat arg1' '
246+
diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch)
247+
test "$diff" = master
248+
'
239249

250+
test_expect_success 'difftool --extcmd cat arg2' '
251+
diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch)
252+
test "$diff" = branch
240253
'
241254

242255
test_done

0 commit comments

Comments
 (0)