Git fork
at reftables-rust 160 lines 4.7 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2005 Junio C Hamano 4# 5 6test_description='Break and then rename 7 8We have two very different files, file0 and file1, registered in a tree. 9 10We update file1 so drastically that it is more similar to file0, and 11then remove file0. With -B, changes to file1 should be broken into 12separate delete and create, resulting in removal of file0, removal of 13original file1 and creation of completely rewritten file1. The latter 14two are then merged back into a single "complete rewrite". 15 16Further, with -B and -M together, these three modifications should 17turn into rename-edit of file0 into file1. 18 19Starting from the same two files in the tree, we swap file0 and file1. 20With -B, this should be detected as two complete rewrites. 21 22Further, with -B and -M together, these should turn into two renames. 23' 24 25. ./test-lib.sh 26. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash 27 28test_expect_success setup ' 29 echo some dissimilar content >file0 && 30 COPYING_test_data >file1 && 31 blob0_id=$(git hash-object file0) && 32 blob1_id=$(git hash-object file1) && 33 git update-index --add file0 file1 && 34 git tag reference $(git write-tree) 35' 36 37test_expect_success 'change file1 with copy-edit of file0 and remove file0' ' 38 sed -e "s/git/GIT/" file0 >file1 && 39 blob2_id=$(git hash-object file1) && 40 rm -f file0 && 41 git update-index --remove file0 file1 42' 43 44test_expect_success 'run diff with -B (#1)' ' 45 git diff-index -B --cached reference >current && 46 cat >expect <<-EOF && 47 :100644 000000 $blob0_id $ZERO_OID D file0 48 :100644 100644 $blob1_id $blob2_id M100 file1 49 EOF 50 compare_diff_raw expect current 51' 52 53test_expect_success 'run diff with -B and -M (#2)' ' 54 git diff-index -B -M reference >current && 55 cat >expect <<-EOF && 56 :100644 100644 $blob0_id $blob2_id R100 file0 file1 57 EOF 58 compare_diff_raw expect current 59' 60 61test_expect_success 'swap file0 and file1' ' 62 rm -f file0 file1 && 63 git read-tree -m reference && 64 git checkout-index -f -u -a && 65 mv file0 tmp && 66 mv file1 file0 && 67 mv tmp file1 && 68 git update-index file0 file1 69' 70 71test_expect_success 'run diff with -B (#3)' ' 72 git diff-index -B reference >current && 73 cat >expect <<-EOF && 74 :100644 100644 $blob0_id $blob1_id M100 file0 75 :100644 100644 $blob1_id $blob0_id M100 file1 76 EOF 77 compare_diff_raw expect current 78' 79 80test_expect_success 'run diff with -B and -M (#4)' ' 81 git diff-index -B -M reference >current && 82 cat >expect <<-EOF && 83 :100644 100644 $blob1_id $blob1_id R100 file1 file0 84 :100644 100644 $blob0_id $blob0_id R100 file0 file1 85 EOF 86 compare_diff_raw expect current 87' 88 89test_expect_success 'make file0 into something completely different' ' 90 rm -f file0 && 91 test_ln_s_add frotz file0 && 92 slink_id=$(printf frotz | git hash-object --stdin) && 93 git update-index file1 94' 95 96test_expect_success 'run diff with -B (#5)' ' 97 git diff-index -B reference >current && 98 cat >expect <<-EOF && 99 :100644 120000 $blob0_id $slink_id T file0 100 :100644 100644 $blob1_id $blob0_id M100 file1 101 EOF 102 compare_diff_raw expect current 103' 104 105test_expect_success 'run diff with -B -M (#6)' ' 106 git diff-index -B -M reference >current && 107 108 # file0 changed from regular to symlink. file1 is the same as the preimage 109 # of file0. Because the change does not make file0 disappear, file1 is 110 # denoted as a copy of file0 111 cat >expect <<-EOF && 112 :100644 120000 $blob0_id $slink_id T file0 113 :100644 100644 $blob0_id $blob0_id C file0 file1 114 EOF 115 compare_diff_raw expect current 116' 117 118test_expect_success 'run diff with -M (#7)' ' 119 git diff-index -M reference >current && 120 121 # This should not mistake file0 as the copy source of new file1 122 # due to type differences. 123 cat >expect <<-EOF && 124 :100644 120000 $blob0_id $slink_id T file0 125 :100644 100644 $blob1_id $blob0_id M file1 126 EOF 127 compare_diff_raw expect current 128' 129 130test_expect_success 'file1 edited to look like file0 and file0 rename-edited to file2' ' 131 rm -f file0 file1 && 132 git read-tree -m reference && 133 git checkout-index -f -u -a && 134 sed -e "s/git/GIT/" file0 >file1 && 135 sed -e "s/git/GET/" file0 >file2 && 136 blob3_id=$(git hash-object file2) && 137 rm -f file0 && 138 git update-index --add --remove file0 file1 file2 139' 140 141test_expect_success 'run diff with -B (#8)' ' 142 git diff-index -B reference >current && 143 cat >expect <<-EOF && 144 :100644 000000 $blob0_id $ZERO_OID D file0 145 :100644 100644 $blob1_id $blob2_id M100 file1 146 :000000 100644 $ZERO_OID $blob3_id A file2 147 EOF 148 compare_diff_raw expect current 149' 150 151test_expect_success 'run diff with -B -C (#9)' ' 152 git diff-index -B -C reference >current && 153 cat >expect <<-EOF && 154 :100644 100644 $blob0_id $blob2_id C095 file0 file1 155 :100644 100644 $blob0_id $blob3_id R095 file0 file2 156 EOF 157 compare_diff_raw expect current 158' 159 160test_done