Skip to content

Commit 5555a2a

Browse files
hashplinggitster
authored andcommitted
t4201: make use of abbreviation in the test more robust
The test for '--abbrev' in t4201-shortlog.sh assumes that the commits generated in the test can always be uniquely abbreviated to 5 hex digits but this is not always the case. If you were unlucky and happened to run the test at (say) Thu Jun 22 03:04:49 2017 +0000, you would find that the first commit generated would collide with a tree object created later in the same test. This can be simulated in the version of t4201-shortlog.sh prior to this commit by setting GIT_COMMITTER_DATE and GIT_AUTHOR_DATE to 1498100689 after sourcing test-lib.sh. Change the test to test --abbrev=35 instead of --abbrev=5 to almost completely avoid the possibility of a partial collision and add a call to test_tick in the setup to make the test repeatable (the latter alone is sufficient to make it robust enough). Signed-off-by: Charles Bailey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9752ad0 commit 5555a2a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

t/t4201-shortlog.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_description='git shortlog
99
. ./test-lib.sh
1010

1111
test_expect_success 'setup' '
12+
test_tick &&
1213
echo 1 >a1 &&
1314
git add a1 &&
1415
tree=$(git write-tree) &&
@@ -59,7 +60,7 @@ fuzz() {
5960
file=$1 &&
6061
sed "
6162
s/$_x40/OBJECT_NAME/g
62-
s/$_x05/OBJID/g
63+
s/$_x35/OBJID/g
6364
s/^ \{6\}[CTa].*/ SUBJECT/g
6465
s/^ \{8\}[^ ].*/ CONTINUATION/g
6566
" <"$file" >"$file.fuzzy" &&
@@ -81,7 +82,7 @@ test_expect_success 'pretty format' '
8182

8283
test_expect_success '--abbrev' '
8384
sed s/SUBJECT/OBJID/ expect.template >expect &&
84-
git shortlog --format="%h" --abbrev=5 HEAD >log &&
85+
git shortlog --format="%h" --abbrev=35 HEAD >log &&
8586
fuzz log >log.predictable &&
8687
test_cmp expect log.predictable
8788
'

t/test-lib.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ esac
166166

167167
# Convenience
168168
#
169-
# A regexp to match 5 and 40 hexdigits
169+
# A regexp to match 5, 35 and 40 hexdigits
170170
_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
171-
_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
171+
_x35="$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
172+
_x40="$_x35$_x05"
172173

173174
# Zero SHA-1
174175
_z40=0000000000000000000000000000000000000000
@@ -184,7 +185,7 @@ LF='
184185
# when case-folding filenames
185186
u200c=$(printf '\342\200\214')
186187

187-
export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
188+
export _x05 _x35 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
188189

189190
# Each test should start with something like this, after copyright notices:
190191
#

0 commit comments

Comments
 (0)