Skip to content

Commit 1fb77b3

Browse files
committed
Merge branch 'ks/branch-set-upstream'
"branch --set-upstream" that has been deprecated in Git 1.8 has finally been retired. * ks/branch-set-upstream: branch: quote branch/ref names to improve readability builtin/branch: stop supporting the "--set-upstream" option t3200: cleanup cruft of a test
2 parents 238e487 + 9c93ff7 commit 1fb77b3

File tree

5 files changed

+23
-92
lines changed

5 files changed

+23
-92
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>::

branch.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,24 @@ int install_branch_config(int flag, const char *local, const char *origin, const
9090
if (shortname) {
9191
if (origin)
9292
printf_ln(rebasing ?
93-
_("Branch %s set up to track remote branch %s from %s by rebasing.") :
94-
_("Branch %s set up to track remote branch %s from %s."),
93+
_("Branch '%s' set up to track remote branch '%s' from '%s' by rebasing.") :
94+
_("Branch '%s' set up to track remote branch '%s' from '%s'."),
9595
local, shortname, origin);
9696
else
9797
printf_ln(rebasing ?
98-
_("Branch %s set up to track local branch %s by rebasing.") :
99-
_("Branch %s set up to track local branch %s."),
98+
_("Branch '%s' set up to track local branch '%s' by rebasing.") :
99+
_("Branch '%s' set up to track local branch '%s'."),
100100
local, shortname);
101101
} else {
102102
if (origin)
103103
printf_ln(rebasing ?
104-
_("Branch %s set up to track remote ref %s by rebasing.") :
105-
_("Branch %s set up to track remote ref %s."),
104+
_("Branch '%s' set up to track remote ref '%s' by rebasing.") :
105+
_("Branch '%s' set up to track remote ref '%s'."),
106106
local, remote);
107107
else
108108
printf_ln(rebasing ?
109-
_("Branch %s set up to track local ref %s by rebasing.") :
110-
_("Branch %s set up to track local ref %s."),
109+
_("Branch '%s' set up to track local ref '%s' by rebasing.") :
110+
_("Branch '%s' set up to track local ref '%s'."),
111111
local, remote);
112112
}
113113
}

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: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ test_expect_success 'use --set-upstream-to modify HEAD' '
559559
test_expect_success 'use --set-upstream-to modify a particular branch' '
560560
git branch my13 &&
561561
git branch --set-upstream-to master my13 &&
562+
test_when_finished "git branch --unset-upstream my13" &&
562563
test "$(git config branch.my13.remote)" = "." &&
563564
test "$(git config branch.my13.merge)" = "refs/heads/master"
564565
'
@@ -604,38 +605,8 @@ test_expect_success 'test --unset-upstream on a particular branch' '
604605
test_must_fail git config branch.my14.merge
605606
'
606607

607-
test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
608-
git update-ref refs/remotes/origin/master HEAD &&
609-
git branch --set-upstream origin/master 2>actual &&
610-
test_when_finished git update-ref -d refs/remotes/origin/master &&
611-
test_when_finished git branch -d origin/master &&
612-
cat >expected <<EOF &&
613-
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
614-
615-
If you wanted to make '"'master'"' track '"'origin/master'"', do this:
616-
617-
git branch -d origin/master
618-
git branch --set-upstream-to origin/master
619-
EOF
620-
test_i18ncmp expected actual
621-
'
622-
623-
test_expect_success '--set-upstream with two args only shows the deprecation message' '
624-
git branch --set-upstream master my13 2>actual &&
625-
test_when_finished git branch --unset-upstream master &&
626-
cat >expected <<EOF &&
627-
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
628-
EOF
629-
test_i18ncmp expected actual
630-
'
631-
632-
test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
633-
git branch --set-upstream my13 2>actual &&
634-
test_when_finished git branch --unset-upstream my13 &&
635-
cat >expected <<EOF &&
636-
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
637-
EOF
638-
test_i18ncmp expected actual
608+
test_expect_success '--set-upstream fails' '
609+
test_must_fail git branch --set-upstream origin/master
639610
'
640611

641612
test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
@@ -960,19 +931,6 @@ test_expect_success 'attempt to delete a branch merged to its base' '
960931
test_must_fail git branch -d my10
961932
'
962933

963-
test_expect_success 'use set-upstream on the current branch' '
964-
git checkout master &&
965-
git --bare init myupstream.git &&
966-
git push myupstream.git master:refs/heads/frotz &&
967-
git remote add origin myupstream.git &&
968-
git fetch &&
969-
git branch --set-upstream master origin/frotz &&
970-
971-
test "z$(git config branch.master.remote)" = "zorigin" &&
972-
test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
973-
974-
'
975-
976934
test_expect_success 'use --edit-description' '
977935
write_script editor <<-\EOF &&
978936
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)