Merge branch 'jn/push-tests'
authorJunio C Hamano <gitster@pobox.com>
Mon, 1 Apr 2013 16:06:15 +0000 (09:06 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Apr 2013 16:06:15 +0000 (09:06 -0700)
Update t5516 with style fixes.

* jn/push-tests:
push test: rely on &&-chaining instead of 'if bad; then echo Oops; fi'
push test: simplify check of push result
push test: use test_config when appropriate

1  2 
t/t5516-fetch-push.sh
diff --combined t/t5516-fetch-push.sh
index d3dc5df7b145a23a8d0ab55f69d7ca7351d78274,0695d570f217e3ef94490470f61bc45d539cccee..383a2eb1eaa46053fc3a91fb44921aea2f04637a
@@@ -22,19 -22,16 +22,16 @@@ mk_test () 
        (
                for ref in "$@"
                do
-                       git push testrepo $the_first_commit:refs/$ref || {
-                               echo "Oops, push refs/$ref failure"
-                               exit 1
-                       }
+                       git push testrepo $the_first_commit:refs/$ref ||
+                       exit
                done &&
                cd testrepo &&
                for ref in "$@"
                do
-                       r=$(git show-ref -s --verify refs/$ref) &&
-                       test "z$r" = "z$the_first_commit" || {
-                               echo "Oops, refs/$ref is wrong"
-                               exit 1
-                       }
+                       echo "$the_first_commit" >expect &&
+                       git show-ref -s --verify refs/$ref >actual &&
+                       test_cmp expect actual ||
+                       exit
                done &&
                git fsck --full
        )
@@@ -82,15 -79,13 +79,13 @@@ mk_child() 
  check_push_result () {
        (
                cd testrepo &&
-               it="$1" &&
-               shift
+               echo "$1" >expect &&
+               shift &&
                for ref in "$@"
                do
-                       r=$(git show-ref -s --verify refs/$ref) &&
-                       test "z$r" = "z$it" || {
-                               echo "Oops, refs/$ref is wrong"
-                               exit 1
-                       }
+                       git show-ref -s --verify refs/$ref >actual &&
+                       test_cmp expect actual ||
+                       exit
                done &&
                git fsck --full
        )
@@@ -118,10 -113,9 +113,9 @@@ test_expect_success 'fetch without wild
                cd testrepo &&
                git fetch .. refs/heads/master:refs/remotes/origin/master &&
  
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
@@@ -133,10 -127,9 +127,9 @@@ test_expect_success 'fetch with wildcar
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
  
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
@@@ -150,10 -143,9 +143,9 @@@ test_expect_success 'fetch with instead
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
  
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
@@@ -167,10 -159,9 +159,9 @@@ test_expect_success 'fetch with pushIns
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
  
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
@@@ -180,10 -171,9 +171,9 @@@ test_expect_success 'push without wildc
        git push testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
@@@ -193,54 -183,50 +183,50 @@@ test_expect_success 'push with wildcard
        git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
  test_expect_success 'push with insteadOf' '
        mk_empty &&
        TRASH="$(pwd)/" &&
-       git config "url.$TRASH.insteadOf" trash/ &&
+       test_config "url.$TRASH.insteadOf" trash/ &&
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
  test_expect_success 'push with pushInsteadOf' '
        mk_empty &&
        TRASH="$(pwd)/" &&
-       git config "url.$TRASH.pushInsteadOf" trash/ &&
+       test_config "url.$TRASH.pushInsteadOf" trash/ &&
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
  test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
        mk_empty &&
        TRASH="$(pwd)/" &&
-       git config "url.trash2/.pushInsteadOf" trash/ &&
-       git config remote.r.url trash/wrong &&
-       git config remote.r.pushurl "$TRASH/testrepo" &&
+       test_config "url.trash2/.pushInsteadOf" trash/ &&
+       test_config remote.r.url trash/wrong &&
+       test_config remote.r.pushurl "$TRASH/testrepo" &&
        git push r refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
  '
  
@@@ -340,13 -326,8 +326,8 @@@ test_expect_success 'push with weak amb
  test_expect_success 'push with ambiguity' '
  
        mk_test heads/frotz tags/frotz &&
-       if git push testrepo master:frotz
-       then
-               echo "Oops, should have failed"
-               false
-       else
-               check_push_result $the_first_commit heads/frotz tags/frotz
-       fi
+       test_must_fail git push testrepo master:frotz &&
+       check_push_result $the_first_commit heads/frotz tags/frotz
  
  '
  
@@@ -489,31 -470,24 +470,24 @@@ test_expect_success 'push with config r
                git checkout local &&
                git reset --hard $the_first_commit
        ) &&
-       git config remote.there.url testrepo &&
-       git config remote.there.push HEAD &&
-       git config branch.master.remote there &&
+       test_config remote.there.url testrepo &&
+       test_config remote.there.push HEAD &&
+       test_config branch.master.remote there &&
        git push &&
        check_push_result $the_commit heads/master &&
        check_push_result $the_first_commit heads/local
  '
  
- # clean up the cruft left with the previous one
- git config --remove-section remote.there
- git config --remove-section branch.master
  test_expect_success 'push with config remote.*.pushurl' '
  
        mk_test heads/master &&
        git checkout master &&
-       git config remote.there.url test2repo &&
-       git config remote.there.pushurl testrepo &&
+       test_config remote.there.url test2repo &&
+       test_config remote.there.pushurl testrepo &&
        git push there &&
        check_push_result $the_commit heads/master
  '
  
- # clean up the cruft left with the previous one
- git config --remove-section remote.there
  test_expect_success 'push with dry-run' '
  
        mk_test heads/master &&
@@@ -834,9 -808,9 +808,9 @@@ test_expect_success 'fetch with branche
        (
                cd testrepo &&
                git fetch branch1 &&
-               r=$(git show-ref -s --verify refs/heads/branch1) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_commit commit        refs/heads/branch1" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
  '
@@@ -847,9 -821,9 +821,9 @@@ test_expect_success 'fetch with branche
        (
                cd testrepo &&
                git fetch branch2 &&
-               r=$(git show-ref -s --verify refs/heads/branch2) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/branch2" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
  '
@@@ -861,9 -835,9 +835,9 @@@ test_expect_success 'push with branches
        git push branch1 &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/heads/master) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/master" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        )
  '
  
@@@ -873,9 -847,9 +847,9 @@@ test_expect_success 'push with branche
        git push branch2 &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/heads/branch3) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/branch3" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
  '
@@@ -958,9 -932,9 +932,9 @@@ test_expect_success 'push --porcelain' 
        git push >.git/bar --porcelain  testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        ) &&
        test_cmp .git/foo .git/bar
  '
        '
  done
  
 +test_expect_success 'fetch exact SHA1' '
 +      mk_test heads/master hidden/one &&
 +      git push testrepo master:refs/hidden/one &&
 +      (
 +              cd testrepo &&
 +              git config transfer.hiderefs refs/hidden
 +      ) &&
 +      check_push_result $the_commit hidden/one &&
 +
 +      mk_child child &&
 +      (
 +              cd child &&
 +
 +              # make sure $the_commit does not exist here
 +              git repack -a -d &&
 +              git prune &&
 +              test_must_fail git cat-file -t $the_commit &&
 +
 +              # fetching the hidden object should fail by default
 +              test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy &&
 +              test_must_fail git rev-parse --verify refs/heads/copy &&
 +
 +              # the server side can allow it to succeed
 +              (
 +                      cd ../testrepo &&
 +                      git config uploadpack.allowtipsha1inwant true
 +              ) &&
 +
 +              git fetch -v ../testrepo $the_commit:refs/heads/copy &&
 +              result=$(git rev-parse --verify refs/heads/copy) &&
 +              test "$the_commit" = "$result"
 +      )
 +'
 +
 +test_expect_success 'fetch follows tags by default' '
 +      mk_test heads/master &&
 +      rm -fr src dst &&
 +      git init src &&
 +      (
 +              cd src &&
 +              git pull ../testrepo master &&
 +              git tag -m "annotated" tag &&
 +              git for-each-ref >tmp1 &&
 +              (
 +                      cat tmp1
 +                      sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
 +              ) |
 +              sort -k 3 >../expect
 +      ) &&
 +      git init dst &&
 +      (
 +              cd dst &&
 +              git remote add origin ../src &&
 +              git config branch.master.remote origin &&
 +              git config branch.master.merge refs/heads/master &&
 +              git pull &&
 +              git for-each-ref >../actual
 +      ) &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'push does not follow tags by default' '
 +      mk_test heads/master &&
 +      rm -fr src dst &&
 +      git init src &&
 +      git init --bare dst &&
 +      (
 +              cd src &&
 +              git pull ../testrepo master &&
 +              git tag -m "annotated" tag &&
 +              git checkout -b another &&
 +              git commit --allow-empty -m "future commit" &&
 +              git tag -m "future" future &&
 +              git checkout master &&
 +              git for-each-ref refs/heads/master >../expect &&
 +              git push ../dst master
 +      ) &&
 +      (
 +              cd dst &&
 +              git for-each-ref >../actual
 +      ) &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'push --follow-tag only pushes relevant tags' '
 +      mk_test heads/master &&
 +      rm -fr src dst &&
 +      git init src &&
 +      git init --bare dst &&
 +      (
 +              cd src &&
 +              git pull ../testrepo master &&
 +              git tag -m "annotated" tag &&
 +              git checkout -b another &&
 +              git commit --allow-empty -m "future commit" &&
 +              git tag -m "future" future &&
 +              git checkout master &&
 +              git for-each-ref refs/heads/master refs/tags/tag >../expect
 +              git push --follow-tag ../dst master
 +      ) &&
 +      (
 +              cd dst &&
 +              git for-each-ref >../actual
 +      ) &&
 +      test_cmp expect actual
 +'
 +
  test_done