Code

Merge branch 'maint-1.7.6' into maint-1.7.7
[git.git] / t / t5510-fetch.sh
index 13d1d826c20293c26c739c70c0a36ed48bbb41d1..e0af4c4e62c40a563f692361944cc58e2c8e38e2 100755 (executable)
@@ -9,6 +9,11 @@ test_description='Per branch config variables affects "git fetch".
 
 D=`pwd`
 
+test_bundle_object_count () {
+       git verify-pack -v "$1" >verify.out &&
+       test "$2" = $(grep '^[0-9a-f]\{40\} ' verify.out | wc -l)
+}
+
 test_expect_success setup '
        echo >file original &&
        git add file &&
@@ -16,27 +21,30 @@ test_expect_success setup '
 
 test_expect_success "clone and setup child repos" '
        git clone . one &&
-       cd one &&
-       echo >file updated by one &&
-       git commit -a -m "updated by one" &&
-       cd .. &&
+       (
+               cd one &&
+               echo >file updated by one &&
+               git commit -a -m "updated by one"
+       ) &&
        git clone . two &&
-       cd two &&
-       git config branch.master.remote one &&
-       git config remote.one.url ../one/.git/ &&
-       git config remote.one.fetch refs/heads/master:refs/heads/one &&
-       cd .. &&
+       (
+               cd two &&
+               git config branch.master.remote one &&
+               git config remote.one.url ../one/.git/ &&
+               git config remote.one.fetch refs/heads/master:refs/heads/one
+       ) &&
        git clone . three &&
-       cd three &&
-       git config branch.master.remote two &&
-       git config branch.master.merge refs/heads/one &&
-       mkdir -p .git/remotes &&
-       {
-               echo "URL: ../two/.git/"
-               echo "Pull: refs/heads/master:refs/heads/two"
-               echo "Pull: refs/heads/one:refs/heads/one"
-       } >.git/remotes/two &&
-       cd .. &&
+       (
+               cd three &&
+               git config branch.master.remote two &&
+               git config branch.master.merge refs/heads/one &&
+               mkdir -p .git/remotes &&
+               {
+                       echo "URL: ../two/.git/"
+                       echo "Pull: refs/heads/master:refs/heads/two"
+                       echo "Pull: refs/heads/one:refs/heads/one"
+               } >.git/remotes/two
+       ) &&
        git clone . bundle &&
        git clone . seven
 '
@@ -66,7 +74,57 @@ test_expect_success "fetch test for-merge" '
                echo "$one_in_two       "
        } >expected &&
        cut -f -2 .git/FETCH_HEAD >actual &&
-       diff expected actual'
+       test_cmp expected actual'
+
+test_expect_success 'fetch --prune on its own works as expected' '
+       cd "$D" &&
+       git clone . prune &&
+       cd prune &&
+       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+
+       git fetch --prune origin &&
+       test_must_fail git rev-parse origin/extrabranch
+'
+
+test_expect_success 'fetch --prune with a branch name keeps branches' '
+       cd "$D" &&
+       git clone . prune-branch &&
+       cd prune-branch &&
+       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+
+       git fetch --prune origin master &&
+       git rev-parse origin/extrabranch
+'
+
+test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
+       cd "$D" &&
+       git clone . prune-namespace &&
+       cd prune-namespace &&
+
+       git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
+       git rev-parse origin/master
+'
+
+test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
+       cd "$D" &&
+       git clone . prune-tags &&
+       cd prune-tags &&
+       git fetch origin refs/heads/master:refs/tags/sometag &&
+
+       git fetch --prune --tags origin &&
+       git rev-parse origin/master &&
+       test_must_fail git rev-parse somebranch
+'
+
+test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
+       cd "$D" &&
+       git clone . prune-tags-branch &&
+       cd prune-tags-branch &&
+       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+
+       git fetch --prune --tags origin master &&
+       git rev-parse origin/extrabranch
+'
 
 test_expect_success 'fetch tags when there is no tags' '
 
@@ -111,7 +169,7 @@ test_expect_success 'fetch must not resolve short tag name' '
 test_expect_success 'fetch must not resolve short remote name' '
 
        cd "$D" &&
-       git-update-ref refs/remotes/six/HEAD HEAD
+       git update-ref refs/remotes/six/HEAD HEAD &&
 
        mkdir six &&
        cd six &&
@@ -146,6 +204,7 @@ test_expect_success 'unbundle 1' '
        test_must_fail git fetch "$D/bundle1" master:master
 '
 
+
 test_expect_success 'bundle 1 has only 3 files ' '
        cd "$D" &&
        (
@@ -156,8 +215,7 @@ test_expect_success 'bundle 1 has only 3 files ' '
                cat
        ) <bundle1 >bundle.pack &&
        git index-pack bundle.pack &&
-       verify=$(git verify-pack -v bundle.pack) &&
-       test 4 = $(echo "$verify" | wc -l)
+       test_bundle_object_count bundle.pack 3
 '
 
 test_expect_success 'unbundle 2' '
