Merge branch 'cw/log-updates-for-all-refs-really'

The "core.logAllRefUpdates" that used to be boolean has been
enhanced to take 'always' as well, to record ref updates to refs
other than the ones that are expected to be updated (i.e. branches,
remote-tracking branches and notes).

* cw/log-updates-for-all-refs-really:
  doc: add note about ignoring '--no-create-reflog'
  update-ref: add test cases for bare repository
  refs: add option core.logAllRefUpdates = always
  config: add markup to core.logAllRefUpdates doc
This commit is contained in:
Junio C Hamano
2017-02-03 11:25:19 -08:00
15 changed files with 133 additions and 30 deletions

View File

@ -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,61 @@ 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" &&
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 +566,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 <stdin &&
git rev-parse $m >expect &&

View File

@ -71,6 +71,7 @@ test_expect_success 'creating a tag for an unknown revision should fail' '
# commit used in the tests, test_tick is also called here to freeze the date:
test_expect_success 'creating a tag using default HEAD should succeed' '
test_config core.logAllRefUpdates true &&
test_tick &&
echo foo >foo &&
git add foo &&
@ -90,6 +91,13 @@ test_expect_success '--create-reflog does not create reflog on failure' '
test_must_fail git reflog exists refs/tags/mytag
'
test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
test_when_finished "git tag -d tag_with_reflog" &&
test_config core.logAllRefUpdates always &&
git tag tag_with_reflog &&
git reflog exists refs/tags/tag_with_reflog
'
test_expect_success 'listing all tags if one exists should succeed' '
git tag -l &&
git tag