713
int verbose = 0, abbrev = -1, detached = 0;
714
int reflog = 0, edit_description = 0;
715
int quiet = 0;
716
+ const char *new_upstream = NULL;
717
enum branch_track track;
718
int kinds = REF_LOCAL_BRANCH;
719
struct commit_list *with_commit = NULL;
727
BRANCH_TRACK_EXPLICIT),
728
OPT_SET_INT( 0, "set-upstream", &track, "change upstream info",
729
BRANCH_TRACK_OVERRIDE),
730
+ OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", "change the upstream info"),
731
OPT__COLOR(&branch_use_color, "use colored output"),
732
OPT_SET_INT('r', "remotes", &kinds, "act on remote-tracking branches",
733
REF_REMOTE_BRANCH),
796
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
797
0);
798
797
- if (!delete && !rename && !edit_description && argc == 0)
799
+ if (!delete && !rename && !edit_description && !new_upstream && argc == 0)
800
list = 1;
801
800
- if (!!delete + !!rename + !!force_create + !!list > 1)
802
+ if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > 1)
803
usage_with_options(builtin_branch_usage, options);
804
805
if (abbrev == -1)
854
rename_branch(argv[0], argv[1], rename > 1);
855
else
856
usage_with_options(builtin_branch_usage, options);
857
+ } else if (new_upstream) {
858
+ struct branch *branch = branch_get(argv[0]);
859
+
860
+ if (!ref_exists(branch->refname))
861
+ die(_("branch '%s' does not exist"), branch->name);
862
+
863
+ /*
864
+ * create_branch takes care of setting up the tracking
865
+ * info and making sure new_upstream is correct
866
+ */
867
+ create_branch(head, branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
868
} else if (argc > 0 && argc <= 2) {
869
if (kinds != REF_LOCAL_BRANCH)
870
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));