t3700: add a test_mode_in_index helper function

The case statement to check the file mode of a staged file appears a number of times. Simplify the test by utilizing a test_mode_in_index helper function. Signed-off-by: Ingo Brückl <ib@wupperonline.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ingo Brückl committed Jul 30, 2016 at 22:13 UTC 766cdc4147f8e77b32e67338795c8f2a6083a877
1 file changed +22 -32
t/t3700-add.sh
+22 -32
@@ -7,6 +7,20 @@ test_description='Test of git add, including the -- option.'
7
8 . ./test-lib.sh
9
10 +# Test the file mode "$1" of the file "$2" in the index.
11 +test_mode_in_index () {
12 + case "$(git ls-files -s "$2")" in
13 + "$1 "*" $2")
14 + echo pass
15 + ;;
16 + *)
17 + echo fail
18 + git ls-files -s "$2"
19 + return 1
20 + ;;
21 + esac
22 +}
23 +
24 test_expect_success \
25 'Test of git add' \
26 'touch foo && git add foo'
@@ -25,18 +39,12 @@ test_expect_success \
39 echo foo >xfoo1 &&
40 chmod 755 xfoo1 &&
41 git add xfoo1 &&
28 - case "$(git ls-files --stage xfoo1)" in
29 - 100644" "*xfoo1) echo pass;;
30 - *) echo fail; git ls-files --stage xfoo1; (exit 1);;
31 - esac'
42 + test_mode_in_index 100644 xfoo1'
43
44 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
45 rm -f xfoo1 &&
46 test_ln_s_add foo xfoo1 &&
36 - case "$(git ls-files --stage xfoo1)" in
37 - 120000" "*xfoo1) echo pass;;
38 - *) echo fail; git ls-files --stage xfoo1; (exit 1);;
39 - esac
47 + test_mode_in_index 120000 xfoo1
48 '
49
50 test_expect_success \
@@ -45,28 +53,19 @@ test_expect_success \
53 echo foo >xfoo2 &&
54 chmod 755 xfoo2 &&
55 git update-index --add xfoo2 &&
48 - case "$(git ls-files --stage xfoo2)" in
49 - 100644" "*xfoo2) echo pass;;
50 - *) echo fail; git ls-files --stage xfoo2; (exit 1);;
51 - esac'
56 + test_mode_in_index 100644 xfoo2'
57
58 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
59 rm -f xfoo2 &&
60 test_ln_s_add foo xfoo2 &&
56 - case "$(git ls-files --stage xfoo2)" in
57 - 120000" "*xfoo2) echo pass;;
58 - *) echo fail; git ls-files --stage xfoo2; (exit 1);;
59 - esac
61 + test_mode_in_index 120000 xfoo2
62 '
63
64 test_expect_success \
65 'git update-index --add: Test that executable bit is not used...' \
66 'git config core.filemode 0 &&
67 test_ln_s_add xfoo2 xfoo3 && # runs git update-index --add
66 - case "$(git ls-files --stage xfoo3)" in
67 - 120000" "*xfoo3) echo pass;;
68 - *) echo fail; git ls-files --stage xfoo3; (exit 1);;
69 - esac'
68 + test_mode_in_index 120000 xfoo3'
69
70 test_expect_success '.gitignore test setup' '
71 echo "*.ig" >.gitignore &&
@@ -336,15 +335,9 @@ test_expect_success 'git add --chmod=[+-]x stages correctly' '
335 rm -f foo1 &&
336 echo foo >foo1 &&
337 git add --chmod=+x foo1 &&
339 - case "$(git ls-files --stage foo1)" in
340 - 100755" "*foo1) echo pass;;
341 - *) echo fail; git ls-files --stage foo1; (exit 1);;
342 - esac &&
338 + test_mode_in_index 100755 foo1 &&
339 git add --chmod=-x foo1 &&
344 - case "$(git ls-files --stage foo1)" in
345 - 100644" "*foo1) echo pass;;
346 - *) echo fail; git ls-files --stage foo1; (exit 1);;
347 - esac
340 + test_mode_in_index 100644 foo1
341 '
342
343 test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
@@ -353,10 +346,7 @@ test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
346 rm -f foo2 &&
347 echo foo >foo2 &&
348 git add --chmod=+x foo2 &&
356 - case "$(git ls-files --stage foo2)" in
357 - 100755" "*foo2) echo pass;;
358 - *) echo fail; git ls-files --stage foo2; (exit 1);;
359 - esac
349 + test_mode_in_index 100755 foo2
350 '
351
352 test_done