Skip to content

Commit b1421a4

Browse files
Cornelius Weiggitster
authored andcommitted
update-ref: add test cases for bare repository
The default behavior of update-ref to create reflogs differs in repositories with worktree and bare ones. The existing tests cover only the behavior of repositories with worktree. This commit adds tests that assert the correct behavior in bare repositories for update-ref. Two cases are covered: - If core.logAllRefUpdates is not set, no reflogs should be created - If core.logAllRefUpdates is true, reflogs should be created Signed-off-by: Cornelius Weig <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 341fb28 commit b1421a4

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

t/t1400-update-ref.sh

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,33 @@ test_description='Test git update-ref and basic ref logging'
88

99
Z=$_z40
1010

11-
test_expect_success setup '
11+
m=refs/heads/master
12+
n_dir=refs/heads/gu
13+
n=$n_dir/fixes
14+
outside=refs/foo
15+
bare=bare-repo
1216

17+
create_test_commits ()
18+
{
19+
prfx="$1"
1320
for name in A B C D E F
1421
do
1522
test_tick &&
1623
T=$(git write-tree) &&
1724
sha1=$(echo $name | git commit-tree $T) &&
18-
eval $name=$sha1
25+
eval $prfx$name=$sha1
1926
done
27+
}
2028

29+
test_expect_success setup '
30+
create_test_commits "" &&
31+
mkdir $bare &&
32+
cd $bare &&
33+
git init --bare &&
34+
create_test_commits "bare" &&
35+
cd -
2136
'
2237

23-
m=refs/heads/master
24-
n_dir=refs/heads/gu
25-
n=$n_dir/fixes
26-
outside=refs/foo
27-
2838
test_expect_success \
2939
"create $m" \
3040
"git update-ref $m $A &&
@@ -93,6 +103,25 @@ test_expect_success 'update-ref creates reflogs with --create-reflog' '
93103
git reflog exists $outside
94104
'
95105

106+
test_expect_success 'creates no reflog in bare repository' '
107+
git -C $bare update-ref $m $bareA &&
108+
git -C $bare rev-parse $bareA >expect &&
109+
git -C $bare rev-parse $m >actual &&
110+
test_cmp expect actual &&
111+
test_must_fail git -C $bare reflog exists $m
112+
'
113+
114+
test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
115+
test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
116+
rm $bare/logs/$m" &&
117+
git -C $bare config core.logAllRefUpdates true &&
118+
git -C $bare update-ref $m $bareB &&
119+
git -C $bare rev-parse $bareB >expect &&
120+
git -C $bare rev-parse $m >actual &&
121+
test_cmp expect actual &&
122+
git -C $bare reflog exists $m
123+
'
124+
96125
test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' '
97126
test_config core.logAllRefUpdates true &&
98127
test_when_finished "git update-ref -d $outside" &&

0 commit comments

Comments
 (0)