git-difftool: allow skipping file by typing 'n' at prompt
This is useful if you forgot to restrict the diff to the paths you want to see, or selecting precisely the ones you want is too much typing. [jc: with a change to return from the function upon 'n' by Charles Bailey and a small tweak in stdin_doesnot_contain() in the test] Signed-off-by: Sitaram Chamarty <sitaram@atc.tcs.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sitaram Chamarty committed
Oct 8, 2011 at 18:40 UTC
ba959de165c6fc0d08d851894a98778e739aafc9
2 files changed
+48
-4
git-difftool--helper.sh
+6
-3
@@ -43,12 +43,15 @@ launch_merge_tool () {
43
printf "\nViewing: '$MERGED'\n"
44
if use_ext_cmd
45
then
46
- printf "Hit return to launch '%s': " \
46
+ printf "Launch '%s' [Y/n]: " \
47
"$GIT_DIFFTOOL_EXTCMD"
48
else
49
- printf "Hit return to launch '%s': " "$merge_tool"
49
+ printf "Launch '%s' [Y/n]: " "$merge_tool"
50
+ fi
51
+ if read ans && test "$ans" = n
52
+ then
53
+ return
54
fi
51
- read ans
55
fi
56
57
if use_ext_cmd
t/t7800-difftool.sh
+42
-1
@@ -38,7 +38,17 @@ restore_test_defaults()
38
prompt_given()
39
{
40
prompt="$1"
41
- test "$prompt" = "Hit return to launch 'test-tool': branch"
41
+ test "$prompt" = "Launch 'test-tool' [Y/n]: branch"
42
+}
43
+
44
+stdin_contains()
45
+{
46
+ grep >/dev/null "$1"
47
+}
48
+
49
+stdin_doesnot_contain()
50
+{
51
+ ! stdin_contains "$1"
52
}
53
54
# Create a file on master and change it on branch
@@ -265,4 +275,35 @@ test_expect_success PERL 'difftool --extcmd cat arg2' '
275
test "$diff" = branch
276
'
277
278
+# Create a second file on master and a different version on branch
279
+test_expect_success PERL 'setup with 2 files different' '
280
+ echo m2 >file2 &&
281
+ git add file2 &&
282
+ git commit -m "added file2" &&
283
+
284
+ git checkout branch &&
285
+ echo br2 >file2 &&
286
+ git add file2 &&
287
+ git commit -a -m "branch changed file2" &&
288
+ git checkout master
289
+'
290
+
291
+test_expect_success PERL 'say no to the first file' '
292
+ diff=$((echo n; echo) | git difftool -x cat branch) &&
293
+
294
+ echo "$diff" | stdin_contains m2 &&
295
+ echo "$diff" | stdin_contains br2 &&
296
+ echo "$diff" | stdin_doesnot_contain master &&
297
+ echo "$diff" | stdin_doesnot_contain branch
298
+'
299
+
300
+test_expect_success PERL 'say no to the second file' '
301
+ diff=$((echo; echo n) | git difftool -x cat branch) &&
302
+
303
+ echo "$diff" | stdin_contains master &&
304
+ echo "$diff" | stdin_contains branch &&
305
+ echo "$diff" | stdin_doesnot_contain m2 &&
306
+ echo "$diff" | stdin_doesnot_contain br2
307
+'
308
+
309
test_done