Merge branch 'dt/reflog-tests'
authorJunio C Hamano <gitster@pobox.com>
Wed, 12 Aug 2015 21:09:56 +0000 (14:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Aug 2015 21:09:56 +0000 (14:09 -0700)
Tests that assume how reflogs are represented on the filesystem too
much have been corrected.

* dt/reflog-tests:
tests: remove some direct access to .git/logs
t/t7509: remove unnecessary manipulation of reflog

1  2 
t/t1400-update-ref.sh
t/t1411-reflog-show.sh
t/t3210-pack-refs.sh
t/t3404-rebase-interactive.sh
diff --combined t/t1400-update-ref.sh
index 9d21c1927e06312ae49b4c81e1ba53485a49b9de,23721322e83a7d4e56e17c9615c7269e8a847472..97406fa4b137afdd99e64172d956718005844120
@@@ -23,7 -23,6 +23,7 @@@ test_expect_success setup 
  m=refs/heads/master
  n_dir=refs/heads/gu
  n=$n_dir/fixes
 +outside=foo
  
  test_expect_success \
        "create $m" \
@@@ -75,24 -74,6 +75,24 @@@ test_expect_success "delete $m (by HEAD
  '
  rm -f .git/$m
  
 +test_expect_success 'update-ref does not create reflogs by default' '
 +      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 'update-ref creates reflogs with --create-reflog' '
 +      test_when_finished "git update-ref -d $outside" &&
 +      git update-ref --create-reflog $outside $A &&
 +      git rev-parse $A >expect &&
 +      git rev-parse $outside >actual &&
 +      test_cmp expect actual &&
 +      git reflog exists $outside
 +'
 +
  test_expect_success \
        "create $m (by HEAD)" \
        "git update-ref HEAD $A &&
@@@ -174,12 -155,11 +174,11 @@@ test_expect_success "(not) changed .git
  '
  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)" \
@@@ -491,25 -471,6 +490,25 @@@ test_expect_success 'stdin create ref w
        test_cmp expect actual
  '
  
 +test_expect_success 'stdin does not create reflogs by default' '
 +      test_when_finished "git update-ref -d $outside" &&
 +      echo "create $outside $m" >stdin &&
 +      git update-ref --stdin <stdin &&
 +      git rev-parse $m >expect &&
 +      git rev-parse $outside >actual &&
 +      test_cmp expect actual &&
 +      test_must_fail git reflog exists $outside
 +'
 +
 +test_expect_success 'stdin creates reflogs with --create-reflog' '
 +      echo "create $outside $m" >stdin &&
 +      git update-ref --create-reflog --stdin <stdin &&
 +      git rev-parse $m >expect &&
 +      git rev-parse $outside >actual &&
 +      test_cmp expect actual &&
 +      git reflog exists $outside
 +'
 +
  test_expect_success 'stdin succeeds with quoted argument' '
        git update-ref -d $a &&
        echo "create $a \"$m\"" >stdin &&
@@@ -557,7 -518,7 +556,7 @@@ test_expect_success 'stdin create ref w
  test_expect_success 'stdin update ref fails with wrong old value' '
        echo "update $c $m $m~1" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
 -      grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
 +      grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
        test_must_fail git rev-parse --verify -q $c
  '
  
@@@ -593,7 -554,7 +592,7 @@@ test_expect_success 'stdin update ref w
  test_expect_success 'stdin delete ref fails with wrong old value' '
        echo "delete $a $m~1" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
 -      grep "fatal: Cannot lock ref '"'"'$a'"'"'" err &&
 +      grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual
@@@ -726,7 -687,7 +725,7 @@@ test_expect_success 'stdin update refs 
        update $c  ''
        EOF
        test_must_fail git update-ref --stdin <stdin 2>err &&
 -      grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
 +      grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual &&
@@@ -921,7 -882,7 +920,7 @@@ test_expect_success 'stdin -z create re
  test_expect_success 'stdin -z update ref fails with wrong old value' '
        printf $F "update $c" "$m" "$m~1" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
 -      grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
 +      grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
        test_must_fail git rev-parse --verify -q $c
  '
  
