2007-11-22 10:06:44 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='rewrite diff'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
2008-08-08 13:26:28 +04:00
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >test &&
|
2007-11-22 10:06:44 +03: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-13 00:29:57 +03:00
|
|
|
tr \
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
|
|
|
|
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
|
2011-03-01 03:11:55 +03:00
|
|
|
<"$TEST_DIRECTORY"/../COPYING >test &&
|
|
|
|
echo "to be deleted" >test2 &&
|
2018-05-21 05:01:38 +03:00
|
|
|
blob=$(git hash-object test2) &&
|
|
|
|
blob=$(git rev-parse --short $blob) &&
|
2011-03-01 03:11:55 +03:00
|
|
|
git add test2
|
2007-11-22 10:06:44 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'detect rewrite' '
|
|
|
|
|
|
|
|
actual=$(git diff-files -B --summary test) &&
|
2015-03-20 13:09:00 +03:00
|
|
|
verbose expr "$actual" : " rewrite test ([0-9]*%)$"
|
2007-11-22 10:06:44 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2011-03-01 03:11:55 +03:00
|
|
|
cat >expect <<EOF
|
|
|
|
diff --git a/test2 b/test2
|
|
|
|
deleted file mode 100644
|
2018-05-21 05:01:38 +03:00
|
|
|
index $blob..0000000
|
2011-03-01 03:11:55 +03: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-21 05:01:38 +03:00
|
|
|
index $blob..0000000
|
2011-03-01 03:11:55 +03: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-05 01:07:35 +04: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 10:06:44 +03:00
|
|
|
test_done
|
|
|
|
|