]> git.ipfire.org Git - thirdparty/git.git/commitdiff
update-ref: add test cases for bare repository
authorCornelius Weig <cornelius.weig@tngtech.com>
Fri, 27 Jan 2017 10:09:48 +0000 (11:09 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 18:01:24 +0000 (10:01 -0800)
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>
t/t1400-update-ref.sh

index b9084cacb256d3717a06256eff73daf4ea9aad38..b0ffc0b5731dd746ed170604784287d3e48e9c30 100755 (executable)
@@ -8,23 +8,33 @@ test_description='Test git update-ref and basic ref logging'
 
 Z=$_z40
 
-test_expect_success setup '
+m=refs/heads/master
+n_dir=refs/heads/gu
+n=$n_dir/fixes
+outside=refs/foo
+bare=bare-repo
 
+create_test_commits ()
+{
+       prfx="$1"
        for name in A B C D E F
        do
                test_tick &&
                T=$(git write-tree) &&
                sha1=$(echo $name | git commit-tree $T) &&
-               eval $name=$sha1
+               eval $prfx$name=$sha1
        done
+}
 
+test_expect_success setup '
+       create_test_commits "" &&
+       mkdir $bare &&
+       cd $bare &&
+       git init --bare &&
+       create_test_commits "bare" &&
+       cd -
 '
 
-m=refs/heads/master
-n_dir=refs/heads/gu
-n=$n_dir/fixes
-outside=refs/foo
-
 test_expect_success \
        "create $m" \
        "git update-ref $m $A &&
@@ -93,6 +103,25 @@ test_expect_success 'update-ref creates reflogs with --create-reflog' '
        git reflog exists $outside
 '
 
+test_expect_success 'creates no reflog in bare repository' '
+       git -C $bare update-ref $m $bareA &&
+       git -C $bare rev-parse $bareA >expect &&
+       git -C $bare rev-parse $m >actual &&
+       test_cmp expect actual &&
+       test_must_fail git -C $bare reflog exists $m
+'
+
+test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
+       test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
+               rm $bare/logs/$m" &&
+       git -C $bare config core.logAllRefUpdates true &&
+       git -C $bare update-ref $m $bareB &&
+       git -C $bare rev-parse $bareB >expect &&
+       git -C $bare rev-parse $m >actual &&
+       test_cmp expect actual &&
+       git -C $bare reflog exists $m
+'
+
 test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' '
        test_config core.logAllRefUpdates true &&
        test_when_finished "git update-ref -d $outside" &&