@@@ -937,7 -898,7 +936,7 @@@ test_expect_success 'stdin -z create re
        git rev-parse "$c" >expect &&
        printf $F "create $c" "$m~1" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
 -      grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
 +      grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
        git rev-parse "$c" >actual &&
        test_cmp expect actual
  '
@@@ -968,7 -929,7 +967,7 @@@ test_expect_success 'stdin -z update re
  test_expect_success 'stdin -z delete ref fails with wrong old value' '
        printf $F "delete $a" "$m~1" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
 -      grep "fatal: Cannot lock ref '"'"'$a'"'"'" err &&
 +      grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual
@@@ -1083,7 -1044,7 +1082,7 @@@ test_expect_success 'stdin -z update re
        git update-ref $c $m &&
        printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
 -      grep "fatal: Cannot lock ref '"'"'$c'"'"'" err &&
 +      grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
        git rev-parse $m >expect &&
        git rev-parse $a >actual &&
        test_cmp expect actual &&
diff --combined t/t1411-reflog-show.sh
index 3eb4f102e505445041a3772404523a99245a8346,d568b35b43372fb8f95bf4c91397b3769a2ca413..6ac7734d79be21a82feeadff10064bb4ca7ad47b
@@@ -138,7 -138,7 +138,7 @@@ test_expect_success '--date magic does 
  : >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
@@@ -166,9 -166,4 +166,9 @@@ test_expect_success 'git log -g -p show
        test_cmp expect actual
  '
  
 +test_expect_success 'reflog exists works' '
 +      git reflog exists refs/heads/master &&
 +      ! git reflog exists refs/heads/nonexistent
 +'
 +
  test_done
diff --combined t/t3210-pack-refs.sh
index 8aae98d482aa572b3a9a55f9b38280ad716c7baf,9d5394932395d8f57c6a3d06c28538b84f7d24cc..7b5b6d452e3762c9d0e311602bf39317200c21a7
@@@ -169,7 -169,7 +169,7 @@@ test_expect_success 'create packed foo/
        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' '
@@@ -187,21 -187,4 +187,21 @@@ test_expect_success 'notice d/f conflic
        test_must_fail git branch foo/bar/baz/lots/of/extra/components
  '
  
 +test_expect_success 'timeout if packed-refs.lock exists' '
 +      LOCK=.git/packed-refs.lock &&
 +      >"$LOCK" &&
 +      test_when_finished "rm -f $LOCK" &&
 +      test_must_fail git pack-refs --all --prune
 +'
 +
 +test_expect_success 'retry acquiring packed-refs.lock' '
 +      LOCK=.git/packed-refs.lock &&
 +      >"$LOCK" &&
 +      test_when_finished "wait; rm -f $LOCK" &&
 +      {
 +              ( sleep 1 ; rm -f $LOCK ) &
 +      } &&
 +      git -c core.packedrefstimeout=3000 pack-refs --all --prune
 +'
 +
  test_done
index 9d26064abaeb9134f70f3f011ac14f965a250f77,567d6ca9b87431747b602ca4a1459df9f881137c..d26e3f57dcbc18585c360ee78a725708f5a69207
@@@ -961,13 -961,13 +961,13 @@@ test_expect_success 'rebase -i produce
        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
  '
  