@@ -180,7 +238,7 @@ test_expect_success 'bundle does not prerequisite objects' '
                cat
        ) <bundle3 >bundle.pack &&
        git index-pack bundle.pack &&
-       test 4 = $(git verify-pack -v bundle.pack | wc -l)
+       test_bundle_object_count bundle.pack 3
 '
 
 test_expect_success 'bundle should be able to create a full history' '
@@ -191,38 +249,39 @@ test_expect_success 'bundle should be able to create a full history' '
 
 '
 
-test "$TEST_RSYNC" && {
+! rsync --help > /dev/null 2> /dev/null &&
+say 'Skipping rsync tests because rsync was not found' || {
 test_expect_success 'fetch via rsync' '
        git pack-refs &&
        mkdir rsynced &&
-       cd rsynced &&
-       git init &&
-       git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master &&
-       git gc --prune &&
-       test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
-       git fsck --full
+       (cd rsynced &&
+        git init --bare &&
+        git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
+        git gc --prune &&
+        test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
+        git fsck --full)
 '
 
 test_expect_success 'push via rsync' '
-       mkdir ../rsynced2 &&
-       (cd ../rsynced2 &&
+       mkdir rsynced2 &&
+       (cd rsynced2 &&
         git init) &&
-       git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master &&
-       cd ../rsynced2 &&
-       git gc --prune &&
-       test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
-       git fsck --full
+       (cd rsynced &&
+        git push "rsync:$(pwd)/../rsynced2/.git" master) &&
+       (cd rsynced2 &&
+        git gc --prune &&
+        test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
+        git fsck --full)
 '
 
 test_expect_success 'push via rsync' '
-       cd .. &&
        mkdir rsynced3 &&
        (cd rsynced3 &&
         git init) &&
-       git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git &&
-       cd rsynced3 &&
-       test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
-       git fsck --full
+       git push --all "rsync:$(pwd)/rsynced3/.git" &&
+       (cd rsynced3 &&
+        test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
+        git fsck --full)
 '
 }
 
@@ -234,6 +293,38 @@ test_expect_success 'fetch with a non-applying branch.<name>.merge' '
        git fetch blub
 '
 
+# URL supplied to fetch does not match the url of the configured branch's remote
+test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
+       one_head=$(cd one && git rev-parse HEAD) &&
+       this_head=$(git rev-parse HEAD) &&
+       git update-ref -d FETCH_HEAD &&
+       git fetch one &&
+       test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
+       test $this_head = "$(git rev-parse --verify HEAD)"
+'
+
+# URL supplied to fetch matches the url of the configured branch's remote and
+# the merge spec matches the branch the remote HEAD points to
+test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
+       one_ref=$(cd one && git symbolic-ref HEAD) &&
+       git config branch.master.remote blub &&
+       git config branch.master.merge "$one_ref" &&
+       git update-ref -d FETCH_HEAD &&
+       git fetch one &&
+       test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
+       test $this_head = "$(git rev-parse --verify HEAD)"
+'
+
+# URL supplied to fetch matches the url of the configured branch's remote, but
+# the merge spec does not match the branch the remote HEAD points to
+test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
+       git config branch.master.merge "${one_ref}_not" &&
+       git update-ref -d FETCH_HEAD &&
+       git fetch one &&
+       test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
+       test $this_head = "$(git rev-parse --verify HEAD)"
+'
+
 # the strange name is: a\!'b
 test_expect_success 'quoting of a strangely named repo' '
        test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
@@ -303,4 +394,54 @@ test_expect_success 'pushing nonexistent branch by mistake should not segv' '
 
 '
 
+test_expect_success 'auto tag following fetches minimum' '
+
+       cd "$D" &&
+       git clone .git follow &&
+       git checkout HEAD^0 &&
+       (
+               for i in 1 2 3 4 5 6 7
+               do
+                       echo $i >>file &&
+                       git commit -m $i -a &&
+                       git tag -a -m $i excess-$i || exit 1
+               done
+       ) &&
+       git checkout master &&
+       (
+               cd follow &&
+               git fetch
+       )
+'
+
+test_expect_success 'refuse to fetch into the current branch' '
+
+       test_must_fail git fetch . side:master
+
+'
+
+test_expect_success 'fetch into the current branch with --update-head-ok' '
+
+       git fetch --update-head-ok . side:master
+
+'
+
+test_expect_success 'fetch --dry-run' '
+
+       rm -f .git/FETCH_HEAD &&
+       git fetch --dry-run . &&
+       ! test -f .git/FETCH_HEAD
+'
+
+test_expect_success "should be able to fetch with duplicate refspecs" '
+        mkdir dups &&
+        cd dups &&
+        git init &&
+        git config branch.master.remote three &&
+        git config remote.three.url ../three/.git &&
+        git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
+        git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
+        git fetch three
+'
+
 test_done