summaryrefslogtreecommitdiff
path: root/t/t5553-set-upstream.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t5553-set-upstream.sh')
-rwxr-xr-xt/t5553-set-upstream.sh121
1 files changed, 73 insertions, 48 deletions
diff --git a/t/t5553-set-upstream.sh b/t/t5553-set-upstream.sh
index 81975ad..4805016 100755
--- a/t/t5553-set-upstream.sh
+++ b/t/t5553-set-upstream.sh
@@ -1,6 +1,9 @@
#!/bin/sh
test_description='"git fetch/pull --set-upstream" basic tests.'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./test-lib.sh
check_config () {
@@ -32,9 +35,9 @@ test_expect_success 'setup bare parent fetch' '
git remote add upstream parent
'
-test_expect_success 'setup commit on master and other fetch' '
+test_expect_success 'setup commit on main and other fetch' '
test_commit one &&
- git push upstream master &&
+ git push upstream main &&
git checkout -b other &&
test_commit two &&
git push upstream other
@@ -43,51 +46,62 @@ test_expect_success 'setup commit on master and other fetch' '
# tests for fetch --set-upstream
test_expect_success 'fetch --set-upstream does not set upstream w/o branch' '
- clear_config master other &&
- git checkout master &&
+ clear_config main other &&
+ git checkout main &&
git fetch --set-upstream upstream &&
- check_config_missing master &&
+ check_config_missing main &&
check_config_missing other
'
-test_expect_success 'fetch --set-upstream upstream master sets branch master but not other' '
- clear_config master other &&
- git fetch --set-upstream upstream master &&
- check_config master upstream refs/heads/master &&
+test_expect_success 'fetch --set-upstream upstream main sets branch main but not other' '
+ clear_config main other &&
+ git fetch --set-upstream upstream main &&
+ check_config main upstream refs/heads/main &&
check_config_missing other
'
test_expect_success 'fetch --set-upstream upstream other sets branch other' '
- clear_config master other &&
+ clear_config main other &&
git fetch --set-upstream upstream other &&
- check_config master upstream refs/heads/other &&
+ check_config main upstream refs/heads/other &&
check_config_missing other
'
-test_expect_success 'fetch --set-upstream master:other does not set the branch other2' '
+test_expect_success 'fetch --set-upstream main:other does not set the branch other2' '
clear_config other2 &&
- git fetch --set-upstream upstream master:other2 &&
+ git fetch --set-upstream upstream main:other2 &&
check_config_missing other2
'
test_expect_success 'fetch --set-upstream http://nosuchdomain.example.com fails with invalid url' '
- # master explicitly not cleared, we check that it is not touched from previous value
+ # main explicitly not cleared, we check that it is not touched from previous value
clear_config other other2 &&
test_must_fail git fetch --set-upstream http://nosuchdomain.example.com &&
- check_config master upstream refs/heads/other &&
+ check_config main upstream refs/heads/other &&
check_config_missing other &&
check_config_missing other2
'
test_expect_success 'fetch --set-upstream with valid URL sets upstream to URL' '
clear_config other other2 &&
- url="file://'"$PWD"'" &&
+ url="file://$PWD" &&
git fetch --set-upstream "$url" &&
- check_config master "$url" HEAD &&
+ check_config main "$url" HEAD &&
check_config_missing other &&
check_config_missing other2
'
+test_expect_success 'fetch --set-upstream with a detached HEAD' '
+ git checkout HEAD^0 &&
+ test_when_finished "git checkout -" &&
+ cat >expect <<-\EOF &&
+ warning: could not set upstream of HEAD to '"'"'main'"'"' from '"'"'upstream'"'"' when it does not point to any branch.
+ EOF
+ git fetch --set-upstream upstream main 2>actual.raw &&
+ grep ^warning: actual.raw >actual &&
+ test_cmp expect actual
+'
+
# tests for pull --set-upstream
test_expect_success 'setup bare parent pull' '
@@ -96,83 +110,94 @@ test_expect_success 'setup bare parent pull' '
git remote add upstream parent
'
-test_expect_success 'setup commit on master and other pull' '
+test_expect_success 'setup commit on main and other pull' '
test_commit three &&
- git push --tags upstream master &&
+ git push --tags upstream main &&
test_commit four &&
git push upstream other
'
-test_expect_success 'pull --set-upstream upstream master sets branch master but not other' '
- clear_config master other &&
- git pull --set-upstream upstream master &&
- check_config master upstream refs/heads/master &&
+test_expect_success 'pull --set-upstream upstream main sets branch main but not other' '
+ clear_config main other &&
+ git pull --no-rebase --set-upstream upstream main &&
+ check_config main upstream refs/heads/main &&
check_config_missing other
'
-test_expect_success 'pull --set-upstream master:other2 does not set the branch other2' '
+test_expect_success 'pull --set-upstream main:other2 does not set the branch other2' '
clear_config other2 &&
- git pull --set-upstream upstream master:other2 &&
+ git pull --no-rebase --set-upstream upstream main:other2 &&
check_config_missing other2
'
-test_expect_success 'pull --set-upstream upstream other sets branch master' '
- clear_config master other &&
- git pull --set-upstream upstream other &&
- check_config master upstream refs/heads/other &&
+test_expect_success 'pull --set-upstream upstream other sets branch main' '
+ clear_config main other &&
+ git pull --no-rebase --set-upstream upstream other &&
+ check_config main upstream refs/heads/other &&
check_config_missing other
'
test_expect_success 'pull --set-upstream upstream tag does not set the tag' '
clear_config three &&
- git pull --tags --set-upstream upstream three &&
+ git pull --no-rebase --tags --set-upstream upstream three &&
check_config_missing three
'
test_expect_success 'pull --set-upstream http://nosuchdomain.example.com fails with invalid url' '
- # master explicitly not cleared, we check that it is not touched from previous value
+ # main explicitly not cleared, we check that it is not touched from previous value
clear_config other other2 three &&
test_must_fail git pull --set-upstream http://nosuchdomain.example.com &&
- check_config master upstream refs/heads/other &&
+ check_config main upstream refs/heads/other &&
check_config_missing other &&
check_config_missing other2 &&
check_config_missing three
'
test_expect_success 'pull --set-upstream upstream HEAD sets branch HEAD' '
- clear_config master other &&
- git pull --set-upstream upstream HEAD &&
- check_config master upstream HEAD &&
+ clear_config main other &&
+ git pull --no-rebase --set-upstream upstream HEAD &&
+ check_config main upstream HEAD &&
git checkout other &&
- git pull --set-upstream upstream HEAD &&
+ git pull --no-rebase --set-upstream upstream HEAD &&
check_config other upstream HEAD
'
test_expect_success 'pull --set-upstream upstream with more than one branch does nothing' '
- clear_config master three &&
- git pull --set-upstream upstream master three &&
- check_config_missing master &&
+ clear_config main three &&
+ git pull --no-rebase --set-upstream upstream main three &&
+ check_config_missing main &&
check_config_missing three
'
test_expect_success 'pull --set-upstream with valid URL sets upstream to URL' '
- clear_config master other other2 &&
- git checkout master &&
- url="file://'"$PWD"'" &&
+ clear_config main other other2 &&
+ git checkout main &&
+ url="file://$PWD" &&
git pull --set-upstream "$url" &&
- check_config master "$url" HEAD &&
+ check_config main "$url" HEAD &&
check_config_missing other &&
check_config_missing other2
'
test_expect_success 'pull --set-upstream with valid URL and branch sets branch' '
- clear_config master other other2 &&
- git checkout master &&
- url="file://'"$PWD"'" &&
- git pull --set-upstream "$url" master &&
- check_config master "$url" refs/heads/master &&
+ clear_config main other other2 &&
+ git checkout main &&
+ url="file://$PWD" &&
+ git pull --set-upstream "$url" main &&
+ check_config main "$url" refs/heads/main &&
check_config_missing other &&
check_config_missing other2
'
+test_expect_success 'pull --set-upstream with a detached HEAD' '
+ git checkout HEAD^0 &&
+ test_when_finished "git checkout -" &&
+ cat >expect <<-\EOF &&
+ warning: could not set upstream of HEAD to '"'"'main'"'"' from '"'"'upstream'"'"' when it does not point to any branch.
+ EOF
+ git pull --no-rebase --set-upstream upstream main 2>actual.raw &&
+ grep ^warning: actual.raw >actual &&
+ test_cmp expect actual
+'
+
test_done