From 341fb28621201c5e6c9d3fee5baf7c532fa8a618 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Fri, 27 Jan 2017 11:09:47 +0100 Subject: refs: add option core.logAllRefUpdates = always When core.logallrefupdates is true, we only create a new reflog for refs that are under certain well-known hierarchies. The reason is that we know that some hierarchies (like refs/tags) are not meant to change, and that unknown hierarchies might not want reflogs at all (e.g., a hypothetical refs/foo might be meant to change often and drop old history immediately). However, sometimes it is useful to override this decision and simply log for all refs, because the safety and audit trail is more important than the performance implications of keeping the log around. This patch introduces a new "always" mode for the core.logallrefupdates option which will log updates to everything under refs/, regardless where in the hierarchy it is (we still will not log things like ORIG_HEAD and FETCH_HEAD, which are known to be transient). Based-on-patch-by: Jeff King Signed-off-by: Cornelius Weig Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index d4fb977060..b9084cacb2 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -93,6 +93,42 @@ test_expect_success 'update-ref creates reflogs with --create-reflog' ' git reflog exists $outside ' +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" && + git update-ref $outside $A && + git rev-parse $A >expect && + git rev-parse $outside >actual && + test_cmp expect actual && + test_must_fail git reflog exists $outside +' + +test_expect_success 'core.logAllRefUpdates=always creates reflog by default' ' + test_config core.logAllRefUpdates always && + test_when_finished "git update-ref -d $outside" && + git update-ref $outside $A && + git rev-parse $A >expect && + git rev-parse $outside >actual && + test_cmp expect actual && + git reflog exists $outside +' + +test_expect_success 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD' ' + test_config core.logAllRefUpdates always && + git update-ref ORIG_HEAD $A && + test_must_fail git reflog exists ORIG_HEAD +' + +test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' ' + test_config core.logAllRefUpdates true && + test_when_finished "git update-ref -d $outside" && + git update-ref --no-create-reflog $outside $A && + git rev-parse $A >expect && + git rev-parse $outside >actual && + test_cmp expect actual && + test_must_fail git reflog exists $outside +' + test_expect_success \ "create $m (by HEAD)" \ "git update-ref HEAD $A && @@ -501,6 +537,7 @@ test_expect_success 'stdin does not create reflogs by default' ' ' test_expect_success 'stdin creates reflogs with --create-reflog' ' + test_when_finished "git update-ref -d $outside" && echo "create $outside $m" >stdin && git update-ref --create-reflog --stdin expect && -- cgit v1.2.3 From b1421a43d5e28d71dc89b99877c3fbcb845aae08 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Fri, 27 Jan 2017 11:09:48 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index b9084cacb2..b0ffc0b573 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -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" && -- cgit v1.2.3