summaryrefslogtreecommitdiff
path: root/t/t5516-fetch-push.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t5516-fetch-push.sh')
-rwxr-xr-xt/t5516-fetch-push.sh972
1 files changed, 573 insertions, 399 deletions
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 9c6218f..2e7c0e1 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -12,22 +12,24 @@ This test checks the following functionality:
* --porcelain output format
* hiderefs
* reflogs
+* URL validation
'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
D=$(pwd)
mk_empty () {
repo_name="$1"
- rm -fr "$repo_name" &&
- mkdir "$repo_name" &&
- (
- cd "$repo_name" &&
- git init &&
- git config receive.denyCurrentBranch warn &&
- mv .git/hooks .git/hooks-disabled
- )
+ test_when_finished "rm -rf \"$repo_name\"" &&
+ test_path_is_missing "$repo_name" &&
+ git init --template= "$repo_name" &&
+ mkdir "$repo_name"/.git/hooks &&
+ git -C "$repo_name" config receive.denyCurrentBranch warn
}
mk_test () {
@@ -56,41 +58,29 @@ mk_test () {
mk_test_with_hooks() {
repo_name=$1
mk_test "$@" &&
- (
- cd "$repo_name" &&
- mkdir .git/hooks &&
- cd .git/hooks &&
-
- cat >pre-receive <<-'EOF' &&
- #!/bin/sh
- cat - >>pre-receive.actual
- EOF
-
- cat >update <<-'EOF' &&
- #!/bin/sh
- printf "%s %s %s\n" "$@" >>update.actual
- EOF
-
- cat >post-receive <<-'EOF' &&
- #!/bin/sh
- cat - >>post-receive.actual
- EOF
-
- cat >post-update <<-'EOF' &&
- #!/bin/sh
- for ref in "$@"
- do
- printf "%s\n" "$ref" >>post-update.actual
- done
- EOF
-
- chmod +x pre-receive update post-receive post-update
- )
+ test_hook -C "$repo_name" pre-receive <<-'EOF' &&
+ cat - >>pre-receive.actual
+ EOF
+
+ test_hook -C "$repo_name" update <<-'EOF' &&
+ printf "%s %s %s\n" "$@" >>update.actual
+ EOF
+
+ test_hook -C "$repo_name" post-receive <<-'EOF' &&
+ cat - >>post-receive.actual
+ EOF
+
+ test_hook -C "$repo_name" post-update <<-'EOF'
+ for ref in "$@"
+ do
+ printf "%s\n" "$ref" >>post-update.actual
+ done
+ EOF
}
mk_child() {
- rm -rf "$2" &&
- git clone "$1" "$2"
+ test_when_finished "rm -rf \"$2\"" &&
+ git clone --template= "$1" "$2"
}
check_push_result () {
@@ -120,23 +110,34 @@ test_expect_success setup '
git add path1 &&
test_tick &&
git commit -a -m repo &&
- the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
+ the_first_commit=$(git show-ref -s --verify refs/heads/main) &&
>path2 &&
git add path2 &&
test_tick &&
git commit -a -m second &&
- the_commit=$(git show-ref -s --verify refs/heads/master)
+ the_commit=$(git show-ref -s --verify refs/heads/main)
'
+for cmd in push fetch
+do
+ for opt in ipv4 ipv6
+ do
+ test_expect_success "reject 'git $cmd --no-$opt'" '
+ test_must_fail git $cmd --no-$opt 2>err &&
+ grep "unknown option .no-$opt" err
+ '
+ done
+done
+
test_expect_success 'fetch without wildcard' '
mk_empty testrepo &&
(
cd testrepo &&
- git fetch .. refs/heads/master:refs/remotes/origin/master &&
+ git fetch .. refs/heads/main:refs/remotes/origin/main &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -150,7 +151,7 @@ test_expect_success 'fetch with wildcard' '
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
git fetch up &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -166,7 +167,7 @@ test_expect_success 'fetch with insteadOf' '
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
git fetch up &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -182,19 +183,76 @@ test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
git fetch up &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
'
+grep_wrote () {
+ object_count=$1
+ file_name=$2
+ grep 'write_pack_file/wrote.*"value":"'$1'"' $2
+}
+
+test_expect_success 'push without negotiation' '
+ mk_empty testrepo &&
+ git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
+ test_commit -C testrepo unrelated_commit &&
+ git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
+ test_when_finished "rm event" &&
+ GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
+ grep_wrote 5 event # 2 commits, 2 trees, 1 blob
+'
+
+test_expect_success 'push with negotiation' '
+ mk_empty testrepo &&
+ git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
+ test_commit -C testrepo unrelated_commit &&
+ git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
+ test_when_finished "rm event" &&
+ GIT_TRACE2_EVENT="$(pwd)/event" \
+ git -c protocol.version=2 -c push.negotiate=1 \
+ push testrepo refs/heads/main:refs/remotes/origin/main &&
+ grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
+ grep_wrote 2 event # 1 commit, 1 tree
+'
+
+test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' '
+ mk_empty testrepo &&
+ git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
+ test_commit -C testrepo unrelated_commit &&
+ git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
+ test_when_finished "rm event" &&
+ GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
+ git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
+ grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
+ test_grep "push negotiation failed" err
+'
+
+test_expect_success 'push with negotiation does not attempt to fetch submodules' '
+ mk_empty submodule_upstream &&
+ test_commit -C submodule_upstream submodule_commit &&
+ test_config_global protocol.file.allow always &&
+ git submodule add ./submodule_upstream submodule &&
+ mk_empty testrepo &&
+ git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
+ test_commit -C testrepo unrelated_commit &&
+ git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
+ GIT_TRACE2_EVENT="$(pwd)/event" git -c submodule.recurse=true \
+ -c protocol.version=2 -c push.negotiate=1 \
+ push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
+ grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
+ ! grep "Fetching submodule" err
+'
+
test_expect_success 'push without wildcard' '
mk_empty testrepo &&
- git push testrepo refs/heads/master:refs/remotes/origin/master &&
+ git push testrepo refs/heads/main:refs/remotes/origin/main &&
(
cd testrepo &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -206,7 +264,7 @@ test_expect_success 'push with wildcard' '
git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
(
cd testrepo &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -216,10 +274,10 @@ test_expect_success 'push with insteadOf' '
mk_empty testrepo &&
TRASH="$(pwd)/" &&
test_config "url.$TRASH.insteadOf" trash/ &&
- git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
+ git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
(
cd testrepo &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -229,10 +287,10 @@ test_expect_success 'push with pushInsteadOf' '
mk_empty testrepo &&
TRASH="$(pwd)/" &&
test_config "url.$TRASH.pushInsteadOf" trash/ &&
- git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
+ git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
(
cd testrepo &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -244,10 +302,10 @@ test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf
test_config "url.trash3/.pushInsteadOf" trash/wrong &&
test_config remote.r.url trash/wrong &&
test_config remote.r.pushurl "testrepo/" &&
- git push r refs/heads/master:refs/remotes/origin/master &&
+ git push r refs/heads/main:refs/remotes/origin/main &&
(
cd testrepo &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
)
@@ -255,109 +313,114 @@ test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf
test_expect_success 'push with matching heads' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
git push testrepo : &&
- check_push_result testrepo $the_commit heads/master
+ check_push_result testrepo $the_commit heads/main
'
test_expect_success 'push with matching heads on the command line' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
git push testrepo : &&
- check_push_result testrepo $the_commit heads/master
+ check_push_result testrepo $the_commit heads/main
'
test_expect_success 'failed (non-fast-forward) push with matching heads' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
git push testrepo : &&
git commit --amend -massaged &&
test_must_fail git push testrepo &&
- check_push_result testrepo $the_commit heads/master &&
+ check_push_result testrepo $the_commit heads/main &&
git reset --hard $the_commit
'
test_expect_success 'push --force with matching heads' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
git push testrepo : &&
git commit --amend -massaged &&
git push --force testrepo : &&
- ! check_push_result testrepo $the_commit heads/master &&
+ ! check_push_result testrepo $the_commit heads/main &&
git reset --hard $the_commit
'
test_expect_success 'push with matching heads and forced update' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
git push testrepo : &&
git commit --amend -massaged &&
git push testrepo +: &&
- ! check_push_result testrepo $the_commit heads/master &&
+ ! check_push_result testrepo $the_commit heads/main &&
git reset --hard $the_commit
'
test_expect_success 'push with no ambiguity (1)' '
- mk_test testrepo heads/master &&
- git push testrepo master:master &&
- check_push_result testrepo $the_commit heads/master
+ mk_test testrepo heads/main &&
+ git push testrepo main:main &&
+ check_push_result testrepo $the_commit heads/main
'
test_expect_success 'push with no ambiguity (2)' '
- mk_test testrepo remotes/origin/master &&
- git push testrepo master:origin/master &&
- check_push_result testrepo $the_commit remotes/origin/master
+ mk_test testrepo remotes/origin/main &&
+ git push testrepo main:origin/main &&
+ check_push_result testrepo $the_commit remotes/origin/main
'
test_expect_success 'push with colon-less refspec, no ambiguity' '
- mk_test testrepo heads/master heads/t/master &&
- git branch -f t/master master &&
- git push testrepo master &&
- check_push_result testrepo $the_commit heads/master &&
- check_push_result testrepo $the_first_commit heads/t/master
+ mk_test testrepo heads/main heads/t/main &&
+ git branch -f t/main main &&
+ git push testrepo main &&
+ check_push_result testrepo $the_commit heads/main &&
+ check_push_result testrepo $the_first_commit heads/t/main
'
test_expect_success 'push with weak ambiguity (1)' '
- mk_test testrepo heads/master remotes/origin/master &&
- git push testrepo master:master &&
- check_push_result testrepo $the_commit heads/master &&
- check_push_result testrepo $the_first_commit remotes/origin/master
+ mk_test testrepo heads/main remotes/origin/main &&
+ git push testrepo main:main &&
+ check_push_result testrepo $the_commit heads/main &&
+ check_push_result testrepo $the_first_commit remotes/origin/main
'
test_expect_success 'push with weak ambiguity (2)' '
- mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
- git push testrepo master:master &&
- check_push_result testrepo $the_commit heads/master &&
- check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
+ mk_test testrepo heads/main remotes/origin/main remotes/another/main &&
+ git push testrepo main:main &&
+ check_push_result testrepo $the_commit heads/main &&
+ check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main
'
test_expect_success 'push with ambiguity' '
mk_test testrepo heads/frotz tags/frotz &&
- test_must_fail git push testrepo master:frotz &&
+ test_must_fail git push testrepo main:frotz &&
check_push_result testrepo $the_first_commit heads/frotz tags/frotz
'
+test_expect_success 'push with onelevel ref' '
+ mk_test testrepo heads/main &&
+ test_must_fail git push testrepo HEAD:refs/onelevel
+'
+
test_expect_success 'push with colon-less refspec (1)' '
mk_test testrepo heads/frotz tags/frotz &&
- git branch -f frotz master &&
+ git branch -f frotz main &&
git push testrepo frotz &&
check_push_result testrepo $the_commit heads/frotz &&
check_push_result testrepo $the_first_commit tags/frotz
@@ -385,7 +448,7 @@ test_expect_success 'push with colon-less refspec (3)' '
then
git tag -d frotz
fi &&
- git branch -f frotz master &&
+ git branch -f frotz main &&
git push testrepo frotz &&
check_push_result testrepo $the_commit heads/frotz &&
test 1 = $( cd testrepo && git show-ref | wc -l )
@@ -408,7 +471,7 @@ test_expect_success 'push with colon-less refspec (4)' '
test_expect_success 'push head with non-existent, incomplete dest' '
mk_test testrepo &&
- git push testrepo master:branch &&
+ git push testrepo main:branch &&
check_push_result testrepo $the_commit heads/branch
'
@@ -425,236 +488,263 @@ test_expect_success 'push tag with non-existent, incomplete dest' '
test_expect_success 'push sha1 with non-existent, incomplete dest' '
mk_test testrepo &&
- test_must_fail git push testrepo $(git rev-parse master):foo
+ test_must_fail git push testrepo $(git rev-parse main):foo
'
test_expect_success 'push ref expression with non-existent, incomplete dest' '
mk_test testrepo &&
- test_must_fail git push testrepo master^:branch
+ test_must_fail git push testrepo main^:branch
'
-test_expect_success 'push with HEAD' '
-
- mk_test testrepo heads/master &&
- git checkout master &&
- git push testrepo HEAD &&
- check_push_result testrepo $the_commit heads/master
-
-'
-
-test_expect_success 'push with HEAD nonexisting at remote' '
-
- mk_test testrepo heads/master &&
- git checkout -b local master &&
- git push testrepo HEAD &&
- check_push_result testrepo $the_commit heads/local
-'
-
-test_expect_success 'push with +HEAD' '
-
- mk_test testrepo heads/master &&
- git checkout master &&
- git branch -D local &&
- git checkout -b local &&
- git push testrepo master local &&
- check_push_result testrepo $the_commit heads/master &&
- check_push_result testrepo $the_commit heads/local &&
+for head in HEAD @
+do
- # Without force rewinding should fail
- git reset --hard HEAD^ &&
- test_must_fail git push testrepo HEAD &&
- check_push_result testrepo $the_commit heads/local &&
+ test_expect_success "push with $head" '
+ mk_test testrepo heads/main &&
+ git checkout main &&
+ git push testrepo $head &&
+ check_push_result testrepo $the_commit heads/main
+ '
- # With force rewinding should succeed
- git push testrepo +HEAD &&
- check_push_result testrepo $the_first_commit heads/local
+ test_expect_success "push with $head nonexisting at remote" '
+ mk_test testrepo heads/main &&
+ git checkout -b local main &&
+ test_when_finished "git checkout main; git branch -D local" &&
+ git push testrepo $head &&
+ check_push_result testrepo $the_commit heads/local
+ '
-'
+ test_expect_success "push with +$head" '
+ mk_test testrepo heads/main &&
+ git checkout -b local main &&
+ test_when_finished "git checkout main; git branch -D local" &&
+ git push testrepo main local &&
+ check_push_result testrepo $the_commit heads/main &&
+ check_push_result testrepo $the_commit heads/local &&
+
+ # Without force rewinding should fail
+ git reset --hard $head^ &&
+ test_must_fail git push testrepo $head &&
+ check_push_result testrepo $the_commit heads/local &&
+
+ # With force rewinding should succeed
+ git push testrepo +$head &&
+ check_push_result testrepo $the_first_commit heads/local
+ '
-test_expect_success 'push HEAD with non-existent, incomplete dest' '
+ test_expect_success "push $head with non-existent, incomplete dest" '
+ mk_test testrepo &&
+ git checkout main &&
+ git push testrepo $head:branch &&
+ check_push_result testrepo $the_commit heads/branch
- mk_test testrepo &&
- git checkout master &&
- git push testrepo HEAD:branch &&
- check_push_result testrepo $the_commit heads/branch
+ '
-'
+ test_expect_success "push with config remote.*.push = $head" '
+ mk_test testrepo heads/local &&
+ git checkout main &&
+ git branch -f local $the_commit &&
+ test_when_finished "git branch -D local" &&
+ (
+ cd testrepo &&
+ git checkout local &&
+ git reset --hard $the_first_commit
+ ) &&
+ test_config remote.there.url testrepo &&
+ test_config remote.there.push $head &&
+ test_config branch.main.remote there &&
+ git push &&
+ check_push_result testrepo $the_commit heads/main &&
+ check_push_result testrepo $the_first_commit heads/local
+ '
-test_expect_success 'push with config remote.*.push = HEAD' '
+done
- mk_test testrepo heads/local &&
- git checkout master &&
- git branch -f local $the_commit &&
- (
- cd testrepo &&
- git checkout local &&
- git reset --hard $the_first_commit
- ) &&
+test_expect_success "push to remote with no explicit refspec and config remote.*.push = src:dest" '
+ mk_test testrepo heads/main &&
+ git checkout $the_first_commit &&
test_config remote.there.url testrepo &&
- test_config remote.there.push HEAD &&
- test_config branch.master.remote there &&
- git push &&
- check_push_result testrepo $the_commit heads/master &&
- check_push_result testrepo $the_first_commit heads/local
+ test_config remote.there.push refs/heads/main:refs/heads/main &&
+ git push there &&
+ check_push_result testrepo $the_commit heads/main
'
test_expect_success 'push with remote.pushdefault' '
- mk_test up_repo heads/master &&
- mk_test down_repo heads/master &&
+ mk_test up_repo heads/main &&
+ mk_test down_repo heads/main &&
test_config remote.up.url up_repo &&
test_config remote.down.url down_repo &&
- test_config branch.master.remote up &&
+ test_config branch.main.remote up &&
test_config remote.pushdefault down &&
test_config push.default matching &&
git push &&
- check_push_result up_repo $the_first_commit heads/master &&
- check_push_result down_repo $the_commit heads/master
+ check_push_result up_repo $the_first_commit heads/main &&
+ check_push_result down_repo $the_commit heads/main
'
test_expect_success 'push with config remote.*.pushurl' '
- mk_test testrepo heads/master &&
- git checkout master &&
+ mk_test testrepo heads/main &&
+ git checkout main &&
test_config remote.there.url test2repo &&
test_config remote.there.pushurl testrepo &&
git push there : &&
- check_push_result testrepo $the_commit heads/master
+ check_push_result testrepo $the_commit heads/main
'
test_expect_success 'push with config branch.*.pushremote' '
- mk_test up_repo heads/master &&
- mk_test side_repo heads/master &&
- mk_test down_repo heads/master &&
+ mk_test up_repo heads/main &&
+ mk_test side_repo heads/main &&
+ mk_test down_repo heads/main &&
test_config remote.up.url up_repo &&
test_config remote.pushdefault side_repo &&
test_config remote.down.url down_repo &&
- test_config branch.master.remote up &&
- test_config branch.master.pushremote down &&
+ test_config branch.main.remote up &&
+ test_config branch.main.pushremote down &&
test_config push.default matching &&
git push &&
- check_push_result up_repo $the_first_commit heads/master &&
- check_push_result side_repo $the_first_commit heads/master &&
- check_push_result down_repo $the_commit heads/master
+ check_push_result up_repo $the_first_commit heads/main &&
+ check_push_result side_repo $the_first_commit heads/main &&
+ check_push_result down_repo $the_commit heads/main
'
test_expect_success 'branch.*.pushremote config order is irrelevant' '
- mk_test one_repo heads/master &&
- mk_test two_repo heads/master &&
+ mk_test one_repo heads/main &&
+ mk_test two_repo heads/main &&
test_config remote.one.url one_repo &&
test_config remote.two.url two_repo &&
- test_config branch.master.pushremote two_repo &&
+ test_config branch.main.pushremote two_repo &&
test_config remote.pushdefault one_repo &&
test_config push.default matching &&
git push &&
- check_push_result one_repo $the_first_commit heads/master &&
- check_push_result two_repo $the_commit heads/master
+ check_push_result one_repo $the_first_commit heads/main &&
+ check_push_result two_repo $the_commit heads/main
+'
+
+test_expect_success 'push rejects empty branch name entries' '
+ mk_test one_repo heads/main &&
+ test_config remote.one.url one_repo &&
+ test_config branch..remote one &&
+ test_config branch..merge refs/heads/ &&
+ test_config branch.main.remote one &&
+ test_config branch.main.merge refs/heads/main &&
+ test_must_fail git push 2>err &&
+ grep "bad config variable .branch\.\." err
+'
+
+test_expect_success 'push ignores "branch." config without subsection' '
+ mk_test one_repo heads/main &&
+ test_config remote.one.url one_repo &&
+ test_config branch.autoSetupMerge true &&
+ test_config branch.main.remote one &&
+ test_config branch.main.merge refs/heads/main &&
+ git push
'
test_expect_success 'push with dry-run' '
- mk_test testrepo heads/master &&
- old_commit=$(git -C testrepo show-ref -s --verify refs/heads/master) &&
+ mk_test testrepo heads/main &&
+ old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) &&
git push --dry-run testrepo : &&
- check_push_result testrepo $old_commit heads/master
+ check_push_result testrepo $old_commit heads/main
'
test_expect_success 'push updates local refs' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child &&
(
cd child &&
- git pull .. master &&
+ git pull .. main &&
git push &&
- test $(git rev-parse master) = \
- $(git rev-parse remotes/origin/master)
+ test $(git rev-parse main) = \
+ $(git rev-parse remotes/origin/main)
)
'
test_expect_success 'push updates up-to-date local refs' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child1 &&
mk_child testrepo child2 &&
- (cd child1 && git pull .. master && git push) &&
+ (cd child1 && git pull .. main && git push) &&
(
cd child2 &&
- git pull ../child1 master &&
+ git pull ../child1 main &&
git push &&
- test $(git rev-parse master) = \
- $(git rev-parse remotes/origin/master)
+ test $(git rev-parse main) = \
+ $(git rev-parse remotes/origin/main)
)
'
test_expect_success 'push preserves up-to-date packed refs' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child &&
(
cd child &&
git push &&
- ! test -f .git/refs/remotes/origin/master
+ ! test -f .git/refs/remotes/origin/main
)
'
test_expect_success 'push does not update local refs on failure' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child &&
- mkdir testrepo/.git/hooks &&
echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
chmod +x testrepo/.git/hooks/pre-receive &&
(
cd child &&
- git pull .. master &&
+ git pull .. main &&
test_must_fail git push &&
- test $(git rev-parse master) != \
- $(git rev-parse remotes/origin/master)
+ test $(git rev-parse main) != \
+ $(git rev-parse remotes/origin/main)
)
'
test_expect_success 'allow deleting an invalid remote ref' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/branch &&
rm -f testrepo/.git/objects/??/* &&
- git push testrepo :refs/heads/master &&
- (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
+ git push testrepo :refs/heads/branch &&
+ (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
'
test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
- mk_test_with_hooks testrepo heads/master heads/next &&
- orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
- newmaster=$(git show-ref -s --verify refs/heads/master) &&
+ mk_test_with_hooks testrepo heads/main heads/next &&
+ orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
+ newmain=$(git show-ref -s --verify refs/heads/main) &&
orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
newnext=$ZERO_OID &&
- git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
+ git push testrepo refs/heads/main:refs/heads/main :refs/heads/next &&
(
cd testrepo/.git &&
cat >pre-receive.expect <<-EOF &&
- $orgmaster $newmaster refs/heads/master
+ $orgmain $newmain refs/heads/main
$orgnext $newnext refs/heads/next
EOF
cat >update.expect <<-EOF &&
- refs/heads/master $orgmaster $newmaster
+ refs/heads/main $orgmain $newmain
refs/heads/next $orgnext $newnext
EOF
cat >post-receive.expect <<-EOF &&
- $orgmaster $newmaster refs/heads/master
+ $orgmain $newmain refs/heads/main
$orgnext $newnext refs/heads/next
EOF
cat >post-update.expect <<-EOF &&
- refs/heads/master
+ refs/heads/main
refs/heads/next
EOF
@@ -666,25 +756,26 @@ test_expect_success 'pushing valid refs triggers post-receive and post-update ho
'
test_expect_success 'deleting dangling ref triggers hooks with correct args' '
- mk_test_with_hooks testrepo heads/master &&
+ mk_test_with_hooks testrepo heads/branch &&
+ orig=$(git -C testrepo rev-parse refs/heads/branch) &&
rm -f testrepo/.git/objects/??/* &&
- git push testrepo :refs/heads/master &&
+ git push testrepo :refs/heads/branch &&
(
cd testrepo/.git &&
cat >pre-receive.expect <<-EOF &&
- $ZERO_OID $ZERO_OID refs/heads/master
+ $orig $ZERO_OID refs/heads/branch
EOF
cat >update.expect <<-EOF &&
- refs/heads/master $ZERO_OID $ZERO_OID
+ refs/heads/branch $orig $ZERO_OID
EOF
cat >post-receive.expect <<-EOF &&
- $ZERO_OID $ZERO_OID refs/heads/master
+ $orig $ZERO_OID refs/heads/branch
EOF
cat >post-update.expect <<-EOF &&
- refs/heads/master
+ refs/heads/branch
EOF
test_cmp pre-receive.expect pre-receive.actual &&
@@ -695,28 +786,28 @@ test_expect_success 'deleting dangling ref triggers hooks with correct args' '
'
test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
- mk_test_with_hooks testrepo heads/master &&
- orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
- newmaster=$(git show-ref -s --verify refs/heads/master) &&
- git push testrepo master :refs/heads/nonexistent &&
+ mk_test_with_hooks testrepo heads/main &&
+ orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
+ newmain=$(git show-ref -s --verify refs/heads/main) &&
+ git push testrepo main :refs/heads/nonexistent &&
(
cd testrepo/.git &&
cat >pre-receive.expect <<-EOF &&
- $orgmaster $newmaster refs/heads/master
+ $orgmain $newmain refs/heads/main
$ZERO_OID $ZERO_OID refs/heads/nonexistent
EOF
cat >update.expect <<-EOF &&
- refs/heads/master $orgmaster $newmaster
+ refs/heads/main $orgmain $newmain
refs/heads/nonexistent $ZERO_OID $ZERO_OID
EOF
cat >post-receive.expect <<-EOF &&
- $orgmaster $newmaster refs/heads/master
+ $orgmain $newmain refs/heads/main
EOF
cat >post-update.expect <<-EOF &&
- refs/heads/master
+ refs/heads/main
EOF
test_cmp pre-receive.expect pre-receive.actual &&
@@ -727,7 +818,7 @@ test_expect_success 'deletion of a non-existent ref is not fed to post-receive a
'
test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
- mk_test_with_hooks testrepo heads/master &&
+ mk_test_with_hooks testrepo heads/main &&
git push testrepo :refs/heads/nonexistent &&
(
cd testrepo/.git &&
@@ -747,42 +838,42 @@ test_expect_success 'deletion of a non-existent ref alone does trigger post-rece
'
test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
- mk_test_with_hooks testrepo heads/master heads/next heads/pu &&
- orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
- newmaster=$(git show-ref -s --verify refs/heads/master) &&
+ mk_test_with_hooks testrepo heads/main heads/next heads/seen &&
+ orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
+ newmain=$(git show-ref -s --verify refs/heads/main) &&
orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
newnext=$ZERO_OID &&
- orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) &&
- newpu=$(git show-ref -s --verify refs/heads/master) &&
- git push testrepo refs/heads/master:refs/heads/master \
- refs/heads/master:refs/heads/pu :refs/heads/next \
+ orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
+ newseen=$(git show-ref -s --verify refs/heads/main) &&
+ git push testrepo refs/heads/main:refs/heads/main \
+ refs/heads/main:refs/heads/seen :refs/heads/next \
:refs/heads/nonexistent &&
(
cd testrepo/.git &&
cat >pre-receive.expect <<-EOF &&
- $orgmaster $newmaster refs/heads/master
+ $orgmain $newmain refs/heads/main
$orgnext $newnext refs/heads/next
- $orgpu $newpu refs/heads/pu
+ $orgseen $newseen refs/heads/seen
$ZERO_OID $ZERO_OID refs/heads/nonexistent
EOF
cat >update.expect <<-EOF &&
- refs/heads/master $orgmaster $newmaster
+ refs/heads/main $orgmain $newmain
refs/heads/next $orgnext $newnext
- refs/heads/pu $orgpu $newpu
+ refs/heads/seen $orgseen $newseen
refs/heads/nonexistent $ZERO_OID $ZERO_OID
EOF
cat >post-receive.expect <<-EOF &&
- $orgmaster $newmaster refs/heads/master
+ $orgmain $newmain refs/heads/main
$orgnext $newnext refs/heads/next
- $orgpu $newpu refs/heads/pu
+ $orgseen $newseen refs/heads/seen
EOF
cat >post-update.expect <<-EOF &&
- refs/heads/master
+ refs/heads/main
refs/heads/next
- refs/heads/pu
+ refs/heads/seen
EOF
test_cmp pre-receive.expect pre-receive.actual &&
@@ -793,15 +884,15 @@ test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks w
'
test_expect_success 'allow deleting a ref using --delete' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
(cd testrepo && git config receive.denyDeleteCurrent warn) &&
- git push testrepo --delete master &&
- (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
+ git push testrepo --delete main &&
+ (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main)
'
test_expect_success 'allow deleting a tag using --delete' '
- mk_test testrepo heads/master &&
- git tag -a -m dummy_message deltag heads/master &&
+ mk_test testrepo heads/main &&
+ git tag -a -m dummy_message deltag heads/main &&
git push testrepo --tags &&
(cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
git push testrepo --delete tag deltag &&
@@ -809,56 +900,68 @@ test_expect_success 'allow deleting a tag using --delete' '
'
test_expect_success 'push --delete without args aborts' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
test_must_fail git push testrepo --delete
'
test_expect_success 'push --delete refuses src:dest refspecs' '
+ mk_test testrepo heads/main &&
+ test_must_fail git push testrepo --delete main:foo
+'
+
+test_expect_success 'push --delete refuses empty string' '
mk_test testrepo heads/master &&
- test_must_fail git push testrepo --delete master:foo
+ test_must_fail git push testrepo --delete ""
+'
+
+test_expect_success 'push --delete onelevel refspecs' '
+ mk_test testrepo heads/main &&
+ git -C testrepo update-ref refs/onelevel refs/heads/main &&
+ git push testrepo --delete refs/onelevel &&
+ test_must_fail git -C testrepo rev-parse --verify refs/onelevel
'
test_expect_success 'warn on push to HEAD of non-bare repository' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
(
cd testrepo &&
- git checkout master &&
+ git checkout main &&
git config receive.denyCurrentBranch warn
) &&
- git push testrepo master 2>stderr &&
+ git push testrepo main 2>stderr &&
grep "warning: updating the current branch" stderr
'
test_expect_success 'deny push to HEAD of non-bare repository' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
(
cd testrepo &&
- git checkout master &&
+ git checkout main &&
git config receive.denyCurrentBranch true
) &&
- test_must_fail git push testrepo master
+ test_must_fail git push testrepo main
'
test_expect_success 'allow push to HEAD of bare repository (bare)' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
(
cd testrepo &&
- git checkout master &&
+ git checkout main &&
git config receive.denyCurrentBranch true &&
git config core.bare true
) &&
- git push testrepo master 2>stderr &&
+ git push testrepo main 2>stderr &&
! grep "warning: updating the current branch" stderr
'
test_expect_success 'allow push to HEAD of non-bare repository (config)' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
(
cd testrepo &&
- git checkout master &&
+ git checkout main &&
git config receive.denyCurrentBranch false
) &&
- git push testrepo master 2>stderr &&
+ git push testrepo main 2>stderr &&
! grep "warning: updating the current branch" stderr
'
@@ -866,6 +969,7 @@ test_expect_success 'fetch with branches' '
mk_empty testrepo &&
git branch second $the_first_commit &&
git checkout second &&
+ mkdir testrepo/.git/branches &&
echo ".." > testrepo/.git/branches/branch1 &&
(
cd testrepo &&
@@ -874,11 +978,12 @@ test_expect_success 'fetch with branches' '
git for-each-ref refs/heads >actual &&
test_cmp expect actual
) &&
- git checkout master
+ git checkout main
'
test_expect_success 'fetch with branches containing #' '
mk_empty testrepo &&
+ mkdir testrepo/.git/branches &&
echo "..#second" > testrepo/.git/branches/branch2 &&
(
cd testrepo &&
@@ -887,17 +992,21 @@ test_expect_success 'fetch with branches containing #' '
git for-each-ref refs/heads >actual &&
test_cmp expect actual
) &&
- git checkout master
+ git checkout main
'
test_expect_success 'push with branches' '
mk_empty testrepo &&
git checkout second &&
+
+ test_when_finished "rm -rf .git/branches" &&
+ mkdir .git/branches &&
echo "testrepo" > .git/branches/branch1 &&
+
git push branch1 &&
(
cd testrepo &&
- echo "$the_first_commit commit refs/heads/master" >expect &&
+ echo "$the_first_commit commit refs/heads/main" >expect &&
git for-each-ref refs/heads >actual &&
test_cmp expect actual
)
@@ -905,7 +1014,11 @@ test_expect_success 'push with branches' '
test_expect_success 'push with branches containing #' '
mk_empty testrepo &&
+
+ test_when_finished "rm -rf .git/branches" &&
+ mkdir .git/branches &&
echo "testrepo#branch3" > .git/branches/branch2 &&
+
git push branch2 &&
(
cd testrepo &&
@@ -913,11 +1026,11 @@ test_expect_success 'push with branches containing #' '
git for-each-ref refs/heads >actual &&
test_cmp expect actual
) &&
- git checkout master
+ git checkout main
'
test_expect_success 'push into aliased refs (consistent)' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child1 &&
mk_child testrepo child2 &&
(
@@ -939,7 +1052,7 @@ test_expect_success 'push into aliased refs (consistent)' '
'
test_expect_success 'push into aliased refs (inconsistent)' '
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child1 &&
mk_child testrepo child2 &&
(
@@ -970,7 +1083,7 @@ test_force_push_tag () {
tag_args=$2
test_expect_success "force pushing required to update $tag_type_description" "
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child1 &&
mk_child testrepo child2 &&
(
@@ -1016,7 +1129,7 @@ test_force_fetch_tag () {
tag_args=$2
test_expect_success "fetch will not clobber an existing $tag_type_description without --force" "
- mk_test testrepo heads/master &&
+ mk_test testrepo heads/main &&
mk_child testrepo child1 &&
mk_child testrepo child2 &&
(
@@ -1039,12 +1152,12 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'"
test_expect_success 'push --porcelain' '
mk_empty testrepo &&
echo >.git/foo "To testrepo" &&
- echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
+ echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" &&
echo >>.git/foo "Done" &&
- git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
+ git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main &&
(
cd testrepo &&
- echo "$the_commit commit refs/remotes/origin/master" >expect &&
+ echo "$the_commit commit refs/remotes/origin/main" >expect &&
git for-each-ref refs/remotes/origin >actual &&
test_cmp expect actual
) &&
@@ -1053,52 +1166,52 @@ test_expect_success 'push --porcelain' '
test_expect_success 'push --porcelain bad url' '
mk_empty testrepo &&
- test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
+ test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main &&
! grep -q Done .git/bar
'
test_expect_success 'push --porcelain rejected' '
mk_empty testrepo &&
- git push testrepo refs/heads/master:refs/remotes/origin/master &&
+ git push testrepo refs/heads/main:refs/remotes/origin/main &&
(cd testrepo &&
- git reset --hard origin/master^ &&
+ git reset --hard origin/main^ &&
git config receive.denyCurrentBranch true) &&
echo >.git/foo "To testrepo" &&
- echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
+ echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" &&
echo >>.git/foo "Done" &&
- test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
+ test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main &&
test_cmp .git/foo .git/bar
'
test_expect_success 'push --porcelain --dry-run rejected' '
mk_empty testrepo &&
- git push testrepo refs/heads/master:refs/remotes/origin/master &&
+ git push testrepo refs/heads/main:refs/remotes/origin/main &&
(cd testrepo &&
- git reset --hard origin/master &&
+ git reset --hard origin/main &&
git config receive.denyCurrentBranch true) &&
echo >.git/foo "To testrepo" &&
- echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
+ echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" &&
echo >>.git/foo "Done" &&
- test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
+ test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main &&
test_cmp .git/foo .git/bar
'
test_expect_success 'push --prune' '
- mk_test testrepo heads/master heads/second heads/foo heads/bar &&
+ mk_test testrepo heads/main heads/second heads/foo heads/bar &&
git push --prune testrepo : &&
- check_push_result testrepo $the_commit heads/master &&
+ check_push_result testrepo $the_commit heads/main &&
check_push_result testrepo $the_first_commit heads/second &&
! check_push_result testrepo $the_first_commit heads/foo heads/bar
'
test_expect_success 'push --prune refspec' '
- mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
+ mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar &&
git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
- check_push_result testrepo $the_commit tmp/master &&
+ check_push_result testrepo $the_commit tmp/main &&
check_push_result testrepo $the_first_commit tmp/second &&
! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
'
@@ -1106,18 +1219,18 @@ test_expect_success 'push --prune refspec' '
for configsection in transfer receive
do
test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
- mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
+ mk_test testrepo heads/main hidden/one hidden/two hidden/three &&
(
cd testrepo &&
git config $configsection.hiderefs refs/hidden
) &&
# push to unhidden ref succeeds normally
- git push testrepo master:refs/heads/master &&
- check_push_result testrepo $the_commit heads/master &&
+ git push testrepo main:refs/heads/main &&
+ check_push_result testrepo $the_commit heads/main &&
# push to update a hidden ref should fail
- test_must_fail git push testrepo master:refs/hidden/one &&
+ test_must_fail git push testrepo main:refs/hidden/one &&
check_push_result testrepo $the_first_commit hidden/one &&
# push to delete a hidden ref should fail
@@ -1131,8 +1244,8 @@ do
done
test_expect_success 'fetch exact SHA1' '
- mk_test testrepo heads/master hidden/one &&
- git push testrepo master:refs/hidden/one &&
+ mk_test testrepo heads/main hidden/one &&
+ git push testrepo main:refs/hidden/one &&
(
cd testrepo &&
git config transfer.hiderefs refs/hidden
@@ -1154,7 +1267,7 @@ test_expect_success 'fetch exact SHA1' '
# fetching the hidden object should fail by default
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
- test_i18ngrep "Server does not allow request for unadvertised object" err &&
+ test_grep "Server does not allow request for unadvertised object" err &&
test_must_fail git rev-parse --verify refs/heads/copy &&
# the server side can allow it to succeed
@@ -1163,7 +1276,7 @@ test_expect_success 'fetch exact SHA1' '
git config uploadpack.allowtipsha1inwant true
) &&
- git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
+ git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra &&
cat >expect <<-EOF &&
$the_commit
$the_first_commit
@@ -1177,8 +1290,8 @@ test_expect_success 'fetch exact SHA1' '
'
test_expect_success 'fetch exact SHA1 in protocol v2' '
- mk_test testrepo heads/master hidden/one &&
- git push testrepo master:refs/hidden/one &&
+ mk_test testrepo heads/main hidden/one &&
+ git push testrepo main:refs/hidden/one &&
git -C testrepo config transfer.hiderefs refs/hidden &&
check_push_result testrepo $the_commit hidden/one &&
@@ -1254,32 +1367,32 @@ do
git cat-file commit $SHA1_2 &&
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
git fetch ../testrepo/.git $SHA1_3 2>err &&
- test_i18ngrep "remote error:.*not our ref.*$SHA1_3\$" err
+ # ideally we would insist this be on a "remote error:"
+ # line, but it is racy; see the commit message
+ test_grep "not our ref.*$SHA1_3\$" err
)
'
done
test_expect_success 'fetch follows tags by default' '
- mk_test testrepo heads/master &&
- rm -fr src dst &&
+ mk_test testrepo heads/main &&
+ test_when_finished "rm -rf src" &&
git init src &&
(
cd src &&
- git pull ../testrepo master &&
+ git pull ../testrepo main &&
git tag -m "annotated" tag &&
git for-each-ref >tmp1 &&
- (
- cat tmp1
- sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
- ) |
+ sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
sort -k 3 >../expect
) &&
+ test_when_finished "rm -rf dst" &&
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 config branch.main.remote origin &&
+ git config branch.main.merge refs/heads/main &&
git pull &&
git for-each-ref >../actual
) &&
@@ -1294,78 +1407,81 @@ test_expect_success 'peeled advertisements are not considered ref tips' '
oid=$(git -C testrepo rev-parse mytag^{commit}) &&
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
git fetch testrepo $oid 2>err &&
- test_i18ngrep "Server does not allow request for unadvertised object" err
+ test_grep "Server does not allow request for unadvertised object" err
'
test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
- mk_test testrepo heads/master &&
- rm -fr src dst &&
+ mk_test testrepo heads/main &&
+ test_when_finished "rm -rf src" &&
git init src &&
+ test_when_finished "rm -rf dst" &&
git init --bare dst &&
(
cd src &&
- git pull ../testrepo master &&
+ git pull ../testrepo main &&
git branch next &&
git config remote.dst.url ../dst &&
git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
- git push dst master &&
- git show-ref refs/heads/master |
+ git push dst main &&
+ git show-ref refs/heads/main |
sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
) &&
(
cd dst &&
test_must_fail git show-ref refs/heads/next &&
- test_must_fail git show-ref refs/heads/master &&
- git show-ref refs/remotes/src/master >actual
+ test_must_fail git show-ref refs/heads/main &&
+ git show-ref refs/remotes/src/main >actual
) &&
test_cmp dst/expect dst/actual
'
test_expect_success 'with no remote.$name.push, it is not used as refmap' '
- mk_test testrepo heads/master &&
- rm -fr src dst &&
+ mk_test testrepo heads/main &&
+ test_when_finished "rm -rf src" &&
git init src &&
+ test_when_finished "rm -rf dst" &&
git init --bare dst &&
(
cd src &&
- git pull ../testrepo master &&
+ git pull ../testrepo main &&
git branch next &&
git config remote.dst.url ../dst &&
git config push.default matching &&
- git push dst master &&
- git show-ref refs/heads/master >../dst/expect
+ git push dst main &&
+ git show-ref refs/heads/main >../dst/expect
) &&
(
cd dst &&
test_must_fail git show-ref refs/heads/next &&
- git show-ref refs/heads/master >actual
+ git show-ref refs/heads/main >actual
) &&
test_cmp dst/expect dst/actual
'
test_expect_success 'with no remote.$name.push, upstream mapping is used' '
- mk_test testrepo heads/master &&
- rm -fr src dst &&
+ mk_test testrepo heads/main &&
+ test_when_finished "rm -rf src" &&
git init src &&
+ test_when_finished "rm -rf dst" &&
git init --bare dst &&
(
cd src &&
- git pull ../testrepo master &&
+ git pull ../testrepo main &&
git branch next &&
git config remote.dst.url ../dst &&
git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
git config push.default upstream &&
- git config branch.master.merge refs/heads/trunk &&
- git config branch.master.remote dst &&
+ git config branch.main.merge refs/heads/trunk &&
+ git config branch.main.remote dst &&
- git push dst master &&
- git show-ref refs/heads/master |
- sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
+ git push dst main &&
+ git show-ref refs/heads/main |
+ sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect
) &&
(
cd dst &&
- test_must_fail git show-ref refs/heads/master &&
+ test_must_fail git show-ref refs/heads/main &&
test_must_fail git show-ref refs/heads/next &&
git show-ref refs/heads/trunk >actual
) &&
@@ -1373,20 +1489,21 @@ test_expect_success 'with no remote.$name.push, upstream mapping is used' '
'
test_expect_success 'push does not follow tags by default' '
- mk_test testrepo heads/master &&
- rm -fr src dst &&
+ mk_test testrepo heads/main &&
+ test_when_finished "rm -rf src" &&
git init src &&
+ test_when_finished "rm -rf dst" &&
git init --bare dst &&
(
cd src &&
- git pull ../testrepo master &&
+ git pull ../testrepo main &&
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
+ git checkout main &&
+ git for-each-ref refs/heads/main >../expect &&
+ git push ../dst main
) &&
(
cd dst &&
@@ -1396,20 +1513,21 @@ test_expect_success 'push does not follow tags by default' '
'
test_expect_success 'push --follow-tags only pushes relevant tags' '
- mk_test testrepo heads/master &&
- rm -fr src dst &&
+ mk_test testrepo heads/main &&
+ test_when_finished "rm -rf src" &&
git init src &&
+ test_when_finished "rm -rf dst" &&
git init --bare dst &&
(
cd src &&
- git pull ../testrepo master &&
+ git pull ../testrepo main &&
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-tags ../dst master
+ git checkout main &&
+ git for-each-ref refs/heads/main refs/tags/tag >../expect &&
+ git push --follow-tags ../dst main
) &&
(
cd dst &&
@@ -1427,18 +1545,18 @@ EOF
git commit -am initial &&
git init no-thin &&
git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
- git push no-thin/.git refs/heads/master:refs/heads/foo &&
+ git push no-thin/.git refs/heads/main:refs/heads/foo &&
echo modified >> path1 &&
git commit -am modified &&
git repack -adf &&
rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
- git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
+ git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo
'
test_expect_success 'pushing a tag pushes the tagged object' '
- rm -rf dst.git &&
blob=$(echo unreferenced | git hash-object -w --stdin) &&
git tag -m foo tag-of-blob $blob &&
+ test_when_finished "rm -rf dst.git" &&
git init --bare dst.git &&
git push dst.git tag-of-blob &&
# the receiving index-pack should have noticed
@@ -1449,25 +1567,25 @@ test_expect_success 'pushing a tag pushes the tagged object' '
'
test_expect_success 'push into bare respects core.logallrefupdates' '
- rm -rf dst.git &&
+ test_when_finished "rm -rf dst.git" &&
git init --bare dst.git &&
git -C dst.git config core.logallrefupdates true &&
# double push to test both with and without
# the actual pack transfer
- git push dst.git master:one &&
+ git push dst.git main:one &&
echo "one@{0} push" >expect &&
git -C dst.git log -g --format="%gd %gs" one >actual &&
test_cmp expect actual &&
- git push dst.git master:two &&
+ git push dst.git main:two &&
echo "two@{0} push" >expect &&
git -C dst.git log -g --format="%gd %gs" two >actual &&
test_cmp expect actual
'
test_expect_success 'fetch into bare respects core.logallrefupdates' '
- rm -rf dst.git &&
+ test_when_finished "rm -rf dst.git" &&
git init --bare dst.git &&
(
cd dst.git &&
@@ -1475,20 +1593,21 @@ test_expect_success 'fetch into bare respects core.logallrefupdates' '
# as above, we double-fetch to test both
# with and without pack transfer
- git fetch .. master:one &&
- echo "one@{0} fetch .. master:one: storing head" >expect &&
+ git fetch .. main:one &&
+ echo "one@{0} fetch .. main:one: storing head" >expect &&
git log -g --format="%gd %gs" one >actual &&
test_cmp expect actual &&
- git fetch .. master:two &&
- echo "two@{0} fetch .. master:two: storing head" >expect &&
+ git fetch .. main:two &&
+ echo "two@{0} fetch .. main:two: storing head" >expect &&
git log -g --format="%gd %gs" two >actual &&
test_cmp expect actual
)
'
test_expect_success 'receive.denyCurrentBranch = updateInstead' '
- git push testrepo master &&
+ mk_empty testrepo &&
+ git push testrepo main &&
(
cd testrepo &&
git reset --hard &&
@@ -1497,7 +1616,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
test_commit third path2 &&
# Try pushing into a repository with pristine working tree
- git push testrepo master &&
+ git push testrepo main &&
(
cd testrepo &&
git update-index -q --refresh &&
@@ -1514,7 +1633,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
test-tool chmtime +100 path1
) &&
- git push testrepo master &&
+ git push testrepo main &&
(
cd testrepo &&
git update-index -q --refresh &&
@@ -1534,7 +1653,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
cd testrepo &&
echo changed >path1
) &&
- test_must_fail git push testrepo master &&
+ test_must_fail git push testrepo main &&
(
cd testrepo &&
test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
@@ -1548,7 +1667,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
echo changed >path1 &&
git add path1
) &&
- test_must_fail git push testrepo master &&
+ test_must_fail git push testrepo main &&
(
cd testrepo &&
test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
@@ -1565,7 +1684,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
git reset --hard &&
echo changed >path3
) &&
- test_must_fail git push testrepo master &&
+ test_must_fail git push testrepo main &&
(
cd testrepo &&
test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
@@ -1581,7 +1700,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
echo fifth >path3 &&
git add path3
) &&
- test_must_fail git push testrepo master &&
+ test_must_fail git push testrepo main &&
(
cd testrepo &&
test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
@@ -1590,51 +1709,48 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
) &&
# (5) push into void
- rm -fr void &&
+ test_when_finished "rm -rf void" &&
git init void &&
(
cd void &&
git config receive.denyCurrentBranch updateInstead
) &&
- git push void master &&
+ git push void main &&
(
cd void &&
- test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
+ test $(git -C .. rev-parse main) = $(git rev-parse HEAD) &&
git diff --quiet &&
git diff --cached --quiet
) &&
# (6) updateInstead intervened by fast-forward check
- test_must_fail git push void master^:master &&
- test $(git -C void rev-parse HEAD) = $(git rev-parse master) &&
+ test_must_fail git push void main^:main &&
+ test $(git -C void rev-parse HEAD) = $(git rev-parse main) &&
git -C void diff --quiet &&
git -C void diff --cached --quiet
'
test_expect_success 'updateInstead with push-to-checkout hook' '
- rm -fr testrepo &&
+ test_when_finished "rm -rf testrepo" &&
git init testrepo &&
- (
- cd testrepo &&
- git pull .. master &&
- git reset --hard HEAD^^ &&
- git tag initial &&
- git config receive.denyCurrentBranch updateInstead &&
- write_script .git/hooks/push-to-checkout <<-\EOF
- echo >&2 updating from $(git rev-parse HEAD)
- echo >&2 updating to "$1"
-
- git update-index -q --refresh &&
- git read-tree -u -m HEAD "$1" || {
- status=$?
- echo >&2 read-tree failed
- exit $status
- }
- EOF
- ) &&
+ git -C testrepo pull .. main &&
+ git -C testrepo reset --hard HEAD^^ &&
+ git -C testrepo tag initial &&
+ git -C testrepo config receive.denyCurrentBranch updateInstead &&
+ test_hook -C testrepo push-to-checkout <<-\EOF &&
+ echo >&2 updating from $(git rev-parse HEAD)
+ echo >&2 updating to "$1"
+
+ git update-index -q --refresh &&
+ git read-tree -u -m HEAD "$1" || {
+ status=$?
+ echo >&2 read-tree failed
+ exit $status
+ }
+ EOF
# Try pushing into a pristine
- git push testrepo master &&
+ git push testrepo main &&
(
cd testrepo &&
git diff --quiet &&
@@ -1648,7 +1764,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' '
git reset --hard initial &&
echo conflicting >path2
) &&
- test_must_fail git push testrepo master &&
+ test_must_fail git push testrepo main &&
(
cd testrepo &&
test $(git rev-parse initial) = $(git rev-parse HEAD) &&
@@ -1664,7 +1780,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' '
echo irrelevant >path5 &&
git add path5
) &&
- git push testrepo master &&
+ git push testrepo main &&
(
cd testrepo &&
test "$(cat path1)" = unrelated &&
@@ -1674,37 +1790,34 @@ test_expect_success 'updateInstead with push-to-checkout hook' '
) &&
# push into void
- rm -fr void &&
+ test_when_finished "rm -rf void" &&
git init void &&
- (
- cd void &&
- git config receive.denyCurrentBranch updateInstead &&
- write_script .git/hooks/push-to-checkout <<-\EOF
- if git rev-parse --quiet --verify HEAD
- then
- has_head=yes
- echo >&2 updating from $(git rev-parse HEAD)
- else
- has_head=no
- echo >&2 pushing into void
- fi
- echo >&2 updating to "$1"
-
- git update-index -q --refresh &&
- case "$has_head" in
- yes)
- git read-tree -u -m HEAD "$1" ;;
- no)
- git read-tree -u -m "$1" ;;
- esac || {
- status=$?
- echo >&2 read-tree failed
- exit $status
- }
- EOF
- ) &&
-
- git push void master &&
+ git -C void config receive.denyCurrentBranch updateInstead &&
+ test_hook -C void push-to-checkout <<-\EOF &&
+ if git rev-parse --quiet --verify HEAD
+ then
+ has_head=yes
+ echo >&2 updating from $(git rev-parse HEAD)
+ else
+ has_head=no
+ echo >&2 pushing into void
+ fi
+ echo >&2 updating to "$1"
+
+ git update-index -q --refresh &&
+ case "$has_head" in
+ yes)
+ git read-tree -u -m HEAD "$1" ;;
+ no)
+ git read-tree -u -m "$1" ;;
+ esac || {
+ status=$?
+ echo >&2 read-tree failed
+ exit $status
+ }
+ EOF
+
+ git push void main &&
(
cd void &&
git diff --quiet &&
@@ -1721,7 +1834,68 @@ test_expect_success 'denyCurrentBranch and worktrees' '
test_must_fail git -C cloned push origin HEAD:new-wt &&
test_config receive.denyCurrentBranch updateInstead &&
git -C cloned push origin HEAD:new-wt &&
+ test_path_exists new-wt/first.t &&
test_must_fail git -C cloned push --delete origin new-wt
'
+test_expect_success 'denyCurrentBranch and bare repository worktrees' '
+ test_when_finished "rm -fr bare.git" &&
+ git clone --bare . bare.git &&
+ git -C bare.git worktree add wt &&
+ test_commit grape &&
+ git -C bare.git config receive.denyCurrentBranch refuse &&
+ test_must_fail git push bare.git HEAD:wt &&
+ git -C bare.git config receive.denyCurrentBranch updateInstead &&
+ git push bare.git HEAD:wt &&
+ test_path_exists bare.git/wt/grape.t &&
+ test_must_fail git push --delete bare.git wt
+'
+
+test_expect_success 'refuse fetch to current branch of worktree' '
+ test_when_finished "git worktree remove --force wt && git branch -D wt" &&
+ git worktree add wt &&
+ test_commit apple &&
+ test_must_fail git fetch . HEAD:wt &&
+ git fetch -u . HEAD:wt
+'
+
+test_expect_success 'refuse fetch to current branch of bare repository worktree' '
+ test_when_finished "rm -fr bare.git" &&
+ git clone --bare . bare.git &&
+ git -C bare.git worktree add wt &&
+ test_commit banana &&
+ test_must_fail git -C bare.git fetch .. HEAD:wt &&
+ git -C bare.git fetch -u .. HEAD:wt
+'
+
+test_expect_success 'refuse to push a hidden ref, and make sure do not pollute the repository' '
+ mk_empty testrepo &&
+ git -C testrepo config receive.hiderefs refs/hidden &&
+ git -C testrepo config receive.unpackLimit 1 &&
+ test_must_fail git push testrepo HEAD:refs/hidden/foo &&
+ test_dir_is_empty testrepo/.git/objects/pack
+'
+
+test_expect_success 'push with config push.useBitmaps' '
+ mk_test testrepo heads/main &&
+ git checkout main &&
+ test_unconfig push.useBitmaps &&
+ GIT_TRACE2_EVENT="$PWD/default" \
+ git push --quiet testrepo main:test &&
+ test_subcommand git pack-objects --all-progress-implied --revs --stdout \
+ --thin --delta-base-offset -q <default &&
+
+ test_config push.useBitmaps true &&
+ GIT_TRACE2_EVENT="$PWD/true" \
+ git push --quiet testrepo main:test2 &&
+ test_subcommand git pack-objects --all-progress-implied --revs --stdout \
+ --thin --delta-base-offset -q <true &&
+
+ test_config push.useBitmaps false &&
+ GIT_TRACE2_EVENT="$PWD/false" \
+ git push --quiet testrepo main:test3 &&
+ test_subcommand git pack-objects --all-progress-implied --revs --stdout \
+ --thin --delta-base-offset -q --no-use-bitmap-index <false
+'
+
test_done