tests: remove some direct access to .git/logs
authorDavid Turner <dturner@twopensource.com>
Mon, 27 Jul 2015 22:57:08 +0000 (18:57 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jul 2015 18:46:46 +0000 (11:46 -0700)
Alternate refs backends might store reflogs somewhere other than
.git/logs. Change most test code that directly accesses .git/logs to
instead use git reflog commands.

There are still a few tests which need direct access to reflogs: to
check reflog permissions, to manually create reflogs from scratch, to
save/restore reflogs, to check the format of raw reflog data, and to
remove not just reflog contents, but the reflogs themselves. All cases
which don't need direct access have been modified.

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1400-update-ref.sh
t/t1410-reflog.sh
t/t1411-reflog-show.sh
t/t1503-rev-parse-verify.sh
t/t3200-branch.sh
t/t3210-pack-refs.sh
t/t3404-rebase-interactive.sh
t/t3903-stash.sh
t/t5312-prune-corruption.sh
t/t6501-freshen-objects.sh
index ba89f4c00959112b2cfc0efaff94f3447df32357..23721322e83a7d4e56e17c9615c7269e8a847472 100755 (executable)
@@ -155,12 +155,11 @@ test_expect_success "(not) changed .git/$m" "
 '
 rm -f .git/$m
 
-: a repository with working tree always has reflog these days...
-: >.git/logs/refs/heads/master
+rm -f .git/logs/refs/heads/master
 test_expect_success \
        "create $m (logged by touch)" \
        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
-        git update-ref HEAD '"$A"' -m "Initial Creation" &&
+        git update-ref --create-reflog HEAD '"$A"' -m "Initial Creation" &&
         test '"$A"' = $(cat .git/'"$m"')'
 test_expect_success \
        "update $m (logged by touch)" \
index 779d4e3829b29d7092d54f6e342f923f0d239b96..b79049f6f606f106e40dfdc241d7a168b10b88cb 100755 (executable)
@@ -100,7 +100,8 @@ test_expect_success setup '
 
        check_fsck &&
 
-       test_line_count = 4 .git/logs/refs/heads/master
+       git reflog refs/heads/master >output &&
+       test_line_count = 4 output
 '
 
 test_expect_success rewind '
@@ -116,7 +117,8 @@ test_expect_success rewind '
 
        check_have A B C D E F G H I J K L &&
 
-       test_line_count = 5 .git/logs/refs/heads/master
+       git reflog refs/heads/master >output &&
+       test_line_count = 5 output
 '
 
 test_expect_success 'corrupt and check' '
@@ -134,7 +136,8 @@ test_expect_success 'reflog expire --dry-run should not touch reflog' '
                --stale-fix \
                --all &&
 
-       test_line_count = 5 .git/logs/refs/heads/master &&
+       git reflog refs/heads/master >output &&
+       test_line_count = 5 output &&
 
        check_fsck "missing blob $F"
 '
@@ -147,7 +150,8 @@ test_expect_success 'reflog expire' '
                --stale-fix \
                --all &&
 
-       test_line_count = 2 .git/logs/refs/heads/master &&
+       git reflog refs/heads/master >output &&
+       test_line_count = 2 output &&
 
        check_fsck "dangling commit $K"
 '
@@ -213,7 +217,8 @@ test_expect_success 'delete' '
 test_expect_success 'rewind2' '
 
        test_tick && git reset --hard HEAD~2 &&
-       test_line_count = 4 .git/logs/refs/heads/master
+       git reflog refs/heads/master >output &&
+       test_line_count = 4 output
 '
 
 test_expect_success '--expire=never' '
@@ -222,7 +227,8 @@ test_expect_success '--expire=never' '
                --expire=never \
                --expire-unreachable=never \
                --all &&
-       test_line_count = 4 .git/logs/refs/heads/master
+       git reflog refs/heads/master >output &&
+       test_line_count = 4 output
 '
 
 test_expect_success 'gc.reflogexpire=never' '
@@ -230,7 +236,8 @@ test_expect_success 'gc.reflogexpire=never' '
        git config gc.reflogexpire never &&
        git config gc.reflogexpireunreachable never &&
        git reflog expire --verbose --all &&
-       test_line_count = 4 .git/logs/refs/heads/master
+       git reflog refs/heads/master >output &&
+       test_line_count = 4 output
 '
 
 test_expect_success 'gc.reflogexpire=false' '
@@ -238,7 +245,8 @@ test_expect_success 'gc.reflogexpire=false' '
        git config gc.reflogexpire false &&
        git config gc.reflogexpireunreachable false &&
        git reflog expire --verbose --all &&
-       test_line_count = 4 .git/logs/refs/heads/master &&
+       git reflog refs/heads/master >output &&
+       test_line_count = 4 output &&
 
        git config --unset gc.reflogexpire &&
        git config --unset gc.reflogexpireunreachable
index 6f47c0dd0ec9b5e59205ca98eea9bd729605e004..d568b35b43372fb8f95bf4c91397b3769a2ca413 100755 (executable)
@@ -138,7 +138,7 @@ test_expect_success '--date magic does not override explicit @{0} syntax' '
 : >expect
 test_expect_success 'empty reflog file' '
        git branch empty &&
-       : >.git/logs/refs/heads/empty &&
+       git reflog expire --expire=all refs/heads/empty &&
 
        git log -g empty >actual &&
        test_cmp expect actual
index 823fe1d79924b68950a59ffde902b16db29205b6..ab27d0db5c5577a23e1053b58eefa63015526d0c 100755 (executable)
@@ -85,8 +85,7 @@ test_expect_success 'fails silently when using -q' '
 
 test_expect_success 'fails silently when using -q with deleted reflogs' '
        ref=$(git rev-parse HEAD) &&
-       : >.git/logs/refs/test &&
-       git update-ref -m "message for refs/test" refs/test "$ref" &&
+       git update-ref --create-reflog -m "message for refs/test" refs/test "$ref" &&
        git reflog delete --updateref --rewrite refs/test@{0} &&
        test_must_fail git rev-parse -q --verify refs/test@{0} >error 2>&1 &&
        test_must_be_empty error
@@ -94,16 +93,14 @@ test_expect_success 'fails silently when using -q with deleted reflogs' '
 
 test_expect_success 'fails silently when using -q with not enough reflogs' '
        ref=$(git rev-parse HEAD) &&
-       : >.git/logs/refs/test2 &&
-       git update-ref -m "message for refs/test2" refs/test2 "$ref" &&
+       git update-ref --create-reflog -m "message for refs/test2" refs/test2 "$ref" &&
        test_must_fail git rev-parse -q --verify refs/test2@{999} >error 2>&1 &&
        test_must_be_empty error
 '
 
 test_expect_success 'succeeds silently with -q and reflogs that do not go far back enough in time' '
        ref=$(git rev-parse HEAD) &&
-       : >.git/logs/refs/test3 &&
-       git update-ref -m "message for refs/test3" refs/test3 "$ref" &&
+       git update-ref --create-reflog -m "message for refs/test3" refs/test3 "$ref" &&
        git rev-parse -q --verify refs/test3@{1.year.ago} >actual 2>error &&
        test_must_be_empty error &&
        echo "$ref" >expect &&
index ddea49808d063f6c169cf8078f5698e34c2ba803..cdaf6f64ec78830def2f082b72604075e15496f6 100755 (executable)
@@ -59,7 +59,7 @@ test_expect_success 'git branch -l d/e/f should create a branch and a log' '
 test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
        git branch -d d/e/f &&
        test_path_is_missing .git/refs/heads/d/e/f &&
-       test_path_is_missing .git/logs/refs/heads/d/e/f
+       test_must_fail git reflog exists refs/heads/d/e/f
 '
 
 test_expect_success 'git branch j/k should work after branch j has been deleted' '
@@ -82,13 +82,13 @@ test_expect_success 'git branch -m dumps usage' '
 test_expect_success 'git branch -m m m/m should work' '
        git branch -l m &&
        git branch -m m m/m &&
-       test_path_is_file .git/logs/refs/heads/m/m
+       git reflog exists refs/heads/m/m
 '
 
 test_expect_success 'git branch -m n/n n should work' '
        git branch -l n/n &&
        git branch -m n/n n &&
-       test_path_is_file .git/logs/refs/heads/n
+       git reflog exists refs/heads/n
 '
 
 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
@@ -267,12 +267,12 @@ git config branch.s/s.dummy Hello
 
 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
        git branch -l s/s &&
-       test_path_is_file .git/logs/refs/heads/s/s &&
+       git reflog exists refs/heads/s/s &&
        git branch -l s/t &&
-       test_path_is_file .git/logs/refs/heads/s/t &&
+       git reflog exists refs/heads/s/t &&
        git branch -d s/t &&
        git branch -m s/s s &&
-       test_path_is_file .git/logs/refs/heads/s
+       git reflog exists refs/heads/s
 '
 
 test_expect_success 'config information was renamed, too' '
index aa9eb3a3e5ef0637615c6d958a29dbd9bbbf0895..9d5394932395d8f57c6a3d06c28538b84f7d24cc 100755 (executable)
@@ -169,7 +169,7 @@ test_expect_success 'create packed foo/bar/baz branch' '
        git branch foo/bar/baz &&
        git pack-refs --all --prune &&
        test_path_is_missing .git/refs/heads/foo/bar/baz &&
-       test_path_is_missing .git/logs/refs/heads/foo/bar/baz
+       test_must_fail git reflog exists refs/heads/foo/bar/baz
 '
 
 test_expect_success 'notice d/f conflict with existing directory' '
index ac429a0bbbbeb95f96336aa203a5d9726ed6eb1d..567d6ca9b87431747b602ca4a1459df9f881137c 100755 (executable)
@@ -961,13 +961,13 @@ test_expect_success 'rebase -i produces readable reflog' '
        set_fake_editor &&
        git rebase -i --onto I F branch-reflog-test &&
        cat >expect <<-\EOF &&
-       rebase -i (start): checkout I
-       rebase -i (pick): G
-       rebase -i (pick): H
        rebase -i (finish): returning to refs/heads/branch-reflog-test
+       rebase -i (pick): H
+       rebase -i (pick): G
+       rebase -i (start): checkout I
        EOF
-       tail -n 4 .git/logs/HEAD |
-       sed -e "s/.*    //" >actual &&
+       git reflog -n4 HEAD |
+       sed "s/[^:]*: //" >actual &&
        test_cmp expect actual
 '
 
index f5f18b7d21c00da258125a9125a46b32cf9e8504..2142c1fa92017bc47cfc4ccb1f25e16fc0eec1a4 100755 (executable)
@@ -672,7 +672,7 @@ test_expect_success 'store updates stash ref and reflog' '
        ! grep quux bazzy &&
        git stash store -m quuxery $STASH_ID &&
        test $(cat .git/refs/stash) = $STASH_ID &&
-       grep $STASH_ID .git/logs/refs/stash &&
+       git reflog --format=%H stash| grep $STASH_ID &&
        git stash pop &&
        grep quux bazzy
 '
index 8e98b44083f76b959f32883059f07d65a5b8aadb..da9d59940d5aa72a059a36f4187775b093eb5a58 100755 (executable)
@@ -12,7 +12,7 @@ delete objects that cannot be recovered.
 
 test_expect_success 'disable reflogs' '
        git config core.logallrefupdates false &&
-       rm -rf .git/logs
+       git reflog expire --expire=all --all
 '
 
 test_expect_success 'create history reachable only from a bogus-named ref' '
index 2adf825076b9c8f774973dcc83686980dca7725b..cf076dcd940aa0d74bd8df03b4f6c768e1954455 100755 (executable)
@@ -56,7 +56,7 @@ for repack in '' true; do
 
        test_expect_success "disable reflogs ($title)" '
                git config core.logallrefupdates false &&
-               rm -rf .git/logs
+               git reflog expire --expire=all --all
        '
 
        test_expect_success "setup basic history ($title)" '