2007-11-22 00:06:44 -07:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='rewrite diff'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
2021-10-15 03:30:17 -06:00
|
|
|
. "$TEST_DIRECTORY"/lib-diff-data.sh
|
2007-11-22 00:06:44 -07:00
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
2021-10-15 03:30:17 -06:00
|
|
|
COPYING_test_data >test.data &&
|
|
|
|
cp test.data test &&
|
2007-11-22 00:06:44 -07:00
|
|
|
git add test &&
|
tr portability fixes
Specifying character ranges in tr differs between System V
and POSIX. In System V, brackets are required (e.g.,
'[A-Z]'), whereas in POSIX they are not.
We can mostly get around this by just using the bracket form
for both sets, as in:
tr '[A-Z] '[a-z]'
in which case POSIX interpets this as "'[' becomes '['",
which is OK.
However, this doesn't work with multiple sequences, like:
# rot13
tr '[A-Z][a-z]' '[N-Z][A-M][n-z][a-m]'
where the POSIX version does not behave the same as the
System V version. In this case, we must simply enumerate the
sequence.
This patch fixes problematic uses of tr in git scripts and
test scripts in one of three ways:
- if a single sequence, make sure it uses brackets
- if multiple sequences, enumerate
- if extra brackets (e.g., tr '[A]' 'a'), eliminate
brackets
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-12 15:29:57 -06:00
|
|
|
tr \
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
|
|
|
|
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
|
2021-10-15 03:30:17 -06:00
|
|
|
<test.data >test &&
|
2011-02-28 17:11:55 -07:00
|
|
|
echo "to be deleted" >test2 &&
|
2018-05-20 20:01:38 -06:00
|
|
|
blob=$(git hash-object test2) &&
|
|
|
|
blob=$(git rev-parse --short $blob) &&
|
2011-02-28 17:11:55 -07:00
|
|
|
git add test2
|
2007-11-22 00:06:44 -07:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'detect rewrite' '
|
|
|
|
|
|
|
|
actual=$(git diff-files -B --summary test) &&
|
t: drop "verbose" helper function
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 to 8ad1652418 (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 added a136f6d8ff (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>
2023-05-08 13:04:57 -06:00
|
|
|
expr "$actual" : " rewrite test ([0-9]*%)$"
|
2007-11-22 00:06:44 -07:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2011-02-28 17:11:55 -07:00
|
|
|
cat >expect <<EOF
|
|
|
|
diff --git a/test2 b/test2
|
|
|
|
deleted file mode 100644
|
2018-05-20 20:01:38 -06:00
|
|
|
index $blob..0000000
|
2011-02-28 17:11:55 -07:00
|
|
|
--- 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
|
2018-05-20 20:01:38 -06:00
|
|
|
index $blob..0000000
|
2011-02-28 17:11:55 -07:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2012-08-04 15:07:35 -06:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2007-11-22 00:06:44 -07:00
|
|
|
test_done
|
|
|
|
|