Re: [PATCH 2/3] branch: suggest how to undo a --set-upstream when given one branch
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 10, 2012, 17:40 UTC
- Message-ID
- <7va9z7ikfi.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1341939181-8962-3-git-send-email-cmn@elego.de>
Carlos Martín Nieto <cmn@elego.de> writes:
Show 13 quoted lines
> This interface is error prone, and a better one (--set-upstream-to) > exists. Suggest how to fix a --set-upstream invocation in case the > user only gives one argument, which makes it likely that he meant to > do the opposite, like with > > git branch --set-upstream origin/master > > when they meant one of > > git branch --set-upstream origin/master master > git branch --set-upstream-to origin/master > > Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
The new code does not seem to depend on the value of "track" (which is set by either -t or --set-upstream) in any way. Shouldn't it be done only when it is set to track-override?
Doesn't "git branch [-f] frotz" without any other argument trigger the warning?
Show 39 quoted lines
> builtin/branch.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index c886fc0..5551227 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -864,10 +864,32 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
> info and making sure new_upstream is correct */
> create_branch(head, branch->name, new_upstream, 0, 0, 0, quiet, BRANCH_TRACK_OVERRIDE);
> } else if (argc > 0 && argc <= 2) {
> + struct branch *branch = branch_get(argv[0]);
> + const char *old_upstream = NULL;
> + int branch_existed = 0;
> +
> if (kinds != REF_LOCAL_BRANCH)
> die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
> +
> + /* Save what argv[0] was pointing to so we can give
> + the --set-upstream-to hint */
> + if (branch_has_merge_config(branch))
> + old_upstream = shorten_unambiguous_ref(branch->merge[0]->dst, 0);
> +
> + branch_existed = ref_exists(branch->refname);
> create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
> force_create, reflog, 0, quiet, track);
> +
> + if (argc == 1) {
> + printf("If you wanted to make '%s' track '%s', do this:\n", head, argv[0]);
> + if (branch_existed)
> + printf(" $ git branch --set-upstream '%s' '%s'\n", argv[0], old_upstream);
> + else
> + printf(" $ git branch -d '%s'\n", argv[0]);
> +
> + printf(" $ git branch --set-upstream-to '%s'\n", argv[0]);
> + }
> +
> } else
> usage_with_options(builtin_branch_usage, options);