builtin/branch: stop supporting the "--set-upstream" option

The '--set-upstream' option of branch was deprecated in b347d06b ("branch: deprecate --set-upstream and show help if we detect possible mistaken use", 2012-08-30) and has been planned for removal ever since. In order to prevent "--set-upstream" on a command line from being taken as an abbreviated form of "--set-upstream-to", explicitly catch "--set-upstream" option and die, instead of just removing it from the list of options. Before this change, an attempt to use "--set-upstream" resulted in: $ git branch * master $ git branch --set-upstream origin/master The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to Branch origin/master set up to track local branch master. $ echo $? 0 $ git branch * master origin/master With this change, the behaviour becomes like this: $ git branch * master $ git branch --set-upstream origin/master fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead. $ echo $? 128 $ git branch * master Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kaartic Sivaraam committed Aug 17, 2017 at 08:24 UTC 52668846ea2d41ffbd87cda7cb8e492dea9f2c4d
4 files changed +14 -84
Documentation/git-branch.txt
+2 -4
@@ -195,10 +195,8 @@ start-point is either a local or remote-tracking branch.
195 branch.autoSetupMerge configuration variable is true.
196
197 --set-upstream::
198 - If specified branch does not exist yet or if `--force` has been
199 - given, acts exactly like `--track`. Otherwise sets up configuration
200 - like `--track` would when creating the branch, except that where
201 - branch points to is not changed.
198 + As this option had confusing syntax, it is no longer supported.
199 + Please use `--track` or `--set-upstream-to` instead.
200
201 -u <upstream>::
202 --set-upstream-to=<upstream>::
builtin/branch.c
+3 -22
@@ -561,8 +561,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
561 OPT__QUIET(&quiet, N_("suppress informational messages")),
562 OPT_SET_INT('t', "track", &track, N_("set up tracking mode (see git-pull(1))"),
563 BRANCH_TRACK_EXPLICIT),
564 - OPT_SET_INT( 0, "set-upstream", &track, N_("change upstream info"),
565 - BRANCH_TRACK_OVERRIDE),
564 + { OPTION_SET_INT, 0, "set-upstream", &track, NULL, N_("do not use"),
565 + PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, BRANCH_TRACK_OVERRIDE },
566 OPT_STRING('u', "set-upstream-to", &new_upstream, N_("upstream"), N_("change the upstream info")),
567 OPT_BOOL(0, "unset-upstream", &unset_upstream, N_("Unset the upstream info")),
568 OPT__COLOR(&branch_use_color, N_("use colored output")),
@@ -759,8 +759,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
759 strbuf_release(&buf);
760 } else if (argc > 0 && argc <= 2) {
761 struct branch *branch = branch_get(argv[0]);
762 - int branch_existed = 0, remote_tracking = 0;
763 - struct strbuf buf = STRBUF_INIT;
762
763 if (!strcmp(argv[0], "HEAD"))
764 die(_("it does not make sense to create 'HEAD' manually"));
@@ -772,28 +770,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
770 die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
771
772 if (track == BRANCH_TRACK_OVERRIDE)
775 - fprintf(stderr, _("The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to\n"));
776 -
777 - strbuf_addf(&buf, "refs/remotes/%s", branch->name);
778 - remote_tracking = ref_exists(buf.buf);
779 - strbuf_release(&buf);
773 + die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));
774
781 - branch_existed = ref_exists(branch->refname);
775 create_branch(argv[0], (argc == 2) ? argv[1] : head,
776 force, reflog, 0, quiet, track);
777
785 - /*
786 - * We only show the instructions if the user gave us
787 - * one branch which doesn't exist locally, but is the
788 - * name of a remote-tracking branch.
789 - */
790 - if (argc == 1 && track == BRANCH_TRACK_OVERRIDE &&
791 - !branch_existed && remote_tracking) {
792 - fprintf(stderr, _("\nIf you wanted to make '%s' track '%s', do this:\n\n"), head, branch->name);
793 - fprintf(stderr, " git branch -d %s\n", branch->name);
794 - fprintf(stderr, " git branch --set-upstream-to %s\n", branch->name);
795 - }
796 -
778 } else
779 usage_with_options(builtin_branch_usage, options);
780
t/t3200-branch.sh
+2 -45
@@ -605,38 +605,8 @@ test_expect_success 'test --unset-upstream on a particular branch' '
605 test_must_fail git config branch.my14.merge
606 '
607
608 -test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
609 - git update-ref refs/remotes/origin/master HEAD &&
610 - git branch --set-upstream origin/master 2>actual &&
611 - test_when_finished git update-ref -d refs/remotes/origin/master &&
612 - test_when_finished git branch -d origin/master &&
613 - cat >expected <<EOF &&
614 -The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
615 -
616 -If you wanted to make '"'master'"' track '"'origin/master'"', do this:
617 -
618 - git branch -d origin/master
619 - git branch --set-upstream-to origin/master
620 -EOF
621 - test_i18ncmp expected actual
622 -'
623 -
624 -test_expect_success '--set-upstream with two args only shows the deprecation message' '
625 - git branch --set-upstream master my13 2>actual &&
626 - test_when_finished git branch --unset-upstream master &&
627 - cat >expected <<EOF &&
628 -The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
629 -EOF
630 - test_i18ncmp expected actual
631 -'
632 -
633 -test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
634 - git branch --set-upstream my13 2>actual &&
635 - test_when_finished git branch --unset-upstream my13 &&
636 - cat >expected <<EOF &&
637 -The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
638 -EOF
639 - test_i18ncmp expected actual
608 +test_expect_success '--set-upstream fails' '
609 + test_must_fail git branch --set-upstream origin/master
610 '
611
612 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
@@ -961,19 +931,6 @@ test_expect_success 'attempt to delete a branch merged to its base' '
931 test_must_fail git branch -d my10
932 '
933
964 -test_expect_success 'use set-upstream on the current branch' '
965 - git checkout master &&
966 - git --bare init myupstream.git &&
967 - git push myupstream.git master:refs/heads/frotz &&
968 - git remote add origin myupstream.git &&
969 - git fetch &&
970 - git branch --set-upstream master origin/frotz &&
971 -
972 - test "z$(git config branch.master.remote)" = "zorigin" &&
973 - test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
974 -
975 -'
976 -
934 test_expect_success 'use --edit-description' '
935 write_script editor <<-\EOF &&
936 echo "New contents" >"$1"
t/t6040-tracking-info.sh
+7 -13
@@ -188,35 +188,29 @@ test_expect_success 'fail to track annotated tags' '
188 test_must_fail git checkout heavytrack
189 '
190
191 -test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
191 +test_expect_success '--set-upstream-to does not change branch' '
192 git branch from-master master &&
193 - test_must_fail git config branch.from-master.merge > actual &&
194 - git branch --set-upstream from-master master &&
195 - git config branch.from-master.merge > actual &&
196 - grep -q "^refs/heads/master$" actual
197 -'
198 -
199 -test_expect_success '--set-upstream does not change branch' '
193 + git branch --set-upstream-to master from-master &&
194 git branch from-master2 master &&
195 test_must_fail git config branch.from-master2.merge > actual &&
196 git rev-list from-master2 &&
197 git update-ref refs/heads/from-master2 from-master2^ &&
198 git rev-parse from-master2 >expect2 &&
205 - git branch --set-upstream from-master2 master &&
199 + git branch --set-upstream-to master from-master2 &&
200 git config branch.from-master.merge > actual &&
201 git rev-parse from-master2 >actual2 &&
202 grep -q "^refs/heads/master$" actual &&
203 cmp expect2 actual2
204 '
205
212 -test_expect_success '--set-upstream @{-1}' '
213 - git checkout from-master &&
206 +test_expect_success '--set-upstream-to @{-1}' '
207 + git checkout follower &&
208 git checkout from-master2 &&
209 git config branch.from-master2.merge > expect2 &&
216 - git branch --set-upstream @{-1} follower &&
210 + git branch --set-upstream-to @{-1} from-master &&
211 git config branch.from-master.merge > actual &&
212 git config branch.from-master2.merge > actual2 &&
219 - git branch --set-upstream from-master follower &&
213 + git branch --set-upstream-to follower from-master &&
214 git config branch.from-master.merge > expect &&
215 test_cmp expect2 actual2 &&
216 test_cmp expect actual