summaryrefslogtreecommitdiff
path: root/t/t3200-branch.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t3200-branch.sh')
-rwxr-xr-xt/t3200-branch.sh53
1 files changed, 51 insertions, 2 deletions
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 7a0ff75..9723c28 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -886,6 +886,41 @@ test_expect_success 'branch from tag w/--track causes failure' '
test_must_fail git branch --track my11 foobar
'
+test_expect_success 'simple tracking works when remote branch name matches' '
+ test_when_finished "rm -rf otherserver" &&
+ git init otherserver &&
+ test_commit -C otherserver my_commit 1 &&
+ git -C otherserver branch feature &&
+ test_config branch.autosetupmerge simple &&
+ test_config remote.otherserver.url otherserver &&
+ test_config remote.otherserver.fetch refs/heads/*:refs/remotes/otherserver/* &&
+ git fetch otherserver &&
+ git branch feature otherserver/feature &&
+ test_cmp_config otherserver branch.feature.remote &&
+ test_cmp_config refs/heads/feature branch.feature.merge
+'
+
+test_expect_success 'simple tracking skips when remote branch name does not match' '
+ test_config branch.autosetupmerge simple &&
+ test_config remote.local.url . &&
+ test_config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+ git fetch local &&
+ git branch my-other local/main &&
+ test_cmp_config "" --default "" branch.my-other.remote &&
+ test_cmp_config "" --default "" branch.my-other.merge
+'
+
+test_expect_success 'simple tracking skips when remote ref is not a branch' '
+ test_config branch.autosetupmerge simple &&
+ test_config remote.localtags.url . &&
+ test_config remote.localtags.fetch refs/tags/*:refs/remotes/localtags/* &&
+ git tag mytag12 main &&
+ git fetch localtags &&
+ git branch mytag12 localtags/mytag12 &&
+ test_cmp_config "" --default "" branch.mytag12.remote &&
+ test_cmp_config "" --default "" branch.mytag12.merge
+'
+
test_expect_success '--set-upstream-to fails on multiple branches' '
echo "fatal: too many arguments to set new upstream" >expect &&
test_must_fail git branch --set-upstream-to main a b c 2>err &&
@@ -1039,13 +1074,27 @@ test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates
git rev-parse --verify gamma@{0}
'
-test_expect_success 'avoid ambiguous track' '
+test_expect_success 'avoid ambiguous track and advise' '
git config branch.autosetupmerge true &&
git config remote.ambi1.url lalala &&
git config remote.ambi1.fetch refs/heads/lalala:refs/heads/main &&
git config remote.ambi2.url lilili &&
git config remote.ambi2.fetch refs/heads/lilili:refs/heads/main &&
- test_must_fail git branch all1 main &&
+ cat <<-EOF >expected &&
+ fatal: not tracking: ambiguous information for ref '\''refs/heads/main'\''
+ hint: There are multiple remotes whose fetch refspecs map to the remote
+ hint: tracking ref '\''refs/heads/main'\'':
+ hint: ambi1
+ hint: ambi2
+ hint: ''
+ hint: This is typically a configuration error.
+ hint: ''
+ hint: To support setting up tracking branches, ensure that
+ hint: different remotes'\'' fetch refspecs map into different
+ hint: tracking namespaces.
+ EOF
+ test_must_fail git branch all1 main 2>actual &&
+ test_cmp expected actual &&
test -z "$(git config branch.all1.merge)"
'