t3301: abstract away SHA-1-specific constants
Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Move some invocations of test_commit around so that we can compute the object IDs for these commits. Compute several object IDs in the tests instead of using hard-coded values so that the test works with any hash algorithm. Since the actual values are sorted by the object ID of the object being annotated, sort the expected values accordingly as well. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Aug 18, 2019 at 19:16 UTC
b408cf8cf67fdefa3cf72469599a407544624357
1 file changed
+90
-50
t/t3301-notes.sh
+90
-50
@@ -66,8 +66,9 @@ test_expect_success 'show notes entry with %N' '
66
'
67
68
test_expect_success 'create reflog entry' '
69
+ ref=$(git rev-parse --short refs/notes/commits) &&
70
cat <<-EOF >expect &&
70
- a1d8fa6 refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
71
+ $ref refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
72
EOF
73
git reflog show refs/notes/commits >actual &&
74
test_cmp expect actual
@@ -134,8 +135,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' '
135
'
136
137
test_expect_success 'show notes' '
138
+ commit=$(git rev-parse HEAD) &&
139
cat >expect <<-EOF &&
138
- commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691
140
+ commit $commit
141
Author: A U Thor <author@example.com>
142
Date: Thu Apr 7 15:14:13 2005 -0700
143
@@ -152,8 +154,9 @@ test_expect_success 'show notes' '
154
test_expect_success 'show multi-line notes' '
155
test_commit 3rd &&
156
MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
157
+ commit=$(git rev-parse HEAD) &&
158
cat >expect-multiline <<-EOF &&
156
- commit d07d62e5208f22eb5695e7eb47667dc8b9860290
159
+ commit $commit
160
Author: A U Thor <author@example.com>
161
Date: Thu Apr 7 15:15:13 2005 -0700
162
@@ -174,8 +177,9 @@ test_expect_success 'show -F notes' '
177
test_commit 4th &&
178
echo "xyzzy" >note5 &&
179
git notes add -F note5 &&
180
+ commit=$(git rev-parse HEAD) &&
181
cat >expect-F <<-EOF &&
178
- commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
182
+ commit $commit
183
Author: A U Thor <author@example.com>
184
Date: Thu Apr 7 15:16:13 2005 -0700
185
@@ -198,10 +202,13 @@ test_expect_success 'Re-adding -F notes without -f fails' '
202
'
203
204
test_expect_success 'git log --pretty=raw does not show notes' '
205
+ commit=$(git rev-parse HEAD) &&
206
+ tree=$(git rev-parse HEAD^{tree}) &&
207
+ parent=$(git rev-parse HEAD^) &&
208
cat >expect <<-EOF &&
202
- commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
203
- tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae
204
- parent d07d62e5208f22eb5695e7eb47667dc8b9860290
209
+ commit $commit
210
+ tree $tree
211
+ parent $parent
212
author A U Thor <author@example.com> 1112912173 -0700
213
committer C O Mitter <committer@example.com> 1112912173 -0700
214
@@ -291,8 +298,9 @@ test_expect_success 'git log --no-notes resets ref list' '
298
test_expect_success 'show -m notes' '
299
test_commit 5th &&
300
git notes add -m spam -m "foo${LF}bar${LF}baz" &&
301
+ commit=$(git rev-parse HEAD) &&
302
cat >expect-m <<-EOF &&
295
- commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
303
+ commit $commit
304
Author: A U Thor <author@example.com>
305
Date: Thu Apr 7 15:17:13 2005 -0700
306
@@ -313,8 +321,9 @@ test_expect_success 'show -m notes' '
321
322
test_expect_success 'remove note with add -f -F /dev/null' '
323
git notes add -f -F /dev/null &&
324
+ commit=$(git rev-parse HEAD) &&
325
cat >expect-rm-F <<-EOF &&
317
- commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
326
+ commit $commit
327
Author: A U Thor <author@example.com>
328
Date: Thu Apr 7 15:17:13 2005 -0700
329
@@ -356,14 +365,16 @@ test_expect_success 'create note with combination of -m and -F' '
365
test_expect_success 'remove note with "git notes remove"' '
366
git notes remove HEAD^ &&
367
git notes remove &&
368
+ commit=$(git rev-parse HEAD) &&
369
+ parent=$(git rev-parse HEAD^) &&
370
cat >expect-rm-remove <<-EOF &&
360
- commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
371
+ commit $commit
372
Author: A U Thor <author@example.com>
373
Date: Thu Apr 7 15:17:13 2005 -0700
374
375
${indent}5th
376
366
- commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
377
+ commit $parent
378
Author: A U Thor <author@example.com>
379
Date: Thu Apr 7 15:16:13 2005 -0700
380
@@ -459,9 +470,11 @@ test_expect_success 'removing with --stdin --ignore-missing' '
470
'
471
472
test_expect_success 'list notes with "git notes list"' '
462
- cat >expect <<-EOF &&
463
- c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
464
- c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
473
+ commit_2=$(git rev-parse 2nd) &&
474
+ commit_3=$(git rev-parse 3rd) &&
475
+ sort -t" " -k2 >expect <<-EOF &&
476
+ $(git rev-parse refs/notes/commits:$commit_2) $commit_2
477
+ $(git rev-parse refs/notes/commits:$commit_3) $commit_3
478
EOF
479
git notes list >actual &&
480
test_cmp expect actual
@@ -474,7 +487,7 @@ test_expect_success 'list notes with "git notes"' '
487
488
test_expect_success 'list specific note with "git notes list <object>"' '
489
cat >expect <<-EOF &&
477
- c18dc024e14f08d18d14eea0d747ff692d66d6a3
490
+ $(git rev-parse refs/notes/commits:$commit_3)
491
EOF
492
git notes list HEAD^^ >actual &&
493
test_cmp expect actual
@@ -498,10 +511,11 @@ test_expect_success 'append to existing note with "git notes append"' '
511
'
512
513
test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
501
- cat >expect_list <<-EOF &&
502
- c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
503
- 4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
504
- c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
514
+ commit_5=$(git rev-parse 5th) &&
515
+ sort -t" " -k2 >expect_list <<-EOF &&
516
+ $(git rev-parse refs/notes/commits:$commit_2) $commit_2
517
+ $(git rev-parse refs/notes/commits:$commit_3) $commit_3
518
+ $(git rev-parse refs/notes/commits:$commit_5) $commit_5
519
EOF
520
git notes list >actual &&
521
test_cmp expect_list actual
@@ -531,8 +545,9 @@ test_expect_success 'appending empty string to non-existing note does not create
545
test_expect_success 'create other note on a different notes ref (setup)' '
546
test_commit 6th &&
547
GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
548
+ commit=$(git rev-parse HEAD) &&
549
cat >expect-not-other <<-EOF &&
535
- commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
550
+ commit $commit
551
Author: A U Thor <author@example.com>
552
Date: Thu Apr 7 15:18:13 2005 -0700
553
@@ -569,8 +584,10 @@ test_expect_success 'Do not show note when core.notesRef is overridden' '
584
'
585
586
test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
587
+ commit=$(git rev-parse HEAD) &&
588
+ parent=$(git rev-parse HEAD^) &&
589
cat >expect-both <<-EOF &&
573
- commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
590
+ commit $commit
591
Author: A U Thor <author@example.com>
592
Date: Thu Apr 7 15:18:13 2005 -0700
593
@@ -582,7 +599,7 @@ test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
599
Notes (other):
600
${indent}other note
601
585
- commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
602
+ commit $parent
603
Author: A U Thor <author@example.com>
604
Date: Thu Apr 7 15:17:13 2005 -0700
605
@@ -616,8 +633,9 @@ test_expect_success 'notes.displayRef can be given more than once' '
633
'
634
635
test_expect_success 'notes.displayRef respects order' '
636
+ commit=$(git rev-parse HEAD) &&
637
cat >expect-both-reversed <<-EOF &&
620
- commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
638
+ commit $commit
639
Author: A U Thor <author@example.com>
640
Date: Thu Apr 7 15:18:13 2005 -0700
641
@@ -642,14 +660,16 @@ test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
660
'
661
662
test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
663
+ commit=$(git rev-parse HEAD) &&
664
+ parent=$(git rev-parse HEAD^) &&
665
cat >expect-none <<-EOF &&
646
- commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
666
+ commit $commit
667
Author: A U Thor <author@example.com>
668
Date: Thu Apr 7 15:18:13 2005 -0700
669
670
${indent}6th
671
652
- commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
672
+ commit $parent
673
Author: A U Thor <author@example.com>
674
Date: Thu Apr 7 15:17:13 2005 -0700
675
@@ -666,8 +686,9 @@ test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
686
'
687
688
test_expect_success '--no-standard-notes' '
689
+ commit=$(git rev-parse HEAD) &&
690
cat >expect-commits <<-EOF &&
670
- commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
691
+ commit $commit
692
Author: A U Thor <author@example.com>
693
Date: Thu Apr 7 15:18:13 2005 -0700
694
@@ -712,8 +733,10 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
733
'
734
735
test_expect_success 'create note from other note with "git notes add -C"' '
736
+ test_commit 7th &&
737
+ commit=$(git rev-parse HEAD) &&
738
cat >expect <<-EOF &&
716
- commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c
739
+ commit $commit
740
Author: A U Thor <author@example.com>
741
Date: Thu Apr 7 15:19:13 2005 -0700
742
@@ -722,7 +745,6 @@ test_expect_success 'create note from other note with "git notes add -C"' '
745
Notes:
746
${indent}order test
747
EOF
725
- test_commit 7th &&
748
git notes add -C $(git notes list HEAD^) &&
749
git log -1 >actual &&
750
test_cmp expect actual &&
@@ -744,8 +766,9 @@ test_expect_success 'create note from non-blob with "git notes add -C" fails' '
766
'
767
768
test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
769
+ commit=$(git rev-parse HEAD) &&
770
cat >expect <<-EOF &&
748
- commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf
771
+ commit $commit
772
Author: A U Thor <author@example.com>
773
Date: Thu Apr 7 15:20:13 2005 -0700
774
@@ -762,8 +785,10 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
785
'
786
787
test_expect_success 'create note from other note with "git notes add -c"' '
788
+ test_commit 9th &&
789
+ commit=$(git rev-parse HEAD) &&
790
cat >expect <<-EOF &&
766
- commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
791
+ commit $commit
792
Author: A U Thor <author@example.com>
793
Date: Thu Apr 7 15:21:13 2005 -0700
794
@@ -772,7 +797,6 @@ test_expect_success 'create note from other note with "git notes add -c"' '
797
Notes:
798
${indent}yet another note
799
EOF
775
- test_commit 9th &&
800
MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
801
git log -1 >actual &&
802
test_cmp expect actual
@@ -785,8 +809,9 @@ test_expect_success 'create note from non-existing note with "git notes add -c"
809
'
810
811
test_expect_success 'append to note from other note with "git notes append -C"' '
812
+ commit=$(git rev-parse HEAD^) &&
813
cat >expect <<-EOF &&
789
- commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
814
+ commit $commit
815
Author: A U Thor <author@example.com>
816
Date: Thu Apr 7 15:21:13 2005 -0700
817
@@ -803,8 +828,9 @@ test_expect_success 'append to note from other note with "git notes append -C"'
828
'
829
830
test_expect_success 'create note from other note with "git notes append -c"' '
831
+ commit=$(git rev-parse HEAD) &&
832
cat >expect <<-EOF &&
807
- commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
833
+ commit $commit
834
Author: A U Thor <author@example.com>
835
Date: Thu Apr 7 15:22:13 2005 -0700
836
@@ -819,8 +845,9 @@ test_expect_success 'create note from other note with "git notes append -c"' '
845
'
846
847
test_expect_success 'append to note from other note with "git notes append -c"' '
848
+ commit=$(git rev-parse HEAD) &&
849
cat >expect <<-EOF &&
823
- commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
850
+ commit $commit
851
Author: A U Thor <author@example.com>
852
Date: Thu Apr 7 15:22:13 2005 -0700
853
@@ -837,8 +864,10 @@ test_expect_success 'append to note from other note with "git notes append -c"'
864
'
865
866
test_expect_success 'copy note with "git notes copy"' '
867
+ test_commit 11th &&
868
+ commit=$(git rev-parse HEAD) &&
869
cat >expect <<-EOF &&
841
- commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
870
+ commit $commit
871
Author: A U Thor <author@example.com>
872
Date: Thu Apr 7 15:23:13 2005 -0700
873
@@ -849,7 +878,6 @@ test_expect_success 'copy note with "git notes copy"' '
878
${indent}
879
${indent}yet another note
880
EOF
852
- test_commit 11th &&
881
git notes copy HEAD^ HEAD &&
882
git log -1 >actual &&
883
test_cmp expect actual &&
@@ -864,8 +892,9 @@ test_expect_success 'prevent overwrite with "git notes copy"' '
892
'
893
894
test_expect_success 'allow overwrite with "git notes copy -f"' '
895
+ commit=$(git rev-parse HEAD) &&
896
cat >expect <<-EOF &&
868
- commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
897
+ commit $commit
898
Author: A U Thor <author@example.com>
899
Date: Thu Apr 7 15:23:13 2005 -0700
900
@@ -889,8 +918,10 @@ test_expect_success 'cannot copy note from object without notes' '
918
'
919
920
test_expect_success 'git notes copy --stdin' '
921
+ commit=$(git rev-parse HEAD) &&
922
+ parent=$(git rev-parse HEAD^) &&
923
cat >expect <<-EOF &&
893
- commit e871aa61182b1d95d0a6fb75445d891722863b6b
924
+ commit $commit
925
Author: A U Thor <author@example.com>
926
Date: Thu Apr 7 15:25:13 2005 -0700
927
@@ -901,7 +932,7 @@ test_expect_success 'git notes copy --stdin' '
932
${indent}
933
${indent}yet another note
934
904
- commit 65e263ded02ae4e8839bc151095113737579dc12
935
+ commit $parent
936
Author: A U Thor <author@example.com>
937
Date: Thu Apr 7 15:24:13 2005 -0700
938
@@ -922,21 +953,23 @@ test_expect_success 'git notes copy --stdin' '
953
'
954
955
test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
956
+ test_commit 14th &&
957
+ test_commit 15th &&
958
+ commit=$(git rev-parse HEAD) &&
959
+ parent=$(git rev-parse HEAD^) &&
960
cat >expect <<-EOF &&
926
- commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
961
+ commit $commit
962
Author: A U Thor <author@example.com>
963
Date: Thu Apr 7 15:27:13 2005 -0700
964
965
${indent}15th
966
932
- commit 07c85d77059393ed0154b8c96906547a59dfcddd
967
+ commit $parent
968
Author: A U Thor <author@example.com>
969
Date: Thu Apr 7 15:26:13 2005 -0700
970
971
${indent}14th
972
EOF
938
- test_commit 14th &&
939
- test_commit 15th &&
973
(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
974
echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
975
git notes copy --for-rewrite=foo &&
@@ -945,8 +978,10 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
978
'
979
980
test_expect_success 'git notes copy --for-rewrite (enabled)' '
981
+ commit=$(git rev-parse HEAD) &&
982
+ parent=$(git rev-parse HEAD^) &&
983
cat >expect <<-EOF &&
949
- commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
984
+ commit $commit
985
Author: A U Thor <author@example.com>
986
Date: Thu Apr 7 15:27:13 2005 -0700
987
@@ -957,7 +992,7 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
992
${indent}
993
${indent}yet another note
994
960
- commit 07c85d77059393ed0154b8c96906547a59dfcddd
995
+ commit $parent
996
Author: A U Thor <author@example.com>
997
Date: Thu Apr 7 15:26:13 2005 -0700
998
@@ -986,8 +1021,9 @@ test_expect_success 'git notes copy --for-rewrite (disabled)' '
1021
'
1022
1023
test_expect_success 'git notes copy --for-rewrite (overwrite)' '
1024
+ commit=$(git rev-parse HEAD) &&
1025
cat >expect <<-EOF &&
990
- commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1026
+ commit $commit
1027
Author: A U Thor <author@example.com>
1028
Date: Thu Apr 7 15:27:13 2005 -0700
1029
@@ -1015,8 +1051,9 @@ test_expect_success 'git notes copy --for-rewrite (ignore)' '
1051
'
1052
1053
test_expect_success 'git notes copy --for-rewrite (append)' '
1054
+ commit=$(git rev-parse HEAD) &&
1055
cat >expect <<-EOF &&
1019
- commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1056
+ commit $commit
1057
Author: A U Thor <author@example.com>
1058
Date: Thu Apr 7 15:27:13 2005 -0700
1059
@@ -1037,8 +1074,9 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
1074
'
1075
1076
test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1077
+ commit=$(git rev-parse HEAD) &&
1078
cat >expect <<-EOF &&
1041
- commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1079
+ commit $commit
1080
Author: A U Thor <author@example.com>
1081
Date: Thu Apr 7 15:27:13 2005 -0700
1082
@@ -1075,8 +1113,9 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' '
1113
'
1114
1115
test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1116
+ commit=$(git rev-parse HEAD) &&
1117
cat >expect <<-EOF &&
1079
- commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1118
+ commit $commit
1119
Author: A U Thor <author@example.com>
1120
Date: Thu Apr 7 15:27:13 2005 -0700
1121
@@ -1095,8 +1134,9 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1134
'
1135
1136
test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1137
+ commit=$(git rev-parse HEAD) &&
1138
cat >expect <<-EOF &&
1099
- commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1139
+ commit $commit
1140
Author: A U Thor <author@example.com>
1141
Date: Thu Apr 7 15:27:13 2005 -0700
1142