Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t4204-patch-id.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t4204-patch-id.sh` 347 lines ยท 8517 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git patch-id' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 test_expect_success 'setup' ' 11 str="ab cd ef gh ij kl mn op" && 12 test_write_lines $str >foo && 13 test_write_lines $str >bar && 14 git add foo bar && 15 git commit -a -m initial && 16 test_write_lines $str b >foo && 17 test_write_lines $str b >bar && 18 git commit -a -m first && 19 git checkout -b same main && 20 git commit --amend -m same-msg && 21 git checkout -b notsame main && 22 echo c >foo && 23 echo c >bar && 24 git commit --amend -a -m notsame-msg && 25 git checkout -b with_space main~ && 26 cat >foo <<-\EOF && 27 a b 28 c d 29 e f 30 g h 31 i j 32 k l 33 m n 34 op 35 EOF 36 cp foo bar && 37 git add foo bar && 38 git commit --amend -m "with spaces" && 39 test_write_lines bar foo >bar-then-foo && 40 test_write_lines foo bar >foo-then-bar 41 42 ' 43 44 test_expect_success 'patch-id output is well-formed' ' 45 git log -p -1 >log.output && 46 git patch-id output && 47 test_grep "^$OID_REGEX $(git rev-parse HEAD)$" output 48 ' 49 50 #calculate patch id. Make sure output is not empty. 51 calc_patch_id () { 52 patch_name="$1" 53 shift 54 git patch-id "$@" >patch-id.output && 55 sed "s/ .*//" patch-id.output >patch-id_"$patch_name" && 56 test_line_count -eq 1 patch-id_"$patch_name" 57 } 58 59 get_top_diff () { 60 git log -p -1 "$@" -O bar-then-foo --full-index -- 61 } 62 63 get_patch_id () { 64 get_top_diff "$1" >top-diff.output && 65 calc_patch_id .gitattributes <<-\EOF && 81 foo binary 82 bar binary 83 EOF 84 get_patch_id main && 85 get_patch_id same && 86 git log -p -1 --binary main >top-diff.output && 87 calc_patch_id top-diff.output && 89 calc_patch_id .gitattributes <<-\EOF && 98 foo binary 99 bar binary 100 EOF 101 get_patch_id main && 102 get_patch_id notsame && 103 ! test_cmp patch-id_main patch-id_notsame && 104 test_when_finished "rm .gitattributes" 105 ' 106 107 test_expect_success 'patch-id supports git-format-patch output' ' 108 get_patch_id main && 109 git checkout same && 110 git format-patch -1 --stdout >format-patch.output && 111 calc_patch_id same format-patch.output && 121 sed "s/ \$//" format-patch.output | calc_patch_id same && 122 test_cmp patch-id_main patch-id_same 123 ' 124 125 cmp_patch_id () { 126 if 127 test "$1" = "relevant" 128 then 129 ! test_cmp patch-id_"$2" patch-id_"$3" 130 else 131 test_cmp patch-id_"$2" patch-id_"$3" 132 fi 133 } 134 135 test_patch_id_file_order () { 136 relevant="$1" 137 shift 138 name="order-${1}-$relevant" 139 shift 140 get_top_diff "main" >top-diff.output && 141 calc_patch_id format-patch.output && 144 calc_patch_id top-diff.output && 154 calc_patch_id top-diff.output && 156 calc_patch_id format-patch.output && 229 calc_patch_id nonl <<-\EOF && 249 diff --git i/a w/a 250 index `e69de29`..`2e65efe` 100644 251 --- i/a 252 +++ w/a 253 @@ -0,0 +1 @@ 254 +a 255 \ No newline at end of file 256 diff --git i/b w/b 257 index `e69de29`..`6178079` 100644 258 --- i/b 259 +++ w/b 260 @@ -0,0 +1 @@ 261 +b 262 EOF 263 cat >withnl <<-\EOF && 264 diff --git i/a w/a 265 index `e69de29`..`7898192` 100644 266 --- i/a 267 +++ w/a 268 @@ -0,0 +1 @@ 269 +a 270 diff --git i/b w/b 271 index `e69de29`..`6178079` 100644 272 --- i/b 273 +++ w/b 274 @@ -0,0 +1 @@ 275 +b 276 EOF 277 calc_patch_id nonl diffu1 <<-\EOF && 287 diff --git a/bar b/bar 288 index `bdaf90f`..`31051f6` 100644 289 --- a/bar 290 +++ b/bar 291 @@ -2 +2,2 @@ 292 b 293 +c 294 diff --git a/car b/car 295 index `00750ed`..`2ae5e34` 100644 296 --- a/car 297 +++ b/car 298 @@ -1 +1,2 @@ 299 3 300 +d 301 diff --git a/foo b/foo 302 index `e439850`..`7146eb8` 100644 303 --- a/foo 304 +++ b/foo 305 @@ -2 +2,2 @@ 306 a 307 +e 308 EOF 309 calc_patch_id diffu1 diff <<-\EOF && 318 diff --git a/bar b/bar 319 index `bdaf90f`..`31051f6` 100644 320 --- a/bar 321 +++ b/bar 322 @@ -2 +2,2 @@ 323 b 324 +c 325 EOF 326 327 git init --object-format=sha1 repo-sha1 && 328 git -C repo-sha1 patch-id patch-id-sha1 && 329 git init --object-format=sha256 repo-sha256 && 330 git -C repo-sha256 patch-id patch-id-sha256 && 331 test_cmp patch-id-sha1 patch-id-sha256 332 ' 333 334 test_expect_success 'patch-id without repository' ' 335 cat >diff <<-\EOF && 336 diff --git a/bar b/bar 337 index `bdaf90f`..`31051f6` 100644 338 --- a/bar 339 +++ b/bar 340 @@ -2 +2,2 @@ 341 b 342 +c 343 EOF 344 nongit git patch-id