@@ -1022,6 +1022,53 @@ test_expect_success '--set-upstream-to fails on a missing dst branch' '
10221022 test_cmp expect err
10231023'
10241024
1025+ test_expect_success ' --set-upstream-to suggests <remote>/<branch> on slip' '
1026+ test_when_finished "git remote remove upstream-remote" &&
1027+ test_config_global protocol.file.allow always &&
1028+ git init --bare slip-remote.git &&
1029+ git remote add upstream-remote slip-remote.git &&
1030+ git push upstream-remote main:slip-feature &&
1031+ git fetch upstream-remote &&
1032+ test_must_fail git rev-parse --verify refs/heads/slip-feature &&
1033+ test_must_fail git branch --set-upstream-to upstream-remote slip-feature 2>err &&
1034+ test_grep "takes a single <remote>/<branch> argument" err &&
1035+ test_grep "hint: Did you mean to use: git branch --set-upstream-to=upstream-remote/slip-feature?" err &&
1036+ test_must_fail git -c advice.setUpstreamFailure=false \
1037+ branch --set-upstream-to upstream-remote slip-feature 2>err &&
1038+ test_grep ! "Did you mean" err
1039+ '
1040+
1041+ test_expect_success ' --set-upstream-to does not suggest when no matching remote ref' '
1042+ test_when_finished "git remote remove upstream-remote" &&
1043+ git init --bare slip-remote2.git &&
1044+ git remote add upstream-remote slip-remote2.git &&
1045+ test_must_fail git branch --set-upstream-to upstream-remote no-such-branch 2>err &&
1046+ test_grep "branch ${SQ}no-such-branch${SQ} does not exist" err &&
1047+ test_grep ! "Did you mean" err
1048+ '
1049+
1050+ test_expect_success ' --set-upstream-to to a local branch is not mistaken for a slip' '
1051+ git branch slip-local-upstream &&
1052+ git branch slip-local-target &&
1053+ git branch --set-upstream-to=slip-local-upstream slip-local-target 2>err &&
1054+ test_grep ! "Did you mean" err &&
1055+ echo refs/heads/slip-local-upstream >expect &&
1056+ git config branch.slip-local-target.merge >actual &&
1057+ test_cmp expect actual
1058+ '
1059+
1060+ test_expect_success ' --set-upstream-to slip suggestion keeps a slashed branch name' '
1061+ test_when_finished "git remote remove upstream-remote" &&
1062+ test_config_global protocol.file.allow always &&
1063+ git init --bare slip-remote3.git &&
1064+ git remote add upstream-remote slip-remote3.git &&
1065+ git push upstream-remote main:slip/feature &&
1066+ git fetch upstream-remote &&
1067+ test_must_fail git rev-parse --verify refs/heads/slip/feature &&
1068+ test_must_fail git branch --set-upstream-to upstream-remote slip/feature 2>err &&
1069+ test_grep "hint: Did you mean to use: git branch --set-upstream-to=upstream-remote/slip/feature?" err
1070+ '
1071+
10251072test_expect_success ' --set-upstream-to fails on a missing src branch' '
10261073 test_must_fail git branch --set-upstream-to does-not-exist main 2>err &&
10271074 test_grep "the requested upstream branch ' " '" ' does-not-exist' " '" ' does not exist" err
0 commit comments