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 <cornelius.weig@tngtech.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Cornelius Weig committed
Jan 27, 2017 at 11:09 UTC
b1421a43d5e28d71dc89b99877c3fbcb845aae08
1 file changed
+36
-7
t/t1400-update-ref.sh
+36
-7
@@ -8,23 +8,33 @@ test_description='Test git update-ref and basic ref logging'
8
9
Z=$_z40
10
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
16
17
+create_test_commits ()
18
+{
19
+ prfx="$1"
20
for name in A B C D E F
21
do
22
test_tick &&
23
T=$(git write-tree) &&
24
sha1=$(echo $name | git commit-tree $T) &&
18
- eval $name=$sha1
25
+ eval $prfx$name=$sha1
26
done
27
+}
28
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 -
36
'
37
23
-m=refs/heads/master
24
-n_dir=refs/heads/gu
25
-n=$n_dir/fixes
26
-outside=refs/foo
27
-
38
test_expect_success \
39
"create $m" \
40
"git update-ref $m $A &&
@@ -93,6 +103,25 @@ test_expect_success 'update-ref creates reflogs with --create-reflog' '
103
git reflog exists $outside
104
'
105
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
+
125
test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' '
126
test_config core.logAllRefUpdates true &&
127
test_when_finished "git update-ref -d $outside" &&