{"thread":{"id":"42978","subject":"[PATCH v3 3/3] t3700: add a test_mode_in_index helper function","startedAt":"2016-07-30T20:20:09Z","lastAt":"2016-08-01T21:41:46Z","messageCount":2,"participants":["Ingo Brückl","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":3},"messages":[{"id":"292664","messageId":"579d0a83.4bd3c8e4.bm002@wupperonline.de","threadId":"42978","inReplyTo":null,"subject":"[PATCH v3 3/3] t3700: add a test_mode_in_index helper function","fromName":"Ingo Brückl","fromEmail":"ib@wupperonline.de","sentAt":"2016-07-30T20:13:54Z","receivedAt":"2016-07-30T20:20:09Z","isPatch":true,"sender":{"key":"ib@wupperonline.de","avatar":"https://avatars.githubusercontent.com/u/123327?v=4"},"body":"The case statement to check the file mode of a staged file appears\na number of times.\n\nSimplify the test by utilizing a test_mode_in_index helper function.\n\nSigned-off-by: Ingo Brückl <ib@wupperonline.de>\n---\n t/t3700-add.sh | 54 ++++++++++++++++++++++--------------------------------\n 1 file changed, 22 insertions(+), 32 deletions(-)\n\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex 1fa5dfd..7b98483 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -7,6 +7,20 @@ test_description='Test of git add, including the -- option.'\n\n . ./test-lib.sh\n\n+# Test the file mode \"$1\" of the file \"$2\" in the index.\n+test_mode_in_index () {\n+\tcase \"$(git ls-files --stage \"$2\")\" in\n+\t\t$1\\ *\"$2\")\n+\t\t\techo pass\n+\t\t\t;;\n+\t\t*)\n+\t\t\techo fail\n+\t\t\tgit ls-files --stage \"$2\"\n+\t\t\treturn 1\n+\t\t\t;;\n+\tesac\n+}\n+\n test_expect_success \\\n     'Test of git add' \\\n     'touch foo && git add foo'\n@@ -25,18 +39,12 @@ test_expect_success \\\n \t echo foo >xfoo1 &&\n \t chmod 755 xfoo1 &&\n \t git add xfoo1 &&\n-\t case \"$(git ls-files --stage xfoo1)\" in\n-\t 100644\" \"*xfoo1) echo pass;;\n-\t *) echo fail; git ls-files --stage xfoo1; (exit 1);;\n-\t esac'\n+\t test_mode_in_index 100644 xfoo1'\n\n test_expect_success 'git add: filemode=0 should not get confused by symlink' '\n \trm -f xfoo1 &&\n \ttest_ln_s_add foo xfoo1 &&\n-\tcase \"$(git ls-files --stage xfoo1)\" in\n-\t120000\" \"*xfoo1) echo pass;;\n-\t*) echo fail; git ls-files --stage xfoo1; (exit 1);;\n-\tesac\n+\ttest_mode_in_index 120000 xfoo1\n '\n\n test_expect_success \\\n@@ -45,28 +53,19 @@ test_expect_success \\\n \t echo foo >xfoo2 &&\n \t chmod 755 xfoo2 &&\n \t git update-index --add xfoo2 &&\n-\t case \"$(git ls-files --stage xfoo2)\" in\n-\t 100644\" \"*xfoo2) echo pass;;\n-\t *) echo fail; git ls-files --stage xfoo2; (exit 1);;\n-\t esac'\n+\t test_mode_in_index 100644 xfoo2'\n\n test_expect_success 'git add: filemode=0 should not get confused by symlink' '\n \trm -f xfoo2 &&\n \ttest_ln_s_add foo xfoo2 &&\n-\tcase \"$(git ls-files --stage xfoo2)\" in\n-\t120000\" \"*xfoo2) echo pass;;\n-\t*) echo fail; git ls-files --stage xfoo2; (exit 1);;\n-\tesac\n+\ttest_mode_in_index 120000 xfoo2\n '\n\n test_expect_success \\\n \t'git update-index --add: Test that executable bit is not used...' \\\n \t'git config core.filemode 0 &&\n \t test_ln_s_add xfoo2 xfoo3 &&\t# runs git update-index --add\n-\t case \"$(git ls-files --stage xfoo3)\" in\n-\t 120000\" \"*xfoo3) echo pass;;\n-\t *) echo fail; git ls-files --stage xfoo3; (exit 1);;\n-\t esac'\n+\t test_mode_in_index 120000 xfoo3'\n\n test_expect_success '.gitignore test setup' '\n \techo \"*.ig\" >.gitignore &&\n@@ -336,15 +335,9 @@ test_expect_success 'git add --chmod=[+-]x stages correctly' '\n \trm -f foo1 &&\n \techo foo >foo1 &&\n \tgit add --chmod=+x foo1 &&\n-\tcase \"$(git ls-files --stage foo1)\" in\n-\t100755\" \"*foo1) echo pass;;\n-\t*) echo fail; git ls-files --stage foo1; (exit 1);;\n-\tesac &&\n+\ttest_mode_in_index 100755 foo1 &&\n \tgit add --chmod=-x foo1 &&\n-\tcase \"$(git ls-files --stage foo1)\" in\n-\t100644\" \"*foo1) echo pass;;\n-\t*) echo fail; git ls-files --stage foo1; (exit 1);;\n-\tesac\n+\ttest_mode_in_index 100644 foo1\n '\n\n test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '\n@@ -353,10 +346,7 @@ test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '\n \trm -f foo2 &&\n \techo foo >foo2 &&\n \tgit add --chmod=+x foo2 &&\n-\tcase \"$(git ls-files --stage foo2)\" in\n-\t100755\" \"*foo2) echo pass;;\n-\t*) echo fail; git ls-files --stage foo2; (exit 1);;\n-\tesac\n+\ttest_mode_in_index 100755 foo2\n '\n\n test_done\n--\n2.9.2\n"},{"id":"292799","messageId":"xmqqvazkgp1c.fsf@gitster.mtv.corp.google.com","threadId":"42978","inReplyTo":"579d0a83.4bd3c8e4.bm002@wupperonline.de","subject":"Re: [PATCH v3 3/3] t3700: add a test_mode_in_index helper function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-08-01T21:25:19Z","receivedAt":"2016-08-01T21:41:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ingo Brückl <ib@wupperonline.de> writes:\n\nIngo Brückl <ib@wupperonline.de> writes:\n\n> The case statement to check the file mode of a staged file appears\n> a number of times.\n>\n> Simplify the test by utilizing a test_mode_in_index helper function.\n>\n> Signed-off-by: Ingo Brückl <ib@wupperonline.de>\n> ---\n>  t/t3700-add.sh | 54 ++++++++++++++++++++++--------------------------------\n>  1 file changed, 22 insertions(+), 32 deletions(-)\n\nNice.\n\n> diff --git a/t/t3700-add.sh b/t/t3700-add.sh\n> index 1fa5dfd..7b98483 100755\n> --- a/t/t3700-add.sh\n> +++ b/t/t3700-add.sh\n> @@ -7,6 +7,20 @@ test_description='Test of git add, including the -- option.'\n>\n>  . ./test-lib.sh\n>\n> +# Test the file mode \"$1\" of the file \"$2\" in the index.\n> +test_mode_in_index () {\n> +\tcase \"$(git ls-files --stage \"$2\")\" in\n> +\t\t$1\\ *\"$2\")\n> +\t\t\techo pass\n> +\t\t\t;;\n> +\t\t*)\n> +\t\t\techo fail\n> +\t\t\tgit ls-files --stage \"$2\"\n> +\t\t\treturn 1\n> +\t\t\t;;\n> +\tesac\n> +}\n\nThis case/esac is misindented, but no need to resend; I can fix it\nup trivially while queuing the patches.  It may be both easier to\nread and more robust to tweak the pattern like this, though:\n\n# Test the file mode \"$1\" of the file \"$2\" in the index.\ntest_mode_in_index () {\n\tcase \"$(git ls-files --stage \"$2\")\" in\n\t\"$1 \"*\"\t$2\")\n\t\techo pass\n\t\t;;\n\t*)\n\t\techo fail\n\t\tgit ls-files --stage \"$2\"\n\t\treturn 1\n\t\t;;\n\tesac\n}\n\nThanks.\n"}]}