@@ -17,16 +17,29 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
17
17
. ./test-lib.sh
18
18
19
19
check_describe () {
20
+ indir= &&
21
+ while test $# ! = 0
22
+ do
23
+ case " $1 " in
24
+ -C)
25
+ indir=" $2 "
26
+ shift
27
+ ;;
28
+ * )
29
+ break
30
+ ;;
31
+ esac
32
+ shift
33
+ done &&
34
+ indir=${indir: +" $indir " / } &&
20
35
expect=" $1 "
21
36
shift
22
37
describe_opts=" $@ "
23
38
test_expect_success " describe $describe_opts " '
24
- R=$(git describe $describe_opts 2>err.actual) &&
25
- case "$R" in
26
- $expect) echo happy ;;
27
- *) echo "Oops - $R is not $expect" &&
28
- false ;;
29
- esac
39
+ git ${indir:+ -C "$indir"} describe $describe_opts >raw &&
40
+ sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
41
+ echo "$expect" >expect &&
42
+ test_cmp expect actual
30
43
'
31
44
}
32
45
@@ -59,29 +72,29 @@ test_expect_success setup '
59
72
test_commit --no-tag x file
60
73
'
61
74
62
- check_describe A-* HEAD
63
- check_describe A-* HEAD^
64
- check_describe R-* HEAD^^
65
- check_describe A-* HEAD^^2
75
+ check_describe A-8-gHASH HEAD
76
+ check_describe A-7-gHASH HEAD^
77
+ check_describe R-2-gHASH HEAD^^
78
+ check_describe A-3-gHASH HEAD^^2
66
79
check_describe B HEAD^^2^
67
- check_describe R-* HEAD^^^
80
+ check_describe R-1-gHASH HEAD^^^
68
81
69
- check_describe c-* --tags HEAD
70
- check_describe c-* --tags HEAD^
71
- check_describe e-* --tags HEAD^^
72
- check_describe c-* --tags HEAD^^2
82
+ check_describe c-7-gHASH --tags HEAD
83
+ check_describe c-6-gHASH --tags HEAD^
84
+ check_describe e-1-gHASH --tags HEAD^^
85
+ check_describe c-2-gHASH --tags HEAD^^2
73
86
check_describe B --tags HEAD^^2^
74
87
check_describe e --tags HEAD^^^
75
88
76
89
check_describe heads/main --all HEAD
77
- check_describe tags/c-* --all HEAD^
90
+ check_describe tags/c-6-gHASH --all HEAD^
78
91
check_describe tags/e --all HEAD^^^
79
92
80
- check_describe B-0-* --long HEAD^^2^
81
- check_describe A-3-* --long HEAD^^2
93
+ check_describe B-0-gHASH --long HEAD^^2^
94
+ check_describe A-3-gHASH --long HEAD^^2
82
95
83
- check_describe c-7-* --tags
84
- check_describe e-3-* --first-parent --tags
96
+ check_describe c-7-gHASH --tags
97
+ check_describe e-3-gHASH --first-parent --tags
85
98
86
99
test_expect_success ' describe --contains defaults to HEAD without commit-ish' '
87
100
echo "A^0" >expect &&
@@ -92,20 +105,17 @@ test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
92
105
'
93
106
94
107
check_describe tags/A --all A^0
95
- test_expect_success ' no warning was displayed for A' '
96
- test_must_be_empty err.actual
97
- '
98
108
99
- test_expect_success ' rename tag A to Q locally' '
100
- mv .git/refs/tags/A .git/refs/tags/Q
101
- '
102
- cat - > err.expect << EOF
103
- warning: tag 'Q' is externally known as 'A'
104
- EOF
105
- check_describe A- * HEAD
106
- test_expect_success ' warning was displayed for Q ' '
107
- test_cmp err.expect err.actual
108
- '
109
+ test_expect_success ' renaming tag A to Q locally produces a warning ' "
110
+ mv .git/refs/tags/A .git/refs/tags/Q &&
111
+ git describe HEAD 2>err >out &&
112
+ cat >expected <<-\ EOF &&
113
+ warning: tag 'Q' is externally known as 'A'
114
+ EOF
115
+ test_cmp expected err &&
116
+ grep -E '^A-8-g[0-9a-f]+$' out
117
+ "
118
+
109
119
test_expect_success ' misnamed annotated tag forces long output' '
110
120
description=$(git describe --no-long Q^0) &&
111
121
expr "$description" : "A-0-g[0-9a-f]*$" &&
@@ -129,46 +139,46 @@ test_expect_success 'rename tag Q back to A' '
129
139
'
130
140
131
141
test_expect_success ' pack tag refs' ' git pack-refs'
132
- check_describe A-* HEAD
142
+ check_describe A-8-gHASH HEAD
133
143
134
144
test_expect_success ' describe works from outside repo using --git-dir' '
135
145
git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
136
146
git --git-dir "$TRASH_DIRECTORY/bare" describe >out &&
137
- grep -E "^A-[1-9][0-9]? -g[0-9a-f]+$" out
147
+ grep -E "^A-8 -g[0-9a-f]+$" out
138
148
'
139
149
140
- check_describe " A-*[0-9a-f] " --dirty
150
+ check_describe " A-8-gHASH " --dirty
141
151
142
152
test_expect_success ' describe --dirty with --work-tree' '
143
153
(
144
154
cd "$TEST_DIRECTORY" &&
145
155
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
146
156
) &&
147
- grep -E "^A-[1-9][0-9]? -g[0-9a-f]+$" out
157
+ grep -E "^A-8 -g[0-9a-f]+$" out
148
158
'
149
159
150
160
test_expect_success ' set-up dirty work tree' '
151
161
echo >>file
152
162
'
153
163
154
- check_describe " A-*[0-9a-f]-dirty" --dirty
155
-
156
164
test_expect_success ' describe --dirty with --work-tree (dirty)' '
165
+ git describe --dirty >expected &&
157
166
(
158
167
cd "$TEST_DIRECTORY" &&
159
168
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
160
169
) &&
161
- grep -E "^A-[1-9][0-9]?-g[0-9a-f]+-dirty$" out
170
+ grep -E "^A-8-g[0-9a-f]+-dirty$" out &&
171
+ test_cmp expected out
162
172
'
163
173
164
- check_describe " A-*[0-9a-f].mod" --dirty=.mod
165
-
166
174
test_expect_success ' describe --dirty=.mod with --work-tree (dirty)' '
175
+ git describe --dirty=.mod >expected &&
167
176
(
168
177
cd "$TEST_DIRECTORY" &&
169
178
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
170
179
) &&
171
- grep -E "^A-[1-9][0-9]?-g[0-9a-f]+.mod$" out
180
+ grep -E "^A-8-g[0-9a-f]+.mod$" out &&
181
+ test_cmp expected out
172
182
'
173
183
174
184
test_expect_success ' describe --dirty HEAD' '
@@ -191,21 +201,21 @@ test_expect_success 'set-up matching pattern tests' '
191
201
192
202
'
193
203
194
- check_describe " test-annotated-* " --match=" test-*"
204
+ check_describe " test-annotated-3-gHASH " --match=" test-*"
195
205
196
- check_describe " test1-lightweight-* " --tags --match=" test1-*"
206
+ check_describe " test1-lightweight-2-gHASH " --tags --match=" test1-*"
197
207
198
- check_describe " test2-lightweight-* " --tags --match=" test2-*"
208
+ check_describe " test2-lightweight-1-gHASH " --tags --match=" test2-*"
199
209
200
- check_describe " test2-lightweight-* " --long --tags --match=" test2-*" HEAD^
210
+ check_describe " test2-lightweight-0-gHASH " --long --tags --match=" test2-*" HEAD^
201
211
202
- check_describe " test2-lightweight-* " --long --tags --match=" test1-*" --match=" test2-*" HEAD^
212
+ check_describe " test2-lightweight-0-gHASH " --long --tags --match=" test1-*" --match=" test2-*" HEAD^
203
213
204
- check_describe " test2-lightweight-* " --long --tags --match=" test1-*" --no-match --match=" test2-*" HEAD^
214
+ check_describe " test2-lightweight-0-gHASH " --long --tags --match=" test1-*" --no-match --match=" test2-*" HEAD^
205
215
206
- check_describe " test1-lightweight-* " --long --tags --match=" test1-*" --match=" test3-*" HEAD
216
+ check_describe " test1-lightweight-2-gHASH " --long --tags --match=" test1-*" --match=" test3-*" HEAD
207
217
208
- check_describe " test1-lightweight-* " --long --tags --match=" test3-*" --match=" test1-*" HEAD
218
+ check_describe " test1-lightweight-2-gHASH " --long --tags --match=" test3-*" --match=" test1-*" HEAD
209
219
210
220
test_expect_success ' set-up branches' '
211
221
git branch branch_A A &&
@@ -215,11 +225,11 @@ test_expect_success 'set-up branches' '
215
225
git update-ref refs/original/original_branch_A test-annotated~2
216
226
'
217
227
218
- check_describe " heads/branch_A* " --all --match=" branch_*" --exclude=" branch_C" HEAD
228
+ check_describe " heads/branch_A-11-gHASH " --all --match=" branch_*" --exclude=" branch_C" HEAD
219
229
220
- check_describe " remotes/origin/remote_branch_A* " --all --match=" origin/remote_branch_*" --exclude=" origin/remote_branch_C" HEAD
230
+ check_describe " remotes/origin/remote_branch_A-11-gHASH " --all --match=" origin/remote_branch_*" --exclude=" origin/remote_branch_C" HEAD
221
231
222
- check_describe " original/original_branch_A* " --all test-annotated~1
232
+ check_describe " original/original_branch_A-6-gHASH " --all test-annotated~1
223
233
224
234
test_expect_success ' --match does not work for other types' '
225
235
test_must_fail git describe --all --match="*original_branch_*" test-annotated~1
@@ -474,7 +484,7 @@ test_expect_success 'name-rev covers all conditions while looking at parents' '
474
484
# o-----o---o----x
475
485
# A
476
486
#
477
- test_expect_success ' describe commits with disjoint bases' '
487
+ test_expect_success ' setup: describe commits with disjoint bases' '
478
488
git init disjoint1 &&
479
489
(
480
490
cd disjoint1 &&
@@ -487,19 +497,19 @@ test_expect_success 'describe commits with disjoint bases' '
487
497
git checkout --orphan branch && rm file &&
488
498
echo B > file2 && git add file2 && git commit -m B &&
489
499
git tag B -a -m B &&
490
- git merge --no-ff --allow-unrelated-histories main -m x &&
491
-
492
- check_describe "A-3-*" HEAD
500
+ git merge --no-ff --allow-unrelated-histories main -m x
493
501
)
494
502
'
495
503
504
+ check_describe -C disjoint1 " A-3-gHASH" HEAD
505
+
496
506
# B
497
507
# o---o---o------------.
498
508
# \
499
509
# o---o---x
500
510
# A
501
511
#
502
- test_expect_success ' describe commits with disjoint bases 2' '
512
+ test_expect_success ' setup: describe commits with disjoint bases 2' '
503
513
git init disjoint2 &&
504
514
(
505
515
cd disjoint2 &&
@@ -513,10 +523,10 @@ test_expect_success 'describe commits with disjoint bases 2' '
513
523
echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o &&
514
524
echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
515
525
git tag B -a -m B &&
516
- git merge --no-ff --allow-unrelated-histories main -m x &&
517
-
518
- check_describe "B-3-*" HEAD
526
+ git merge --no-ff --allow-unrelated-histories main -m x
519
527
)
520
528
'
521
529
530
+ check_describe -C disjoint2 " B-3-gHASH" HEAD
531
+
522
532
test_done
0 commit comments