@@@ -1102,148 -1102,4 +1102,148 @@@ test_expect_success 'rebase -i commits 
        test $(git cat-file commit HEAD | sed -ne \$p) = I
  '
  
 +test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
 +      git checkout -b commit-to-skip &&
 +      for double in X 3 1
 +      do
 +              test_seq 5 | sed "s/$double/&&/" >seq &&
 +              git add seq &&
 +              test_tick &&
 +              git commit -m seq-$double
 +      done &&
 +      git tag seq-onto &&
 +      git reset --hard HEAD~2 &&
 +      git cherry-pick seq-onto &&
 +      set_fake_editor &&
 +      test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
 +      test -d .git/rebase-merge &&
 +      git rebase --continue &&
 +      git diff --exit-code seq-onto &&
 +      test ! -d .git/rebase-merge &&
 +      test ! -f .git/CHERRY_PICK_HEAD
 +'
 +
 +rebase_setup_and_clean () {
 +      test_when_finished "
 +              git checkout master &&
 +              test_might_fail git branch -D $1 &&
 +              test_might_fail git rebase --abort
 +      " &&
 +      git checkout -b $1 master
 +}
 +
 +test_expect_success 'drop' '
 +      rebase_setup_and_clean drop-test &&
 +      set_fake_editor &&
 +      FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
 +      test E = $(git cat-file commit HEAD | sed -ne \$p) &&
 +      test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
 +      test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
 +'
 +
 +cat >expect <<EOF
 +Successfully rebased and updated refs/heads/missing-commit.
 +EOF
 +
 +test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
 +      test_config rebase.missingCommitsCheck ignore &&
 +      rebase_setup_and_clean missing-commit &&
 +      set_fake_editor &&
 +      FAKE_LINES="1 2 3 4" \
 +              git rebase -i --root 2>actual &&
 +      test D = $(git cat-file commit HEAD | sed -ne \$p) &&
 +      test_cmp expect actual
 +'
 +
 +cat >expect <<EOF
 +Warning: some commits may have been dropped accidentally.
 +Dropped commits (newer to older):
 + - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
 +To avoid this message, use "drop" to explicitly remove a commit.
 +
 +Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
 +The possible behaviours are: ignore, warn, error.
 +
 +Successfully rebased and updated refs/heads/missing-commit.
 +EOF
 +
 +test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
 +      test_config rebase.missingCommitsCheck warn &&
 +      rebase_setup_and_clean missing-commit &&
 +      set_fake_editor &&
 +      FAKE_LINES="1 2 3 4" \
 +              git rebase -i --root 2>actual &&
 +      test_cmp expect actual &&
 +      test D = $(git cat-file commit HEAD | sed -ne \$p)
 +'
 +
 +cat >expect <<EOF
 +Warning: some commits may have been dropped accidentally.
 +Dropped commits (newer to older):
 + - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
 + - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
 +To avoid this message, use "drop" to explicitly remove a commit.
 +
 +Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
 +The possible behaviours are: ignore, warn, error.
 +
 +You can fix this with 'git rebase --edit-todo'.
 +Or you can abort the rebase with 'git rebase --abort'.
 +EOF
 +
 +test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
 +      test_config rebase.missingCommitsCheck error &&
 +      rebase_setup_and_clean missing-commit &&
 +      set_fake_editor &&
 +      test_must_fail env FAKE_LINES="1 2 4" \
 +              git rebase -i --root 2>actual &&
 +      test_cmp expect actual &&
 +      cp .git/rebase-merge/git-rebase-todo.backup \
 +              .git/rebase-merge/git-rebase-todo &&
 +      FAKE_LINES="1 2 drop 3 4 drop 5" \
 +              git rebase --edit-todo &&
 +      git rebase --continue &&
 +      test D = $(git cat-file commit HEAD | sed -ne \$p) &&
 +      test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 +'
 +
 +cat >expect <<EOF
 +Warning: the command isn't recognized in the following line:
 + - badcmd $(git rev-list --oneline -1 master~1)
 +
 +You can fix this with 'git rebase --edit-todo'.
 +Or you can abort the rebase with 'git rebase --abort'.
 +EOF
 +
 +test_expect_success 'static check of bad command' '
 +      rebase_setup_and_clean bad-cmd &&
 +      set_fake_editor &&
 +      test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
 +              git rebase -i --root 2>actual &&
 +      test_cmp expect actual &&
 +      FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
 +      git rebase --continue &&
 +      test E = $(git cat-file commit HEAD | sed -ne \$p) &&
 +      test C = $(git cat-file commit HEAD^ | sed -ne \$p)
 +'
 +
 +cat >expect <<EOF
 +Warning: the SHA-1 is missing or isn't a commit in the following line:
 + - edit XXXXXXX False commit
 +
 +You can fix this with 'git rebase --edit-todo'.
 +Or you can abort the rebase with 'git rebase --abort'.
 +EOF
 +
 +test_expect_success 'static check of bad SHA-1' '
 +      rebase_setup_and_clean bad-sha &&
 +      set_fake_editor &&
 +      test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
 +              git rebase -i --root 2>actual &&
 +      test_cmp expect actual &&
 +      FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
 +      git rebase --continue &&
 +      test E = $(git cat-file commit HEAD | sed -ne \$p)
 +'
 +
  test_done