2007-11-22 07:06:44 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='rewrite diff'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
2008-08-08 09:26:28 +00:00
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >test &&
|
2007-11-22 07:06:44 +00: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 21:29:57 +00:00
|
|
|
tr \
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
|
|
|
|
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
|
2011-03-01 00:11:55 +00:00
|
|
|
<"$TEST_DIRECTORY"/../COPYING >test &&
|
|
|
|
echo "to be deleted" >test2 &&
|
|
|
|
git add test2
|
2007-11-22 07:06:44 +00: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 00:11:55 +00: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
|
|
|
|
'
|
|
|
|
|
2007-11-22 07:06:44 +00:00
|
|
|
test_done
|
|
|
|
|