From 13a4899886958c211b96bced228fdaaa42674491 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 29 Feb 2012 18:14:14 -0800 Subject: t4011: modernise style Match the style to more modern test scripts, namely: - The first line of each test has prereq, title and opening sq for the script body. This makes the test shorter while reducing the need for backslashes. - Be prepared for the case in which the previous test may have failed. If a test wants to start from not having "frotz" that the previous test may have created, write "rm -f frotz", not "rm frotz". - Prepare the expected output inside your own test. - The order of comparison to check the result is "diff expected actual", so that the output will show how the output from the git you just broke is different from what is expected. - Write no SP between redirection '>' (or '<' for that matter) and the filename. Signed-off-by: Junio C Hamano --- t/t4011-diff-symlink.sh | 168 +++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 86 deletions(-) (limited to 't/t4011-diff-symlink.sh') diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh index 408a19c4c2..cb47ec17f9 100755 --- a/t/t4011-diff-symlink.sh +++ b/t/t4011-diff-symlink.sh @@ -9,85 +9,81 @@ test_description='Test diff of symlinks. . ./test-lib.sh . "$TEST_DIRECTORY"/diff-lib.sh -cat > expected << EOF -diff --git a/frotz b/frotz -new file mode 120000 -index 0000000..7c465af ---- /dev/null -+++ b/frotz -@@ -0,0 +1 @@ -+xyzzy -\ No newline at end of file -EOF - -test_expect_success SYMLINKS \ - 'diff new symlink' \ - 'ln -s xyzzy frotz && - git update-index && - tree=$(git write-tree) && - git update-index --add frotz && - GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree > current && - compare_diff_patch current expected' - -test_expect_success SYMLINKS \ - 'diff unchanged symlink' \ - 'tree=$(git write-tree) && - git update-index frotz && - test -z "$(git diff-index --name-only $tree)"' - -cat > expected << EOF -diff --git a/frotz b/frotz -deleted file mode 120000 -index 7c465af..0000000 ---- a/frotz -+++ /dev/null -@@ -1 +0,0 @@ --xyzzy -\ No newline at end of file -EOF - -test_expect_success SYMLINKS \ - 'diff removed symlink' \ - 'mv frotz frotz2 && - git diff-index -M -p $tree > current && - compare_diff_patch current expected' +test_expect_success SYMLINKS 'diff new symlink' ' + cat >expected <<-\EOF && + diff --git a/frotz b/frotz + new file mode 120000 + index 0000000..7c465af + --- /dev/null + +++ b/frotz + @@ -0,0 +1 @@ + +xyzzy + \ No newline at end of file + EOF + ln -s xyzzy frotz && + git update-index && + tree=$(git write-tree) && + git update-index --add frotz && + GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && + compare_diff_patch expected current +' -cat > expected << EOF -diff --git a/frotz b/frotz -EOF +test_expect_success SYMLINKS 'diff unchanged symlink' ' + tree=$(git write-tree) && + git update-index frotz && + test -z "$(git diff-index --name-only $tree)" +' -test_expect_success SYMLINKS \ - 'diff identical, but newly created symlink' \ - 'ln -s xyzzy frotz && - git diff-index -M -p $tree > current && - compare_diff_patch current expected' +test_expect_success SYMLINKS 'diff removed symlink' ' + cat >expected <<-\EOF && + diff --git a/frotz b/frotz + deleted file mode 120000 + index 7c465af..0000000 + --- a/frotz + +++ /dev/null + @@ -1 +0,0 @@ + -xyzzy + \ No newline at end of file + EOF + mv frotz frotz2 && + git diff-index -M -p $tree >current && + compare_diff_patch expected current +' -cat > expected << EOF -diff --git a/frotz b/frotz -index 7c465af..df1db54 120000 ---- a/frotz -+++ b/frotz -@@ -1 +1 @@ --xyzzy -\ No newline at end of file -+yxyyz -\ No newline at end of file -EOF +test_expect_success SYMLINKS 'diff identical, but newly created symlink' ' + cat >expected <<-\EOF && + diff --git a/frotz b/frotz + EOF + ln -s xyzzy frotz && + git diff-index -M -p $tree >current && + compare_diff_patch expected current +' -test_expect_success SYMLINKS \ - 'diff different symlink' \ - 'rm frotz && - ln -s yxyyz frotz && - git diff-index -M -p $tree > current && - compare_diff_patch current expected' +test_expect_success SYMLINKS 'diff different symlink' ' + cat >expected <<-\EOF && + diff --git a/frotz b/frotz + index 7c465af..df1db54 120000 + --- a/frotz + +++ b/frotz + @@ -1 +1 @@ + -xyzzy + \ No newline at end of file + +yxyyz + \ No newline at end of file + EOF + rm -f frotz && + ln -s yxyyz frotz && + git diff-index -M -p $tree >current && + compare_diff_patch expected current +' -test_expect_success SYMLINKS \ - 'diff symlinks with non-existing targets' \ - 'ln -s narf pinky && - ln -s take\ over brain && - test_must_fail git diff --no-index pinky brain > output 2> output.err && - grep narf output && - ! grep error output.err' +test_expect_success SYMLINKS 'diff symlinks with non-existing targets' ' + ln -s narf pinky && + ln -s take\ over brain && + test_must_fail git diff --no-index pinky brain >output 2>output.err && + grep narf output && + ! test -s output.err +' test_expect_success SYMLINKS 'setup symlinks with attributes' ' echo "*.bin diff=bin" >>.gitattributes && @@ -96,19 +92,19 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' ' git add -N file.bin link.bin ' -cat >expect <<'EOF' -diff --git a/file.bin b/file.bin -index e69de29..d95f3ad 100644 -Binary files a/file.bin and b/file.bin differ -diff --git a/link.bin b/link.bin -index e69de29..dce41ec 120000 ---- a/link.bin -+++ b/link.bin -@@ -0,0 +1 @@ -+file.bin -\ No newline at end of file -EOF test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' ' + cat >expect <<-\EOF && + diff --git a/file.bin b/file.bin + index e69de29..d95f3ad 100644 + Binary files a/file.bin and b/file.bin differ + diff --git a/link.bin b/link.bin + index e69de29..dce41ec 120000 + --- a/link.bin + +++ b/link.bin + @@ -0,0 +1 @@ + +file.bin + \ No newline at end of file + EOF git config diff.bin.binary true && git diff file.bin link.bin >actual && test_cmp expect actual -- cgit v1.2.1 From 5597e84b514454f18bba7b13eee2feea04f0165b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 29 Feb 2012 18:14:15 -0800 Subject: t4011: illustrate "diff-index -p" on stat-dirty paths The plumbing that looks at the working tree, i.e. "diff-index" and "diff-files", always emit the "diff --git a/path b/path" header lines without anything else for paths that are only stat-dirty (i.e. different only because the cached stat information in the index no longer matches that of the working tree, but the real contents are the same), when these commands are run with "-p" option to produce patches. Illustrate this current behaviour. Also demonstrate that with the "-w" option, we (correctly) hold off showing a "diff --git" header until actual differences have been found. This also suppresses the header for merely stat-dirty files, which is inconsistent. Signed-off-by: Junio C Hamano --- t/t4011-diff-symlink.sh | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 't/t4011-diff-symlink.sh') diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh index cb47ec17f9..164f153855 100755 --- a/t/t4011-diff-symlink.sh +++ b/t/t4011-diff-symlink.sh @@ -9,7 +9,7 @@ test_description='Test diff of symlinks. . ./test-lib.sh . "$TEST_DIRECTORY"/diff-lib.sh -test_expect_success SYMLINKS 'diff new symlink' ' +test_expect_success SYMLINKS 'diff new symlink and file' ' cat >expected <<-\EOF && diff --git a/frotz b/frotz new file mode 120000 @@ -19,22 +19,30 @@ test_expect_success SYMLINKS 'diff new symlink' ' @@ -0,0 +1 @@ +xyzzy \ No newline at end of file + diff --git a/nitfol b/nitfol + new file mode 100644 + index 0000000..7c465af + --- /dev/null + +++ b/nitfol + @@ -0,0 +1 @@ + +xyzzy EOF ln -s xyzzy frotz && + echo xyzzy >nitfol && git update-index && tree=$(git write-tree) && - git update-index --add frotz && + git update-index --add frotz nitfol && GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && compare_diff_patch expected current ' -test_expect_success SYMLINKS 'diff unchanged symlink' ' +test_expect_success SYMLINKS 'diff unchanged symlink and file' ' tree=$(git write-tree) && - git update-index frotz && + git update-index frotz nitfol && test -z "$(git diff-index --name-only $tree)" ' -test_expect_success SYMLINKS 'diff removed symlink' ' +test_expect_success SYMLINKS 'diff removed symlink and file' ' cat >expected <<-\EOF && diff --git a/frotz b/frotz deleted file mode 120000 @@ -44,22 +52,38 @@ test_expect_success SYMLINKS 'diff removed symlink' ' @@ -1 +0,0 @@ -xyzzy \ No newline at end of file + diff --git a/nitfol b/nitfol + deleted file mode 100644 + index 7c465af..0000000 + --- a/nitfol + +++ /dev/null + @@ -1 +0,0 @@ + -xyzzy EOF mv frotz frotz2 && + mv nitfol nitfol2 && git diff-index -M -p $tree >current && compare_diff_patch expected current ' -test_expect_success SYMLINKS 'diff identical, but newly created symlink' ' +test_expect_success SYMLINKS 'diff identical, but newly created symlink and file' ' cat >expected <<-\EOF && diff --git a/frotz b/frotz + diff --git a/nitfol b/nitfol EOF + rm -f frotz nitfol && + echo xyzzy >nitfol && + test-chmtime +10 nitfol && ln -s xyzzy frotz && git diff-index -M -p $tree >current && + compare_diff_patch expected current && + + >expected && + git diff-index -M -p -w $tree >current && compare_diff_patch expected current ' -test_expect_success SYMLINKS 'diff different symlink' ' +test_expect_success SYMLINKS 'diff different symlink and file' ' cat >expected <<-\EOF && diff --git a/frotz b/frotz index 7c465af..df1db54 120000 @@ -70,9 +94,17 @@ test_expect_success SYMLINKS 'diff different symlink' ' \ No newline at end of file +yxyyz \ No newline at end of file + diff --git a/nitfol b/nitfol + index 7c465af..df1db54 100644 + --- a/nitfol + +++ b/nitfol + @@ -1 +1 @@ + -xyzzy + +yxyyz EOF rm -f frotz && ln -s yxyyz frotz && + echo yxyyz >nitfol && git diff-index -M -p $tree >current && compare_diff_patch expected current ' -- cgit v1.2.1 From b3f01ff29f7131e959bcfdfd004744d74d5fa319 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 29 Feb 2012 18:14:16 -0800 Subject: diff -p: squelch "diff --git" header for stat-dirty paths The plumbing "diff" commands look at the working tree files without refreshing the index themselves for performance reasons (the calling script is expected to do that upfront just once, before calling one or more of them). In the early days of git, they showed the "diff --git" header before they actually ask the xdiff machinery to produce patches, and ended up showing only these headers if the real contents are the same and the difference they noticed was only because the stat info cached in the index did not match that of the working tree. It was too late for the implementation to take the header that it already emitted back. But 3e97c7c (No diff -b/-w output for all-whitespace changes, 2009-11-19) introduced necessary logic to keep the meta-information headers in a strbuf and delay their output until the xdiff machinery noticed actual changes. This was primarily in order to generate patches that ignore whitespaces. When operating under "-w" mode, we wouldn't know if the header is needed until we actually look at the resulting patch, so it was a sensible thing to do, but we did not realize that the same reasoning applies to stat-dirty paths. Later, 296c6bb (diff: fix "git show -C -C" output when renaming a binary file, 2010-05-26) generalized this machinery and added must_show_header toggle. This is turned on when the header must be shown even when there is no patch to be produced, e.g. only the mode was changed, or the path was renamed, without changing the contents. However, when it did so, it still kept the special case for the "-w" mode, which meant that the plumbing would keep showing these phantom changes. This corrects this historical inconsistency by allowing the plumbing to omit paths that are only stat-dirty from its output in the same way as it handles whitespace only changes under "-w" option. The change in the behaviour can be seen in the updated test. Signed-off-by: Junio C Hamano --- t/t4011-diff-symlink.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 't/t4011-diff-symlink.sh') diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh index 164f153855..f0d5041c11 100755 --- a/t/t4011-diff-symlink.sh +++ b/t/t4011-diff-symlink.sh @@ -67,10 +67,7 @@ test_expect_success SYMLINKS 'diff removed symlink and file' ' ' test_expect_success SYMLINKS 'diff identical, but newly created symlink and file' ' - cat >expected <<-\EOF && - diff --git a/frotz b/frotz - diff --git a/nitfol b/nitfol - EOF + >expected && rm -f frotz nitfol && echo xyzzy >nitfol && test-chmtime +10 nitfol && -- cgit v1.2.1