2007-12-01 09:22:38 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='typechange rename detection'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
test_expect_success setup '
|
2007-12-01 09:22:38 +03:00
|
|
|
|
|
|
|
rm -f foo bar &&
|
2008-08-08 13:26:28 +04:00
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >foo &&
|
2013-06-08 00:53:32 +04:00
|
|
|
test_ln_s_add linklink bar &&
|
|
|
|
git add foo &&
|
2007-12-01 09:22:38 +03:00
|
|
|
git commit -a -m Initial &&
|
|
|
|
git tag one &&
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
git rm -f foo bar &&
|
2008-08-08 13:26:28 +04:00
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >bar &&
|
2013-06-08 00:53:32 +04:00
|
|
|
test_ln_s_add linklink foo &&
|
|
|
|
git add bar &&
|
2007-12-01 09:22:38 +03:00
|
|
|
git commit -a -m Second &&
|
|
|
|
git tag two &&
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
git rm -f foo bar &&
|
2008-08-08 13:26:28 +04:00
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >foo &&
|
2007-12-01 09:22:38 +03:00
|
|
|
git add foo &&
|
|
|
|
git commit -a -m Third &&
|
|
|
|
git tag three &&
|
|
|
|
|
|
|
|
mv foo bar &&
|
2013-06-08 00:53:32 +04:00
|
|
|
test_ln_s_add linklink foo &&
|
|
|
|
git add bar &&
|
2007-12-01 09:22:38 +03:00
|
|
|
git commit -a -m Fourth &&
|
|
|
|
git tag four &&
|
|
|
|
|
|
|
|
# This is purely for sanity check
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
git rm -f foo bar &&
|
2008-08-08 13:26:28 +04:00
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >foo &&
|
|
|
|
cat "$TEST_DIRECTORY"/../Makefile >bar &&
|
2007-12-01 09:22:38 +03:00
|
|
|
git add foo bar &&
|
|
|
|
git commit -a -m Fifth &&
|
|
|
|
git tag five &&
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
git rm -f foo bar &&
|
2008-08-08 13:26:28 +04:00
|
|
|
cat "$TEST_DIRECTORY"/../Makefile >foo &&
|
|
|
|
cat "$TEST_DIRECTORY"/../COPYING >bar &&
|
2007-12-01 09:22:38 +03:00
|
|
|
git add foo bar &&
|
|
|
|
git commit -a -m Sixth &&
|
|
|
|
git tag six
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
test_expect_success 'cross renames to be detected for regular files' '
|
2007-12-01 09:22:38 +03:00
|
|
|
|
|
|
|
git diff-tree five six -r --name-status -B -M | sort >actual &&
|
|
|
|
{
|
|
|
|
echo "R100 foo bar"
|
|
|
|
echo "R100 bar foo"
|
|
|
|
} | sort >expect &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expect actual
|
2007-12-01 09:22:38 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
test_expect_success 'cross renames to be detected for typechange' '
|
2007-12-01 09:22:38 +03:00
|
|
|
|
|
|
|
git diff-tree one two -r --name-status -B -M | sort >actual &&
|
|
|
|
{
|
|
|
|
echo "R100 foo bar"
|
|
|
|
echo "R100 bar foo"
|
|
|
|
} | sort >expect &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expect actual
|
2007-12-01 09:22:38 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-06-08 00:53:32 +04:00
|
|
|
test_expect_success 'moves and renames' '
|
2007-12-01 09:22:38 +03:00
|
|
|
|
|
|
|
git diff-tree three four -r --name-status -B -M | sort >actual &&
|
|
|
|
{
|
diff -B -M: fix output for "copy and then rewrite" case
Starting from a single file, A, if you create B as a copy of A (and
possibly make some edit) and then make extensive change to A, you
will see:
$ git diff -C --name-status
C89 A B
M A
which is expected. However, if you ask the same question in a
different way, you see this:
$ git diff -B -M --name-status
R89 A B
M100 A
telling us that A was rename-edited into B (as if "A will no longer
exist as the result") and at the same time A itself was extensively
edited.
In this case, because the resulting tree still does have file A
(even if it has contents vastly different from the original), we
should use "C"opy, not "R"ename, to avoid hinting that A somehow
goes away.
Two existing tests were depending on the wrong behaviour, and fixed.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-23 21:02:02 +04:00
|
|
|
# see -B -M (#6) in t4008
|
|
|
|
echo "C100 foo bar"
|
2007-12-01 09:22:38 +03:00
|
|
|
echo "T100 foo"
|
|
|
|
} | sort >expect &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expect actual
|
2007-12-01 09:22:38 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|