2007-11-22 08:06:44 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='rewrite diff'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
2008-08-08 11:26:28 +02:00
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >test &&
|
2007-11-22 08:06:44 +01: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 22:29:57 +01:00
|
|
|
tr \
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
|
|
|
|
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
|
2011-03-01 01:11:55 +01:00
|
|
|
<"$TEST_DIRECTORY"/../COPYING >test &&
|
|
|
|
echo "to be deleted" >test2 &&
|
|
|
|
git add test2
|
2007-11-22 08:06:44 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'detect rewrite' '
|
|
|
|
|
|
|
|
actual=$(git diff-files -B --summary test) &&
|
|
|
|
expr "$actual" : " rewrite test ([0-9]*%)$" || {
|
|
|
|
echo "Eh? <<$actual>>"
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2011-03-01 01:11:55 +01:00
|
|
|
cat >expect <<EOF
|
|
|
|
diff --git a/test2 b/test2
|
|
|
|
deleted file mode 100644
|
|
|
|
index 4202011..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 4202011..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
|
|
|
|
'
|
|
|
|
|
2012-08-04 23:07:35 +02: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 08:06:44 +01:00
|
|
|
test_done
|
|
|
|
|