Skip to content

Commit 5266884

Browse files
Kaartic Sivaraamgitster
authored andcommitted
builtin/branch: stop supporting the "--set-upstream" option
The '--set-upstream' option of branch was deprecated in b347d06 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 93a6b3f commit 5266884

File tree

4 files changed

+14
-84
lines changed

4 files changed

+14
-84
lines changed

Documentation/git-branch.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,8 @@ start-point is either a local or remote-tracking branch.
195195
branch.autoSetupMerge configuration variable is true.
196196

197197
--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.
202200

203201
-u <upstream>::
204202
--set-upstream-to=<upstream>::

builtin/branch.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
561561
OPT__QUIET(&quiet, N_("suppress informational messages")),
562562
OPT_SET_INT('t', "track", &track, N_("set up tracking mode (see git-pull(1))"),
563563
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 },
566566
OPT_STRING('u', "set-upstream-to", &new_upstream, N_("upstream"), N_("change the upstream info")),
567567
OPT_BOOL(0, "unset-upstream", &unset_upstream, N_("Unset the upstream info")),
568568
OPT__COLOR(&branch_use_color, N_("use colored output")),
@@ -759,8 +759,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
759759
strbuf_release(&buf);
760760
} else if (argc > 0 && argc <= 2) {
761761
struct branch *branch = branch_get(argv[0]);
762-
int branch_existed = 0, remote_tracking = 0;
763-
struct strbuf buf = STRBUF_INIT;
764762

765763
if (!strcmp(argv[0], "HEAD"))
766764
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)
772770
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
773771

774772
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."));
780774

781-
branch_existed = ref_exists(branch->refname);
782775
create_branch(argv[0], (argc == 2) ? argv[1] : head,
783776
force, reflog, 0, quiet, track);
784777

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-
797778
} else
798779
usage_with_options(builtin_branch_usage, options);
799780

t/t3200-branch.sh

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -605,38 +605,8 @@ test_expect_success 'test --unset-upstream on a particular branch' '
605605
test_must_fail git config branch.my14.merge
606606
'
607607

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
640610
'
641611

642612
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' '
961931
test_must_fail git branch -d my10
962932
'
963933

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-
977934
test_expect_success 'use --edit-description' '
978935
write_script editor <<-\EOF &&
979936
echo "New contents" >"$1"

t/t6040-tracking-info.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,35 +188,29 @@ test_expect_success 'fail to track annotated tags' '
188188
test_must_fail git checkout heavytrack
189189
'
190190

191-
test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
191+
test_expect_success '--set-upstream-to does not change branch' '
192192
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 &&
200194
git branch from-master2 master &&
201195
test_must_fail git config branch.from-master2.merge > actual &&
202196
git rev-list from-master2 &&
203197
git update-ref refs/heads/from-master2 from-master2^ &&
204198
git rev-parse from-master2 >expect2 &&
205-
git branch --set-upstream from-master2 master &&
199+
git branch --set-upstream-to master from-master2 &&
206200
git config branch.from-master.merge > actual &&
207201
git rev-parse from-master2 >actual2 &&
208202
grep -q "^refs/heads/master$" actual &&
209203
cmp expect2 actual2
210204
'
211205

212-
test_expect_success '--set-upstream @{-1}' '
213-
git checkout from-master &&
206+
test_expect_success '--set-upstream-to @{-1}' '
207+
git checkout follower &&
214208
git checkout from-master2 &&
215209
git config branch.from-master2.merge > expect2 &&
216-
git branch --set-upstream @{-1} follower &&
210+
git branch --set-upstream-to @{-1} from-master &&
217211
git config branch.from-master.merge > actual &&
218212
git config branch.from-master2.merge > actual2 &&
219-
git branch --set-upstream from-master follower &&
213+
git branch --set-upstream-to follower from-master &&
220214
git config branch.from-master.merge > expect &&
221215
test_cmp expect2 actual2 &&
222216
test_cmp expect actual

0 commit comments

Comments
 (0)