mirror of
https://github.com/git/git.git
synced 2024-11-30 13:33:44 +08:00
8ddfce7144
We have a small helper function called "verbose", with the idea that you can write: verbose foo to get a message to stderr when the "foo" command fails, even if it does not produce any output itself. This goes back to8ad1652418
(t5304: use helper to report failure of "test foo = bar", 2014-10-10). It does work, but overall it has not been a big success for two reasons: 1. Test writers have to remember to put it there (and the resulting test code is longer as a result). 2. It doesn't handle the opposite case (we expect "foo" to fail, but it succeeds), leading to inconsistencies in tests (which you can see in many hunks of this patch, e.g. ones involving "has_cr"). Most importantly, we addeda136f6d8ff
(test-lib.sh: support -x option for shell-tracing, 2014-10-10) at the same time, and it does roughly the same thing. The output is not quite as succinct as "verbose", and you have to watch out for stray shell-traces ending up in stderr. But it solves both of the problems above, and has clearly become the preferred tool. Let's consider the "verbose" function a failed experiment and remove the last few callers (which are all many years old, and have been dwindling as we remove them from scripts we touch for other reasons). It will be one less thing for new test writers to see and wonder if they should be using themselves. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
102 lines
2.1 KiB
Bash
Executable File
102 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='rewrite diff'
|
|
|
|
. ./test-lib.sh
|
|
. "$TEST_DIRECTORY"/lib-diff-data.sh
|
|
|
|
test_expect_success setup '
|
|
|
|
COPYING_test_data >test.data &&
|
|
cp test.data test &&
|
|
git add test &&
|
|
tr \
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
|
|
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
|
|
<test.data >test &&
|
|
echo "to be deleted" >test2 &&
|
|
blob=$(git hash-object test2) &&
|
|
blob=$(git rev-parse --short $blob) &&
|
|
git add test2
|
|
|
|
'
|
|
|
|
test_expect_success 'detect rewrite' '
|
|
|
|
actual=$(git diff-files -B --summary test) &&
|
|
expr "$actual" : " rewrite test ([0-9]*%)$"
|
|
|
|
'
|
|
|
|
cat >expect <<EOF
|
|
diff --git a/test2 b/test2
|
|
deleted file mode 100644
|
|
index $blob..0000000
|
|
--- a/test2
|
|
+++ /dev/null
|
|
@@ -1 +0,0 @@
|
|
-to be deleted
|
|
EOF
|
|
test_expect_success 'show deletion diff without -D' '
|
|
|
|
rm test2 &&
|
|
git diff -- test2 >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
cat >expect <<EOF
|
|
diff --git a/test2 b/test2
|
|
deleted file mode 100644
|
|
index $blob..0000000
|
|
EOF
|
|
test_expect_success 'suppress deletion diff with -D' '
|
|
|
|
git diff -D -- test2 >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'show deletion diff with -B' '
|
|
|
|
git diff -B -- test >actual &&
|
|
grep "Linus Torvalds" actual
|
|
'
|
|
|
|
test_expect_success 'suppress deletion diff with -B -D' '
|
|
|
|
git diff -B -D -- test >actual &&
|
|
grep -v "Linus Torvalds" actual
|
|
'
|
|
|
|
test_expect_success 'prepare a file that ends with an incomplete line' '
|
|
test_seq 1 99 >seq &&
|
|
printf 100 >>seq &&
|
|
git add seq &&
|
|
git commit seq -m seq
|
|
'
|
|
|
|
test_expect_success 'rewrite the middle 90% of sequence file and terminate with newline' '
|
|
test_seq 1 5 >seq &&
|
|
test_seq 9331 9420 >>seq &&
|
|
test_seq 96 100 >>seq
|
|
'
|
|
|
|
test_expect_success 'confirm that sequence file is considered a rewrite' '
|
|
git diff -B seq >res &&
|
|
grep "dissimilarity index" res
|
|
'
|
|
|
|
test_expect_success 'no newline at eof is on its own line without -B' '
|
|
git diff seq >res &&
|
|
grep "^\\\\ " res &&
|
|
! grep "^..*\\\\ " res
|
|
'
|
|
|
|
test_expect_success 'no newline at eof is on its own line with -B' '
|
|
git diff -B seq >res &&
|
|
grep "^\\\\ " res &&
|
|
! grep "^..*\\\\ " res
|
|
'
|
|
|
|
test_done
|
|
|