]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t5510-fetch.sh
fetch --prune: Run prune before fetching
[thirdparty/git.git] / t / t5510-fetch.sh
index fde689166a5dcb419e0519580d628f91f1f29f83..12674ac0980fdafd60037bdff8009bb02a6da14a 100755 (executable)
@@ -88,7 +88,7 @@ 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 update-ref refs/remotes/origin/extrabranch master &&
 
        git fetch --prune origin &&
        test_must_fail git rev-parse origin/extrabranch
@@ -98,7 +98,7 @@ 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 update-ref refs/remotes/origin/extrabranch master &&
 
        git fetch --prune origin master &&
        git rev-parse origin/extrabranch
@@ -113,25 +113,45 @@ test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
        git rev-parse origin/master
 '
 
-test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
+test_expect_success 'fetch --prune --tags prunes branches but not tags' '
        cd "$D" &&
        git clone . prune-tags &&
        cd prune-tags &&
-       git fetch origin refs/heads/master:refs/tags/sometag &&
+       git tag sometag master &&
+       # Create what looks like a remote-tracking branch from an earlier
+       # fetch that has since been deleted from the remote:
+       git update-ref refs/remotes/origin/fake-remote master &&
 
        git fetch --prune --tags origin &&
        git rev-parse origin/master &&
-       test_must_fail git rev-parse somebranch
+       test_must_fail git rev-parse origin/fake-remote &&
+       git rev-parse sometag
 '
 
-test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
+test_expect_success 'fetch --prune --tags with branch does not prune other things' '
        cd "$D" &&
        git clone . prune-tags-branch &&
        cd prune-tags-branch &&
-       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+       git tag sometag master &&
+       git update-ref refs/remotes/origin/extrabranch master &&
 
        git fetch --prune --tags origin master &&
-       git rev-parse origin/extrabranch
+       git rev-parse origin/extrabranch &&
+       git rev-parse sometag
+'
+
+test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' '
+       cd "$D" &&
+       git clone . prune-tags-refspec &&
+       cd prune-tags-refspec &&
+       git tag sometag master &&
+       git update-ref refs/remotes/origin/foo/otherbranch master &&
+       git update-ref refs/remotes/origin/extrabranch master &&
+
+       git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
+       test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
+       git rev-parse origin/extrabranch &&
+       git rev-parse sometag
 '
 
 test_expect_success 'fetch tags when there is no tags' '
@@ -497,6 +517,88 @@ test_expect_success "should be able to fetch with duplicate refspecs" '
        )
 '
 
+# configured prune tests
+
+set_config_tristate () {
+       # var=$1 val=$2
+       case "$2" in
+       unset)  test_unconfig "$1" ;;
+       *)      git config "$1" "$2" ;;
+       esac
+}
+
+test_configured_prune () {
+       fetch_prune=$1 remote_origin_prune=$2 cmdline=$3 expected=$4
+
+       test_expect_success "prune fetch.prune=$1 remote.origin.prune=$2${3:+ $3}; $4" '
+               # make sure a newbranch is there in . and also in one
+               git branch -f newbranch &&
+               (
+                       cd one &&
+                       test_unconfig fetch.prune &&
+                       test_unconfig remote.origin.prune &&
+                       git fetch &&
+                       git rev-parse --verify refs/remotes/origin/newbranch
+               )
+
+               # now remove it
+               git branch -d newbranch &&
+
+               # then test
+               (
+                       cd one &&
+                       set_config_tristate fetch.prune $fetch_prune &&
+                       set_config_tristate remote.origin.prune $remote_origin_prune &&
+
+                       git fetch $cmdline &&
+                       case "$expected" in
+                       pruned)
+                               test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
+                               ;;
+                       kept)
+                               git rev-parse --verify refs/remotes/origin/newbranch
+                               ;;
+                       esac
+               )
+       '
+}
+
+test_configured_prune unset unset ""           kept
+test_configured_prune unset unset "--no-prune" kept
+test_configured_prune unset unset "--prune"    pruned
+
+test_configured_prune false unset ""           kept
+test_configured_prune false unset "--no-prune" kept
+test_configured_prune false unset "--prune"    pruned
+
+test_configured_prune true  unset ""           pruned
+test_configured_prune true  unset "--prune"    pruned
+test_configured_prune true  unset "--no-prune" kept
+
+test_configured_prune unset false ""           kept
+test_configured_prune unset false "--no-prune" kept
+test_configured_prune unset false "--prune"    pruned
+
+test_configured_prune false false ""           kept
+test_configured_prune false false "--no-prune" kept
+test_configured_prune false false "--prune"    pruned
+
+test_configured_prune true  false ""           kept
+test_configured_prune true  false "--prune"    pruned
+test_configured_prune true  false "--no-prune" kept
+
+test_configured_prune unset true  ""           pruned
+test_configured_prune unset true  "--no-prune" kept
+test_configured_prune unset true  "--prune"    pruned
+
+test_configured_prune false true  ""           pruned
+test_configured_prune false true  "--no-prune" kept
+test_configured_prune false true  "--prune"    pruned
+
+test_configured_prune true  true  ""           pruned
+test_configured_prune true  true  "--prune"    pruned
+test_configured_prune true  true  "--no-prune" kept
+
 test_expect_success 'all boundary commits are excluded' '
        test_commit base &&
        test_commit oneside &&
@@ -512,4 +614,30 @@ test_expect_success 'all boundary commits are excluded' '
        test_bundle_object_count .git/objects/pack/pack-${pack##pack    }.pack 3
 '
 
+test_expect_success 'fetch --prune prints the remotes url' '
+       git branch goodbye &&
+       git clone . only-prunes &&
+       git branch -D goodbye &&
+       (
+               cd only-prunes &&
+               git fetch --prune origin 2>&1 | head -n1 >../actual
+       ) &&
+       echo "From ${D}/." >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'branchname D/F conflict resolved by --prune' '
+       git branch dir/file &&
+       git clone . prune-df-conflict &&
+       git branch -D dir/file &&
+       git branch dir &&
+       (
+               cd prune-df-conflict &&
+               git fetch --prune &&
+               git rev-parse origin/dir >../actual
+       ) &&
+       git rev-parse dir >expect &&
+       test_cmp expect actual
+'
+
 test_done