summaryrefslogtreecommitdiff
path: root/t/t4044-diff-index-unique-abbrev.sh
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2010-05-30 13:37:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-06-01 00:44:01 (GMT)
commit3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf (patch)
tree126ef36605cca11b458eeee5c9e4150a4effe553 /t/t4044-diff-index-unique-abbrev.sh
parent81fa024cd8e336ba257f13fe7724b95baacfa3ad (diff)
downloadgit-3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf.zip
git-3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf.tar.gz
git-3e5a188f1d5b48dcc0bc73ad520925cdb846dfaf.tar.bz2
diff.c: Ensure "index $from..$to" line contains unambiguous SHA1s
In the metainfo section of git diffs there's an "index" line providing abbreviated (unless --full-index is used) blob SHA1s from the pre-/post-images used to generate the diff. These provide hints that can be used to reconstruct a 3-way merge when applying the patch (see the --3way option to 'git am' for more details). In order for this to work, however, the blob SHA1s must not be abbreviated into ambiguity. This patch eliminates the possible ambiguity by using find_unique_abbrev() to produce the abbreviated SHA1s (instead of blind abbreviation by way of "%.*s"). A testcase verifying the fix is also included. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4044-diff-index-unique-abbrev.sh')
-rwxr-xr-xt/t4044-diff-index-unique-abbrev.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/t/t4044-diff-index-unique-abbrev.sh b/t/t4044-diff-index-unique-abbrev.sh
new file mode 100755
index 0000000..d5ce72b
--- /dev/null
+++ b/t/t4044-diff-index-unique-abbrev.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+test_description='test unique sha1 abbreviation on "index from..to" line'
+. ./test-lib.sh
+
+cat >expect_initial <<EOF
+100644 blob 51d2738463ea4ca66f8691c91e33ce64b7d41bb1 foo
+EOF
+
+cat >expect_update <<EOF
+100644 blob 51d2738efb4ad8a1e40bed839ab8e116f0a15e47 foo
+EOF
+
+test_expect_success 'setup' '
+ echo 4827 > foo &&
+ git add foo &&
+ git commit -m "initial" &&
+ git cat-file -p HEAD: > actual &&
+ test_cmp expect_initial actual &&
+ echo 11742 > foo &&
+ git commit -a -m "update" &&
+ git cat-file -p HEAD: > actual &&
+ test_cmp expect_update actual
+'
+
+cat >expect <<EOF
+index 51d27384..51d2738e 100644
+EOF
+
+test_expect_success 'diff does not produce ambiguous index line' '
+ git diff HEAD^..HEAD | grep index > actual &&
+ test_cmp expect actual
+'
+
+test_done