All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 0/3] Improve branch UI for setting upstream information
@ 2012-08-30 17:23 Carlos Martín Nieto
  2012-08-30 17:23 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-08-30 17:23 UTC (permalink / raw)
  To: git; +Cc: gitster

Hi all,

As a result of making --unset-upstream fail if the given branch
doesn't exist, I discovered a copy-paste error in on the the tests in
the patch after it, so I'm resending the whole thing.

The changes from the last reroll are the tightening of the situations
where git will show an error message (not it's just if the branch is
new and exists as remote-tracking) which I already sent as a reply in
the other thread; and making --unset-upstream error out on bad input,
which I already mentioned above.

   cmn

Carlos Martín Nieto (3):
  branch: introduce --set-upstream-to
  branch: add --unset-upstream option
  branch: deprecate --set-upstream and show help if we detect possible
    mistaken use

 Documentation/git-branch.txt | 14 ++++++++-
 builtin/branch.c             | 60 +++++++++++++++++++++++++++++++++++++--
 t/t3200-branch.sh            | 67 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 137 insertions(+), 4 deletions(-)

-- 
1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/3] branch: introduce --set-upstream-to
  2012-08-30 17:23 [PATCHv2 0/3] Improve branch UI for setting upstream information Carlos Martín Nieto
@ 2012-08-30 17:23 ` Carlos Martín Nieto
  2012-08-30 17:51   ` Ralf Thielow
  2012-08-30 17:23 ` [PATCH 2/3] branch: add --unset-upstream option Carlos Martín Nieto
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-08-30 17:23 UTC (permalink / raw)
  To: git; +Cc: gitster

The existing --set-uptream option can cause confusion, as it uses the
usual branch convention of assuming a starting point of HEAD if none
is specified, causing

    git branch --set-upstream origin/master

to create a new local branch 'origin/master' that tracks the current
branch. As --set-upstream already exists, we can't simply change its
behaviour. To work around this, introduce --set-upstream-to which
accepts a compulsory argument indicating what the new upstream branch
should be and one optinal argument indicating which branch to change,
defaulting to HEAD.

The new options allows us to type

    git branch --set-upstream-to origin/master

to set the current branch's upstream to be origin's master.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---
 Documentation/git-branch.txt |  9 ++++++++-
 builtin/branch.c             | 17 +++++++++++++++--
 t/t3200-branch.sh            | 14 ++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 47235be..e41c4b5 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -13,6 +13,7 @@ SYNOPSIS
 	[--column[=<options>] | --no-column]
 	[(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
+'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
 'git branch' (-m | -M) [<oldbranch>] <newbranch>
 'git branch' (-d | -D) [-r] <branchname>...
 'git branch' --edit-description [<branchname>]
@@ -48,7 +49,7 @@ branch so that 'git pull' will appropriately merge from
 the remote-tracking branch. This behavior may be changed via the global
 `branch.autosetupmerge` configuration flag. That setting can be
 overridden by using the `--track` and `--no-track` options, and
-changed later using `git branch --set-upstream`.
+changed later using `git branch --set-upstream-to`.
 
 With a `-m` or `-M` option, <oldbranch> will be renamed to <newbranch>.
 If <oldbranch> had a corresponding reflog, it is renamed to match
@@ -173,6 +174,12 @@ start-point is either a local or remote-tracking branch.
 	like `--track` would when creating the branch, except that where
 	branch points to is not changed.
 
+-u <upstream>::
+--set-upstream-to=<upstream>::
+	Set up <branchname>'s tracking information so <upstream> is
+	considered <branchname>'s upstream branch. If no <branchname>
+	is specified, then it defaults to the current branch.
+
 --edit-description::
 	Open an editor and edit the text to explain what the branch is
 	for, to be used by various other commands (e.g. `request-pull`).
diff --git a/builtin/branch.c b/builtin/branch.c
index 0e060f2..3c978eb 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -713,6 +713,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	int verbose = 0, abbrev = -1, detached = 0;
 	int reflog = 0, edit_description = 0;
 	int quiet = 0;
+	const char *new_upstream = NULL;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
 	struct commit_list *with_commit = NULL;
@@ -726,6 +727,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			BRANCH_TRACK_EXPLICIT),
 		OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
 			BRANCH_TRACK_OVERRIDE),
+		OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", "change the upstream info"),
 		OPT__COLOR(&branch_use_color, "use colored output"),
 		OPT_SET_INT('r', "remotes",     &kinds, "act on remote-tracking branches",
 			REF_REMOTE_BRANCH),
@@ -794,10 +796,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
 			     0);
 
-	if (!delete && !rename && !edit_description && argc == 0)
+	if (!delete && !rename && !edit_description && !new_upstream && argc == 0)
 		list = 1;
 
-	if (!!delete + !!rename + !!force_create + !!list > 1)
+	if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > 1)
 		usage_with_options(builtin_branch_usage, options);
 
 	if (abbrev == -1)
@@ -852,6 +854,17 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			rename_branch(argv[0], argv[1], rename > 1);
 		else
 			usage_with_options(builtin_branch_usage, options);
+	} else if (new_upstream) {
+		struct branch *branch = branch_get(argv[0]);
+
+		if (!ref_exists(branch->refname))
+			die(_("branch '%s' does not exist"), branch->name);
+
+		/*
+		 * create_branch takes care of setting up the tracking
+		 * 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) {
 		if (kinds != REF_LOCAL_BRANCH)
 			die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index a17f8b2..e9019ac 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -369,6 +369,20 @@ test_expect_success \
     'git tag foobar &&
      test_must_fail git branch --track my11 foobar'
 
+test_expect_success 'use --set-upstream-to modify HEAD' \
+    'test_config branch.master.remote foo &&
+     test_config branch.master.merge foo &&
+     git branch my12
+     git branch --set-upstream-to my12 &&
+     test "$(git config branch.master.remote)" = "." &&
+     test "$(git config branch.master.merge)" = "refs/heads/my12"'
+
+test_expect_success 'use --set-upstream-to modify a particular branch' \
+    'git branch my13
+     git branch --set-upstream-to master my13 &&
+     test "$(git config branch.my13.remote)" = "." &&
+     test "$(git config branch.my13.merge)" = "refs/heads/master"'
+
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000	branch: Created from master
-- 
1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 2/3] branch: add --unset-upstream option
  2012-08-30 17:23 [PATCHv2 0/3] Improve branch UI for setting upstream information Carlos Martín Nieto
  2012-08-30 17:23 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
@ 2012-08-30 17:23 ` Carlos Martín Nieto
  2012-08-30 17:23 ` [PATCH 3/3] branch: deprecate --set-upstream and show help if we detect possible mistaken use Carlos Martín Nieto
  2012-08-30 17:37 ` [PATCHv2 0/3] Improve branch UI for setting upstream information Junio C Hamano
  3 siblings, 0 replies; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-08-30 17:23 UTC (permalink / raw)
  To: git; +Cc: gitster

We have ways of setting the upstream information, but if we want to
unset it, we need to resort to modifying the configuration manually.

Teach branch an --unset-upstream option that unsets this information.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---
 Documentation/git-branch.txt |  5 +++++
 builtin/branch.c             | 21 ++++++++++++++++++---
 t/t3200-branch.sh            | 19 +++++++++++++++++++
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index e41c4b5..9c1d2f1 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -14,6 +14,7 @@ SYNOPSIS
 	[(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
 'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
+'git branch' --unset-upstream [<branchname>]
 'git branch' (-m | -M) [<oldbranch>] <newbranch>
 'git branch' (-d | -D) [-r] <branchname>...
 'git branch' --edit-description [<branchname>]
@@ -180,6 +181,10 @@ start-point is either a local or remote-tracking branch.
 	considered <branchname>'s upstream branch. If no <branchname>
 	is specified, then it defaults to the current branch.
 
+--unset-upstream::
+	Remove the upstream information for <branchname>. If no branch
+	is specified it defaults to the current branch.
+
 --edit-description::
 	Open an editor and edit the text to explain what the branch is
 	for, to be used by various other commands (e.g. `request-pull`).
diff --git a/builtin/branch.c b/builtin/branch.c
index 3c978eb..557995d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -712,7 +712,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	int delete = 0, rename = 0, force_create = 0, list = 0;
 	int verbose = 0, abbrev = -1, detached = 0;
 	int reflog = 0, edit_description = 0;
-	int quiet = 0;
+	int quiet = 0, unset_upstream = 0;
 	const char *new_upstream = NULL;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
@@ -728,6 +728,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
 			BRANCH_TRACK_OVERRIDE),
 		OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", "change the upstream info"),
+		OPT_BOOLEAN(0, "unset-upstream", &unset_upstream, "Unset the upstream info"),
 		OPT__COLOR(&branch_use_color, "use colored output"),
 		OPT_SET_INT('r', "remotes",     &kinds, "act on remote-tracking branches",
 			REF_REMOTE_BRANCH),
@@ -796,10 +797,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
 			     0);
 
-	if (!delete && !rename && !edit_description && !new_upstream && argc == 0)
+	if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0)
 		list = 1;
 
-	if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > 1)
+	if (!!delete + !!rename + !!force_create + !!list + !!new_upstream + !!unset_upstream > 1)
 		usage_with_options(builtin_branch_usage, options);
 
 	if (abbrev == -1)
@@ -865,6 +866,20 @@ 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 (unset_upstream) {
+		struct branch *branch = branch_get(argv[0]);
+		struct strbuf buf = STRBUF_INIT;
+
+		if (!branch_has_merge_config(branch)) {
+			die(_("Branch '%s' has no upstream information"), branch->name);
+		}
+
+		strbuf_addf(&buf, "branch.%s.remote", branch->name);
+		git_config_set_multivar(buf.buf, NULL, NULL, 1);
+		strbuf_reset(&buf);
+		strbuf_addf(&buf, "branch.%s.merge", branch->name);
+		git_config_set_multivar(buf.buf, NULL, NULL, 1);
+		strbuf_release(&buf);
 	} else if (argc > 0 && argc <= 2) {
 		if (kinds != REF_LOCAL_BRANCH)
 			die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index e9019ac..1018e8b 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -383,6 +383,25 @@ test_expect_success 'use --set-upstream-to modify a particular branch' \
      test "$(git config branch.my13.remote)" = "." &&
      test "$(git config branch.my13.merge)" = "refs/heads/master"'
 
+test_expect_success '--unset-upstream should fail if given a non-existent branch' \
+    'test_must_fail git branch --unset-upstream i-dont-exist'
+
+test_expect_success 'test --unset-upstream on HEAD' \
+    'git branch my14
+     test_config branch.master.remote foo &&
+     test_config branch.master.merge foo &&
+     git branch --set-upstream-to my14 &&
+     git branch --unset-upstream &&
+     test_must_fail git config branch.master.remote &&
+     test_must_fail git config branch.master.merge'
+
+test_expect_success 'test --unset-upstream on a particular branch' \
+    'git branch my15
+     git branch --set-upstream-to master my14 &&
+     git branch --unset-upstream my14 &&
+     test_must_fail git config branch.my14.remote &&
+     test_must_fail git config branch.my14.merge'
+
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000	branch: Created from master
-- 
1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 3/3] branch: deprecate --set-upstream and show help if we detect possible mistaken use
  2012-08-30 17:23 [PATCHv2 0/3] Improve branch UI for setting upstream information Carlos Martín Nieto
  2012-08-30 17:23 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
  2012-08-30 17:23 ` [PATCH 2/3] branch: add --unset-upstream option Carlos Martín Nieto
@ 2012-08-30 17:23 ` Carlos Martín Nieto
  2012-08-30 17:37 ` [PATCHv2 0/3] Improve branch UI for setting upstream information Junio C Hamano
  3 siblings, 0 replies; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-08-30 17:23 UTC (permalink / raw)
  To: git; +Cc: gitster

This interface is error prone, and a better one (--set-upstream-to)
exists. Add a message listing the alternatives and suggest how to fix
a --set-upstream invocation in case the user only gives one argument
which causes a local branch with the same name as a remote-tracking
one to be created. The typical case is

    git branch --set-upstream origin/master

when the user meant

    git branch --set-upstream master origin/master

assuming that the current branch is master. Show a message telling the
user how to undo their action and get what they wanted. For the
command above, the message would be

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.

If you wanted to make 'master' track 'origin/master', do this:

    git branch -d origin/master
    git branch --set-upstream-to origin/master

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---
 builtin/branch.c  | 26 ++++++++++++++++++++++++++
 t/t3200-branch.sh | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/builtin/branch.c b/builtin/branch.c
index 557995d..5e95e35 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -881,10 +881,36 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		git_config_set_multivar(buf.buf, NULL, NULL, 1);
 		strbuf_release(&buf);
 	} else if (argc > 0 && argc <= 2) {
+		struct branch *branch = branch_get(argv[0]);
+		int branch_existed = 0, remote_tracking = 0;
+		struct strbuf buf = STRBUF_INIT;
+
 		if (kinds != REF_LOCAL_BRANCH)
 			die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
+
+		if (track == BRANCH_TRACK_OVERRIDE)
+			fprintf(stderr, _("The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to\n"));
+
+		strbuf_addf(&buf, "refs/remotes/%s", branch->name);
+		remote_tracking = ref_exists(buf.buf);
+		strbuf_release(&buf);
+
+		branch_existed = ref_exists(branch->refname);
 		create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
 			      force_create, reflog, 0, quiet, track);
+
+		/*
+		 * We only show the instructions if the user gave us
+		 * one branch which doesn't exist locally, but is the
+		 * name of a remote-tracking branch.
+		 */
+		if (argc == 1 && track == BRANCH_TRACK_OVERRIDE &&
+		    !branch_existed && remote_tracking) {
+			fprintf(stderr, _("\nIf you wanted to make '%s' track '%s', do this:\n\n"), head, branch->name);
+			fprintf(stderr, _("    git branch -d %s\n"), branch->name);
+			fprintf(stderr, _("    git branch --set-upstream-to %s\n"), branch->name);
+		}
+
 	} else
 		usage_with_options(builtin_branch_usage, options);
 
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 1018e8b..f2a076c 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -402,6 +402,40 @@ test_expect_success 'test --unset-upstream on a particular branch' \
      test_must_fail git config branch.my14.remote &&
      test_must_fail git config branch.my14.merge'
 
+test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' \
+    'git update-ref refs/remotes/origin/master HEAD &&
+     git branch --set-upstream origin/master 2>actual &&
+     test_when_finished git update-ref -d refs/remotes/origin/master &&
+     test_when_finished git branch -d origin/master &&
+     cat >expected <<EOF &&
+The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
+
+If you wanted to make '"'master'"' track '"'origin/master'"', do this:
+
+    git branch -d origin/master
+    git branch --set-upstream-to origin/master
+EOF
+     test_cmp expected actual
+'
+
+test_expect_success '--set-upstream with two args only shows the deprecation message' \
+    'git branch --set-upstream master my13 2>actual &&
+     test_when_finished git branch --unset-upstream master &&
+     cat >expected <<EOF &&
+The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
+EOF
+     test_cmp expected actual
+'
+
+test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' \
+    'git branch --set-upstream my13 2>actual &&
+     test_when_finished git branch --unset-upstream my13 &&
+     cat >expected <<EOF &&
+The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
+EOF
+     test_cmp expected actual
+'
+
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000	branch: Created from master
-- 
1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCHv2 0/3] Improve branch UI for setting upstream information
  2012-08-30 17:23 [PATCHv2 0/3] Improve branch UI for setting upstream information Carlos Martín Nieto
                   ` (2 preceding siblings ...)
  2012-08-30 17:23 ` [PATCH 3/3] branch: deprecate --set-upstream and show help if we detect possible mistaken use Carlos Martín Nieto
@ 2012-08-30 17:37 ` Junio C Hamano
  2012-08-30 18:57   ` Carlos Martín Nieto
  3 siblings, 1 reply; 27+ messages in thread
From: Junio C Hamano @ 2012-08-30 17:37 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: git

Carlos Martín Nieto <cmn@elego.de> writes:

> As a result of making --unset-upstream fail if the given branch
> doesn't exist, I discovered a copy-paste error in on the the tests in
> the patch after it, so I'm resending the whole thing.
>
> The changes from the last reroll are the tightening of the situations
> where git will show an error message (not it's just if the branch is
> new and exists as remote-tracking) which I already sent as a reply in
> the other thread; and making --unset-upstream error out on bad input,
> which I already mentioned above.

Thanks.

In addition to "--unset-upstream must fail on i-dont-exist branch"
in [2/3], I am wondering if we would want to also make sure the
command fails when the upstream information is not set for the
branch, i.e. something like the following on top.

What do you think?

 t/t3200-branch.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git i/t/t3200-branch.sh w/t/t3200-branch.sh
index 1018e8b..a0aaedd 100755
--- i/t/t3200-branch.sh
+++ w/t/t3200-branch.sh
@@ -393,7 +393,9 @@ test_expect_success 'test --unset-upstream on HEAD' \
      git branch --set-upstream-to my14 &&
      git branch --unset-upstream &&
      test_must_fail git config branch.master.remote &&
-     test_must_fail git config branch.master.merge'
+     test_must_fail git config branch.master.merge &&
+     test_must_fail git branch --unset-upstream
+'
 
 test_expect_success 'test --unset-upstream on a particular branch' \
     'git branch my15

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-08-30 17:23 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
@ 2012-08-30 17:51   ` Ralf Thielow
  2012-08-31 15:22     ` Carlos Martín Nieto
  0 siblings, 1 reply; 27+ messages in thread
From: Ralf Thielow @ 2012-08-30 17:51 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: git, gitster

On Thu, Aug 30, 2012 at 7:23 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
> behaviour. To work around this, introduce --set-upstream-to which
> accepts a compulsory argument indicating what the new upstream branch
> should be and one optinal argument indicating which branch to change,
> defaulting to HEAD.
>

Could you please also add this new option to the
"contrib/completion/git-completion.bash"
script?

Thanks!

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCHv2 0/3] Improve branch UI for setting upstream information
  2012-08-30 17:37 ` [PATCHv2 0/3] Improve branch UI for setting upstream information Junio C Hamano
@ 2012-08-30 18:57   ` Carlos Martín Nieto
  2012-08-30 20:12     ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-08-30 18:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Carlos Martín Nieto, git

Junio C Hamano <gitster@pobox.com> writes:

> Carlos Martín Nieto <cmn@elego.de> writes:
>
>> As a result of making --unset-upstream fail if the given branch
>> doesn't exist, I discovered a copy-paste error in on the the tests in
>> the patch after it, so I'm resending the whole thing.
>>
>> The changes from the last reroll are the tightening of the situations
>> where git will show an error message (not it's just if the branch is
>> new and exists as remote-tracking) which I already sent as a reply in
>> the other thread; and making --unset-upstream error out on bad input,
>> which I already mentioned above.
>
> Thanks.
>
> In addition to "--unset-upstream must fail on i-dont-exist branch"
> in [2/3], I am wondering if we would want to also make sure the
> command fails when the upstream information is not set for the
> branch, i.e. something like the following on top.
>
> What do you think?
>
>  t/t3200-branch.sh | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git i/t/t3200-branch.sh w/t/t3200-branch.sh
> index 1018e8b..a0aaedd 100755
> --- i/t/t3200-branch.sh
> +++ w/t/t3200-branch.sh
> @@ -393,7 +393,9 @@ test_expect_success 'test --unset-upstream on HEAD' \
>       git branch --set-upstream-to my14 &&
>       git branch --unset-upstream &&
>       test_must_fail git config branch.master.remote &&
> -     test_must_fail git config branch.master.merge'
> +     test_must_fail git config branch.master.merge &&
> +     test_must_fail git branch --unset-upstream
> +'

Yeah, this looks good, makes sure that it will still behave correctly
even if the code path for these two situations diverges.

   cmn

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCHv2 0/3] Improve branch UI for setting upstream information
  2012-08-30 18:57   ` Carlos Martín Nieto
@ 2012-08-30 20:12     ` Junio C Hamano
  0 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2012-08-30 20:12 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: Carlos Martín Nieto, git

carlos@cmartin.tk (Carlos Martín Nieto) writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> Carlos Martín Nieto <cmn@elego.de> writes:
>>
>>> As a result of making --unset-upstream fail if the given branch
>>> doesn't exist, I discovered a copy-paste error in on the the tests in
>>> the patch after it, so I'm resending the whole thing.
>>>
>>> The changes from the last reroll are the tightening of the situations
>>> where git will show an error message (not it's just if the branch is
>>> new and exists as remote-tracking) which I already sent as a reply in
>>> the other thread; and making --unset-upstream error out on bad input,
>>> which I already mentioned above.
>>
>> Thanks.
>>
>> In addition to "--unset-upstream must fail on i-dont-exist branch"
>> in [2/3], I am wondering if we would want to also make sure the
>> command fails when the upstream information is not set for the
>> branch, i.e. something like the following on top.
>>
>> What do you think?
>>
>>  t/t3200-branch.sh | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git i/t/t3200-branch.sh w/t/t3200-branch.sh
>> index 1018e8b..a0aaedd 100755
>> --- i/t/t3200-branch.sh
>> +++ w/t/t3200-branch.sh
>> @@ -393,7 +393,9 @@ test_expect_success 'test --unset-upstream on HEAD' \
>>       git branch --set-upstream-to my14 &&
>>       git branch --unset-upstream &&
>>       test_must_fail git config branch.master.remote &&
>> -     test_must_fail git config branch.master.merge'
>> +     test_must_fail git config branch.master.merge &&
>> +     test_must_fail git branch --unset-upstream
>> +'
>
> Yeah, this looks good, makes sure that it will still behave correctly
> even if the code path for these two situations diverges.

Alright; will squash.

Thanks.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-08-30 17:51   ` Ralf Thielow
@ 2012-08-31 15:22     ` Carlos Martín Nieto
  2012-08-31 15:30       ` Ralf Thielow
  0 siblings, 1 reply; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-08-31 15:22 UTC (permalink / raw)
  To: Ralf Thielow; +Cc: git, gitster

Ralf Thielow <ralf.thielow@gmail.com> writes:

> On Thu, Aug 30, 2012 at 7:23 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
>> behaviour. To work around this, introduce --set-upstream-to which
>> accepts a compulsory argument indicating what the new upstream branch
>> should be and one optinal argument indicating which branch to change,
>> defaulting to HEAD.
>>
>
> Could you please also add this new option to the
> "contrib/completion/git-completion.bash"
> script?

If I knew how those things work... Is this enough?

   cmn

--8<--
Subject: [PATCH] completion: add --set-upstream-to and --unset-upstream

---
 contrib/completion/git-completion.bash | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ffedce7..4f46357 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -880,6 +880,7 @@ _git_branch ()
 			--color --no-color --verbose --abbrev= --no-abbrev
 			--track --no-track --contains --merged --no-merged
 			--set-upstream --edit-description --list
+			--unset-upstream --set-upstream-to=
 			"
 		;;
 	*)
-- 
1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-08-31 15:22     ` Carlos Martín Nieto
@ 2012-08-31 15:30       ` Ralf Thielow
  2012-08-31 17:09         ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Ralf Thielow @ 2012-08-31 15:30 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: git, gitster

On Fri, Aug 31, 2012 at 5:22 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
> Ralf Thielow <ralf.thielow@gmail.com> writes:
>
>> On Thu, Aug 30, 2012 at 7:23 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
>>> behaviour. To work around this, introduce --set-upstream-to which
>>> accepts a compulsory argument indicating what the new upstream branch
>>> should be and one optinal argument indicating which branch to change,
>>> defaulting to HEAD.
>>>
>>
>> Could you please also add this new option to the
>> "contrib/completion/git-completion.bash"
>> script?
>
> If I knew how those things work... Is this enough?
>

Yes, Thanks.

>    cmn
>
> --8<--
> Subject: [PATCH] completion: add --set-upstream-to and --unset-upstream
>
> ---
>  contrib/completion/git-completion.bash | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index ffedce7..4f46357 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -880,6 +880,7 @@ _git_branch ()
>                         --color --no-color --verbose --abbrev= --no-abbrev
>                         --track --no-track --contains --merged --no-merged
>                         --set-upstream --edit-description --list
> +                       --unset-upstream --set-upstream-to=
>                         "
>                 ;;
>         *)
> --
> 1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-08-31 15:30       ` Ralf Thielow
@ 2012-08-31 17:09         ` Junio C Hamano
  2012-09-01 15:13           ` Carlos Martín Nieto
  0 siblings, 1 reply; 27+ messages in thread
From: Junio C Hamano @ 2012-08-31 17:09 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: Ralf Thielow, git

Ralf Thielow <ralf.thielow@gmail.com> writes:

> On Fri, Aug 31, 2012 at 5:22 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
>> Ralf Thielow <ralf.thielow@gmail.com> writes:
>>
>>> On Thu, Aug 30, 2012 at 7:23 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
>>>> behaviour. To work around this, introduce --set-upstream-to which
>>>> accepts a compulsory argument indicating what the new upstream branch
>>>> should be and one optinal argument indicating which branch to change,
>>>> defaulting to HEAD.
>>>>
>>>
>>> Could you please also add this new option to the
>>> "contrib/completion/git-completion.bash"
>>> script?
>>
>> If I knew how those things work... Is this enough?
>>
>
> Yes, Thanks.

While you are at it, perhaps you may want to unadvertise --set-upstream?

>
>>    cmn
>>
>> --8<--
>> Subject: [PATCH] completion: add --set-upstream-to and --unset-upstream
>>
>> ---
>>  contrib/completion/git-completion.bash | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>> index ffedce7..4f46357 100644
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -880,6 +880,7 @@ _git_branch ()
>>                         --color --no-color --verbose --abbrev= --no-abbrev
>>                         --track --no-track --contains --merged --no-merged
>>                         --set-upstream --edit-description --list
>> +                       --unset-upstream --set-upstream-to=
>>                         "
>>                 ;;
>>         *)
>> --
>> 1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-08-31 17:09         ` Junio C Hamano
@ 2012-09-01 15:13           ` Carlos Martín Nieto
  0 siblings, 0 replies; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-09-01 15:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ralf Thielow, git

Junio C Hamano <gitster@pobox.com> writes:

> Ralf Thielow <ralf.thielow@gmail.com> writes:
>
>> On Fri, Aug 31, 2012 at 5:22 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
>>> Ralf Thielow <ralf.thielow@gmail.com> writes:
>>>
>>>> On Thu, Aug 30, 2012 at 7:23 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
>>>>> behaviour. To work around this, introduce --set-upstream-to which
>>>>> accepts a compulsory argument indicating what the new upstream branch
>>>>> should be and one optinal argument indicating which branch to change,
>>>>> defaulting to HEAD.
>>>>>
>>>>
>>>> Could you please also add this new option to the
>>>> "contrib/completion/git-completion.bash"
>>>> script?
>>>
>>> If I knew how those things work... Is this enough?
>>>
>>
>> Yes, Thanks.
>
> While you are at it, perhaps you may want to unadvertise --set-upstream?
>

Yeah, that'd be good.

   cmn

--8<--
Subject: [PATCH] completion: add --set-upstream-to and --unset-upstream

Remove --set-upstream as it's deprecated now.
---
 contrib/completion/git-completion.bash | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ffedce7..4a4d30a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -879,7 +879,8 @@ _git_branch ()
 		__gitcomp "
 			--color --no-color --verbose --abbrev= --no-abbrev
 			--track --no-track --contains --merged --no-merged
-			--set-upstream --edit-description --list
+			--set-upstream-to= --edit-description --list
+			--unset-upstream
 			"
 		;;
 	*)
-- 
1.7.12.3.g0dd8ef6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/3] branch: introduce --set-upstream-to
  2012-08-20 13:47 [PATCH " Carlos Martín Nieto
@ 2012-08-20 13:47 ` Carlos Martín Nieto
  0 siblings, 0 replies; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-08-20 13:47 UTC (permalink / raw)
  To: git

The existing --set-uptream option can cause confusion, as it uses the
usual branch convention of assuming a starting point of HEAD if none
is specified, causing

    git branch --set-upstream origin/master

to create a new local branch 'origin/master' that tracks the current
branch. As --set-upstream already exists, we can't simply change its
behaviour. To work around this, introduce --set-upstream-to which
accepts a compulsory argument indicating what the new upstream branch
should be and one optinal argument indicating which branch to change,
defaulting to HEAD.

The new options allows us to type

    git branch --set-upstream-to origin/master

to set the current branch's upstream to be origin's master.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---
 Documentation/git-branch.txt |  9 ++++++++-
 builtin/branch.c             | 17 +++++++++++++++--
 t/t3200-branch.sh            | 14 ++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 47235be..e41c4b5 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -13,6 +13,7 @@ SYNOPSIS
 	[--column[=<options>] | --no-column]
 	[(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
+'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
 'git branch' (-m | -M) [<oldbranch>] <newbranch>
 'git branch' (-d | -D) [-r] <branchname>...
 'git branch' --edit-description [<branchname>]
@@ -48,7 +49,7 @@ branch so that 'git pull' will appropriately merge from
 the remote-tracking branch. This behavior may be changed via the global
 `branch.autosetupmerge` configuration flag. That setting can be
 overridden by using the `--track` and `--no-track` options, and
-changed later using `git branch --set-upstream`.
+changed later using `git branch --set-upstream-to`.
 
 With a `-m` or `-M` option, <oldbranch> will be renamed to <newbranch>.
 If <oldbranch> had a corresponding reflog, it is renamed to match
@@ -173,6 +174,12 @@ start-point is either a local or remote-tracking branch.
 	like `--track` would when creating the branch, except that where
 	branch points to is not changed.
 
+-u <upstream>::
+--set-upstream-to=<upstream>::
+	Set up <branchname>'s tracking information so <upstream> is
+	considered <branchname>'s upstream branch. If no <branchname>
+	is specified, then it defaults to the current branch.
+
 --edit-description::
 	Open an editor and edit the text to explain what the branch is
 	for, to be used by various other commands (e.g. `request-pull`).
diff --git a/builtin/branch.c b/builtin/branch.c
index 0e060f2..3c978eb 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -713,6 +713,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	int verbose = 0, abbrev = -1, detached = 0;
 	int reflog = 0, edit_description = 0;
 	int quiet = 0;
+	const char *new_upstream = NULL;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
 	struct commit_list *with_commit = NULL;
@@ -726,6 +727,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			BRANCH_TRACK_EXPLICIT),
 		OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
 			BRANCH_TRACK_OVERRIDE),
+		OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", "change the upstream info"),
 		OPT__COLOR(&branch_use_color, "use colored output"),
 		OPT_SET_INT('r', "remotes",     &kinds, "act on remote-tracking branches",
 			REF_REMOTE_BRANCH),
@@ -794,10 +796,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
 			     0);
 
-	if (!delete && !rename && !edit_description && argc == 0)
+	if (!delete && !rename && !edit_description && !new_upstream && argc == 0)
 		list = 1;
 
-	if (!!delete + !!rename + !!force_create + !!list > 1)
+	if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > 1)
 		usage_with_options(builtin_branch_usage, options);
 
 	if (abbrev == -1)
@@ -852,6 +854,17 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			rename_branch(argv[0], argv[1], rename > 1);
 		else
 			usage_with_options(builtin_branch_usage, options);
+	} else if (new_upstream) {
+		struct branch *branch = branch_get(argv[0]);
+
+		if (!ref_exists(branch->refname))
+			die(_("branch '%s' does not exist"), branch->name);
+
+		/*
+		 * create_branch takes care of setting up the tracking
+		 * 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) {
 		if (kinds != REF_LOCAL_BRANCH)
 			die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index a17f8b2..e9019ac 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -369,6 +369,20 @@ test_expect_success \
     'git tag foobar &&
      test_must_fail git branch --track my11 foobar'
 
+test_expect_success 'use --set-upstream-to modify HEAD' \
+    'test_config branch.master.remote foo &&
+     test_config branch.master.merge foo &&
+     git branch my12
+     git branch --set-upstream-to my12 &&
+     test "$(git config branch.master.remote)" = "." &&
+     test "$(git config branch.master.merge)" = "refs/heads/my12"'
+
+test_expect_success 'use --set-upstream-to modify a particular branch' \
+    'git branch my13
+     git branch --set-upstream-to master my13 &&
+     test "$(git config branch.my13.remote)" = "." &&
+     test "$(git config branch.my13.merge)" = "refs/heads/master"'
+
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000	branch: Created from master
-- 
1.7.11.1.104.ge7b44f1

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-12  8:41                   ` Miles Bader
@ 2012-07-12 16:58                     ` Junio C Hamano
  0 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2012-07-12 16:58 UTC (permalink / raw)
  To: Miles Bader; +Cc: Jonathan Nieder, Carlos Martín Nieto, git, Matthieu Moy

Miles Bader <miles@gnu.org> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>> is easier to understand, while I think
>>
>> 	git branch <branch> [<start>]
>>         git branch --set-upstream-to=<upstream> [<branch>]
>
> Isn't one problem with this that even if a "--set-upstream-to" option
> exists, inevitably some [and I'm guessing, many] people will not be
> aware of it (after all, nobody reads documentation more than they have
> to), and will attempt to use "--set-upstream" with an argument
> (that's the natural thing to do, after all) -- which may succeed with
> weird results ...?

In the part you quoted in the message you are responding to in the
subthread between Jonathan and, I was expressing doubts about his
"upon seeing a single argument for operations that need two pieces
of info, sometimes the first one is assumed to be missing and gets
the default, some other times the second one is assumed to be
missing and gets the default" design, which I felt would be
unnecessarily confusing.

The issue of possible confusion you raised is real, was discussed in
the main thread of discussion of the earlier round, and has been
addressed in this round of the patch series, I think, with warnings
and/or advises.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-11  1:20                 ` Junio C Hamano
  2012-07-11  1:37                   ` Jonathan Nieder
@ 2012-07-12  8:41                   ` Miles Bader
  2012-07-12 16:58                     ` Junio C Hamano
  1 sibling, 1 reply; 27+ messages in thread
From: Miles Bader @ 2012-07-12  8:41 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jonathan Nieder, Carlos Martín Nieto, git, Matthieu Moy

Junio C Hamano <gitster@pobox.com> writes:
> is easier to understand, while I think
>
> 	git branch <branch> [<start>]
>         git branch --set-upstream-to=<upstream> [<branch>]

Isn't one problem with this that even if a "--set-upstream-to" option
exists, inevitably some [and I'm guessing, many] people will not be
aware of it (after all, nobody reads documentation more than they have
to), and will attempt to use "--set-upstream" with an argument
(that's the natural thing to do, after all) -- which may succeed with
weird results ...?

-miles

-- 
One of the lessons of history is that nothing is often a good thing to
do, and always a clever thing to say.  -- Will Durant

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-11  1:20                 ` Junio C Hamano
@ 2012-07-11  1:37                   ` Jonathan Nieder
  2012-07-12  8:41                   ` Miles Bader
  1 sibling, 0 replies; 27+ messages in thread
From: Jonathan Nieder @ 2012-07-11  1:37 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Junio C Hamano wrote:

> In short, you are saying that, assuming that missing <start> and
> <branch> are given a sane default values (namely "HEAD"), the
> syntax:
>
>	git branch <branch> [<start>]
>	git branch --set-upstream-jrn [<branch>] <upstream>
>
> is easier to understand

I didn't propose allowing the branch argument to be omitted, actually.
It would be clearest, _especially_ because one argument currently
means something different, to make that error out.  Sorry for the lack
of clarity.

One more detail I didn't mention before: I think a convenience feature

	git branch --set-upstream-to <upstream>

that takes exactly one argument and means

	git branch --set-upstream HEAD <upstream>

would be fine.  Having a second command to do the same thing as
--set-upstream does (or adding new --set-other-things commands that
use this proposed convention where the value comes before the key) and
migrating awkwardly to it is what I object to.

Clearer?
Jonathan

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 23:47               ` Jonathan Nieder
@ 2012-07-11  1:20                 ` Junio C Hamano
  2012-07-11  1:37                   ` Jonathan Nieder
  2012-07-12  8:41                   ` Miles Bader
  0 siblings, 2 replies; 27+ messages in thread
From: Junio C Hamano @ 2012-07-11  1:20 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Jonathan Nieder <jrnieder@gmail.com> writes:

> The truth is that neither one of us is right.  Both conventions
> could work, and which one is more intuitive will vary from person
> to person.

It is not just person-to-person, I think.

In short, you are saying that, assuming that missing <start> and
<branch> are given a sane default values (namely "HEAD"), the
syntax:

	git branch <branch> [<start>]
	git branch --set-upstream-jrn [<branch>] <upstream>

is easier to understand, while I think

	git branch <branch> [<start>]
        git branch --set-upstream-to=<upstream> [<branch>]

so that omitted things can come uniformly at the end (of course,
unless the --option=argument in the middle is omitted, that is)
makes things more consistent.

I do not think it is productive to keep agreeing that we disagree
and continuing to talk between ourselves without waiting for others
to catch up, so I'll stop here.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 23:13             ` Junio C Hamano
@ 2012-07-10 23:47               ` Jonathan Nieder
  2012-07-11  1:20                 ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2012-07-10 23:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Junio C Hamano wrote:

> You can think of it this way.
>
> "git branch" can not only _create_ a new branch (or list existing
> ones, but that is another entirely different mode), but also can be
> used to set attributes to an existing branch.  Imagine a new option,
> say --set-description, to replace branch.frotz.description, for
> example.  It would be used like this:
>
> 	$ git branch --set-description='add frotz feature' frotz

That's the same question.

You say that it would be used like that.  I say that it would be
more intuitive, given how "git remote", "git config", and other
commands other than "update-index --chmod" that set attributes already
work, for it to be used like this:

	git branch --set-description frotz 'add frotz feature'

Notice how similar that is to "git remote set-head origin master".
It would just be the consistent thing to do.

The truth is that neither one of us is right.  Both conventions
could work, and which one is more intuitive will vary from person
to person.  The convention used for plain "git branch" is

	copy(target, source)

That matches memcpy() and is the opposite of what "cp" uses.  Oh
well.  The convention used for "git remote add" is

	method(this, args...)

It's generally pretty natural.  The convention used for "git
update-index --chmod" is

	action(parameters)(files...)

That matches "chmod" so it was probably a good choice.

Hoping that clarifies,
Jonathan

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 21:09           ` Jonathan Nieder
@ 2012-07-10 23:13             ` Junio C Hamano
  2012-07-10 23:47               ` Jonathan Nieder
  0 siblings, 1 reply; 27+ messages in thread
From: Junio C Hamano @ 2012-07-10 23:13 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Jonathan Nieder <jrnieder@gmail.com> writes:

> [someone should have]
> | suggested an alternative syntax that avoids the mistake you quoted
> | above, perhaps something like:
> |
> | 	git branch --set-upstream-to=origin/master [HEAD]
>
> with which I disagree.

You can think of it this way.

"git branch" can not only _create_ a new branch (or list existing
ones, but that is another entirely different mode), but also can be
used to set attributes to an existing branch.  Imagine a new option,
say --set-description, to replace branch.frotz.description, for
example.  It would be used like this:

	$ git branch --set-description='add frotz feature' frotz

to set the description for the 'frotz' branch (i.e. the above would
set branch.frotz.description), and we default to HEAD if 'frotz' is
missing from the command line.  "git branch --option [<branch>]" is
about manipulating the branch, and we default the target of
manipulation to HEAD.

"upstream" is just another kind of attribute for the branch being
manipulated, whose value happens to be a branch name.

The mistake was that --set-upstream was coded by piggybacking the
existing --track implementation where a new branch was created, and
in that codepath, "git branch <name1> [<name2>]" creates <name1>
while defaulting a missing <name2> to HEAD.

Creating a new branch that is forked from the current HEAD is an
often useful thing to do, so defaulting a missing <name2> (aka
"start-point") to HEAD is very sensible, but reconfiguring a named
branch <name1> to integrate with the current branch is much less
useful than the other way around.  One major reason why it is so is
because you would more likely set any branch to integrate with a
remote tracking branch (rather than a local branch) and by
definition your HEAD cannot be a remote tracking branch.

It makes it worse that you would often want to reconfigure the
current branch; for the purpose of reconfiguring a branch <name1> to
integrate with something else <name2>, it is much more likely that
you want a missing <name1> to default to HEAD, not the other way
around to default a missing <name2> to HEAD, which is useful for
branch creation.

But switching which missing argument gets default based on what
options are used is insane.

If the very original "create this new branch starting at that point"
were spelled like this

	$ git branch [--start-point=<name2>] <name1>

and a missing <name2> defaulted to HEAD, it probably would have been
better. It would have made it very unlikely to tempt anybody to hack
the --set-upstream option into the system with the wrong parameter
order if such a command line convention was in place.

If anything, it could be a sensible longer-term direction to a more
intuitive UI to deprecate the two-name format and make the creation
to be specified with an explicit --start-point option with an
argument (which defaults to HEAD), but I think that falls into the
"if I were reinventing git without existing userbase in 2005"
category and it is too late for that.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 20:49         ` Junio C Hamano
@ 2012-07-10 21:09           ` Jonathan Nieder
  2012-07-10 23:13             ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2012-07-10 21:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Junio C Hamano wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:

>> The immediate problem that seems to trip people up is that it is very
>> tempting to run
>>
>> 	git branch --set-upstream junio/master
>
> I think we have discussed this already a few days ago.  See my
> comment in the earlier thread before this round.

You wrote[*]:

| I think it was a mistake that nobody noticed that it is likely that
| the operation most often will be done for the current branch and the
| usual "give me one branch name to operate on, or I'll operate on the
| current branch" command line convention of "git branch" commannd is
| not a good fit for it, when "set upstream" feature was added

with which I completely agree.  You then moved on to

|                                                               and
[someone should have]
| suggested an alternative syntax that avoids the mistake you quoted
| above, perhaps something like:
|
| 	git branch --set-upstream-to=origin/master [HEAD]

with which I disagree.

As far as I can tell, nobody really thought very hard about what
--set-upstream would do when passed only one argument.  It should have
been made to error out and only later change if someone had an idea
about how to make it useful.

Luckily we have a way out.  Any example transition plan looks like
the following.

DAY 1.

	$ git branch --set-upstream origin/master
	Branch origin/master set up to track local branch debian-sid.
	hint: If you intended to make the current branch track
	hint: origin/master, you can recover with the following commands:
	hint:  $ git branch -d origin/master
	hint:  $ git branch --set-upstream master origin/master
	$

DAY 2.

	$ git branch --set-upstream origin/master
	Branch origin/master set up to track local branch debian-sid.
	warning: using --set-upstream when creating a new branch is deprecated
	hint: use --track instead
	hint:
	hint: If you intended to make the current branch track
	hint: origin/master, you can recover with the following commands:
	hint:  $ git branch -d origin/master
	hint:  $ git branch --set-upstream master origin/master
	$

DAY 3.

	$ git branch --set-upstream origin/master
	fatal: no such branch "origin/master"
	$

DAY 4.

	$ git branch --set-upstream origin/master
	usage: git branch --set-upstream <branchname> <upstream>
	$

[*] http://thread.gmane.org/gmane.comp.version-control.git/201040/focus=201051

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 20:11       ` Jonathan Nieder
@ 2012-07-10 20:49         ` Junio C Hamano
  2012-07-10 21:09           ` Jonathan Nieder
  0 siblings, 1 reply; 27+ messages in thread
From: Junio C Hamano @ 2012-07-10 20:49 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Jonathan Nieder <jrnieder@gmail.com> writes:

> The immediate problem that seems to trip people up is that it is very
> tempting to run
>
> 	git branch --set-upstream junio/master

I think we have discussed this already a few days ago.  See my
comment in the earlier thread before this round.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 19:49     ` Junio C Hamano
@ 2012-07-10 20:11       ` Jonathan Nieder
  2012-07-10 20:49         ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2012-07-10 20:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Junio C Hamano wrote:

> I am not super excited about it either, but at least it is a vast
> improvement compared to the older one, with which it was entirely
> unclear if we are setting the value of upstream *to* what is given
> as an option, or setting the upstream *for* what is given on the
> command line.

Ah, do you mean that --set-upstream is meant to have usage like
"git remote set-url" and co?

	git remote set-url <remote> <url>
	git branch --set-upstream <branch> <upstream>

That's a reasonable stance, and it seems possible to get used to it.
In that case, we should just teach --set-upstream not to create
new branches, and people will get used to it.

The immediate problem that seems to trip people up is that it is very
tempting to run

	git branch --set-upstream junio/master

in an attempt to change what is upstream to the current branch, and
the result is some other completely counterintuitive thing.  I suspect
the order of arguments to --set-upstream is a red herring, as long as
it errors out when the arguments are switched to help people catch
mistakes.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 19:13   ` Jonathan Nieder
@ 2012-07-10 19:49     ` Junio C Hamano
  2012-07-10 20:11       ` Jonathan Nieder
  0 siblings, 1 reply; 27+ messages in thread
From: Junio C Hamano @ 2012-07-10 19:49 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Carlos Martín Nieto, git, Matthieu Moy

Jonathan Nieder <jrnieder@gmail.com> writes:

>> The existing --set-uptream option can cause confusion, as it uses the
>> usual branch convention of assuming a starting point of HEAD if none
>> is specified, causing
>>
>>     git branch --set-upstream origin/master
>>
>> to create a new local branch 'origin/master' that tracks the current
>> branch. As --set-upstream already exists, we can't simply change its
>> behaviour. To work around this, introduce --set-upstream-to which
>> accepts a compulsory argument
>
> Thanks.  A part of me really dislikes this --set-upstream-to which
> is named more awkwardly than the deprecated mistake it replaces,
> though.

I am not super excited about it either, but at least it is a vast
improvement compared to the older one, with which it was entirely
unclear if we are setting the value of upstream *to* what is given
as an option, or setting the upstream *for* what is given on the
command line.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 16:52 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
  2012-07-10 17:08   ` Matthieu Moy
  2012-07-10 17:26   ` Junio C Hamano
@ 2012-07-10 19:13   ` Jonathan Nieder
  2012-07-10 19:49     ` Junio C Hamano
  2 siblings, 1 reply; 27+ messages in thread
From: Jonathan Nieder @ 2012-07-10 19:13 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: git, gitster, Matthieu Moy

Hi,

Carlos Martín Nieto wrote:

> The existing --set-uptream option can cause confusion, as it uses the
> usual branch convention of assuming a starting point of HEAD if none
> is specified, causing
>
>     git branch --set-upstream origin/master
>
> to create a new local branch 'origin/master' that tracks the current
> branch. As --set-upstream already exists, we can't simply change its
> behaviour. To work around this, introduce --set-upstream-to which
> accepts a compulsory argument

Thanks.  A part of me really dislikes this --set-upstream-to which
is named more awkwardly than the deprecated mistake it replaces,
though.

Here's a patch on top to play with that names the new option
"--set-upstream=".  Untested.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
diff --git i/Documentation/git-branch.txt w/Documentation/git-branch.txt
index f572913f..57935a64 100644
--- i/Documentation/git-branch.txt
+++ w/Documentation/git-branch.txt
@@ -49,7 +49,7 @@ branch so that 'git pull' will appropriately merge from
 the remote-tracking branch. This behavior may be changed via the global
 `branch.autosetupmerge` configuration flag. That setting can be
 overridden by using the `--track` and `--no-track` options, and
-changed later using `git branch --set-upstream-to`.
+changed later using `git branch --set-upstream`.
 
 With a `-m` or `-M` option, <oldbranch> will be renamed to <newbranch>.
 If <oldbranch> had a corresponding reflog, it is renamed to match
@@ -174,11 +174,13 @@ start-point is either a local or remote-tracking branch.
 	like `--track` would when creating the branch, except that where
 	branch points to is not changed.
 
--u <upstream>::
---set-upstream-to=<upstream>::
+--set-upstream=<upstream>::
 	Set up <branchname>'s tracking information so <upstream> is
 	considered <branchname>'s upstream branch. If no branch is
 	specified it defaults to the current branch.
++
+If no argument is attached, for historical reasons the meaning is
+different.  See above.
 
 --edit-description::
 	Open an editor and edit the text to explain what the branch is
diff --git i/builtin/branch.c w/builtin/branch.c
index c886fc06..0d705790 100644
--- i/builtin/branch.c
+++ w/builtin/branch.c
@@ -669,6 +669,31 @@ static int opt_parse_merge_filter(const struct option *opt, const char *arg, int
 	return 0;
 }
 
+struct set_upstream_params {
+	enum branch_track *track;
+	const char **new_upstream;
+};
+static int parse_opt_set_upstream(const struct option *opt, const char *arg, int unset)
+{
+	struct set_upstream_params *o = opt->value;
+
+	if (unset) {	/* --no-set-upstream */
+		*o->track = BRANCH_TRACK_NEVER;
+		*o->new_upstream = NULL;
+		return 0;
+	}
+
+	*o->track = BRANCH_TRACK_OVERRIDE;
+	if (!arg)	/* --set-upstream <branchname> <start-point> */
+		*o->new_upstream = NULL;
+	else	/* --set-upstream=<upstream> <branchname> */
+		*o->new_upstream = arg;
+	return 0;
+}
+#define OPT_SET_UPSTREAM(s, l, v) \
+	{ OPTION_CALLBACK, (s), (l), (v), "upstream", "change upstream info", \
+	  PARSE_OPT_OPTARG, &parse_opt_set_upstream }
+
 static const char edit_description[] = "BRANCH_DESCRIPTION";
 
 static int edit_branch_description(const char *branch_name)
@@ -716,6 +741,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	const char *new_upstream = NULL;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
+	struct set_upstream_params set_upstream_args = { &track, &new_upstream };
 	struct commit_list *with_commit = NULL;
 
 	struct option options[] = {
@@ -725,9 +751,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		OPT__QUIET(&quiet, "suppress informational messages"),
 		OPT_SET_INT('t', "track",  &track, "set up tracking mode (see git-pull(1))",
 			BRANCH_TRACK_EXPLICIT),
-		OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
-			BRANCH_TRACK_OVERRIDE),
-		OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", "change the upstream info"),
+		OPT_SET_UPSTREAM(0, "set-upstream", &set_upstream_args),
 		OPT__COLOR(&branch_use_color, "use colored output"),
 		OPT_SET_INT('r', "remotes",     &kinds, "act on remote-tracking branches",
 			REF_REMOTE_BRANCH),

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 16:52 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
  2012-07-10 17:08   ` Matthieu Moy
@ 2012-07-10 17:26   ` Junio C Hamano
  2012-07-10 19:13   ` Jonathan Nieder
  2 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2012-07-10 17:26 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: git, jrnieder

Carlos Martín Nieto <cmn@elego.de> writes:

> diff --git a/builtin/branch.c b/builtin/branch.c
> index 0e060f2..c886fc0 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -713,6 +713,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  	int verbose = 0, abbrev = -1, detached = 0;
>  	int reflog = 0, edit_description = 0;
>  	int quiet = 0;
> +	const char *new_upstream = NULL;
>  	enum branch_track track;
>  	int kinds = REF_LOCAL_BRANCH;
>  	struct commit_list *with_commit = NULL;
> @@ -726,6 +727,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  			BRANCH_TRACK_EXPLICIT),
>  		OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
>  			BRANCH_TRACK_OVERRIDE),
> +		OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", "change the upstream info"),
>  		OPT__COLOR(&branch_use_color, "use colored output"),
>  		OPT_SET_INT('r', "remotes",     &kinds, "act on remote-tracking branches",
>  			REF_REMOTE_BRANCH),
> @@ -794,10 +796,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  	argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
>  			     0);
>  
> -	if (!delete && !rename && !edit_description && argc == 0)
> +	if (!delete && !rename && !edit_description && !new_upstream && argc == 0)
>  		list = 1;
>  
> -	if (!!delete + !!rename + !!force_create + !!list > 1)
> +	if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > 1)
>  		usage_with_options(builtin_branch_usage, options);

It probably is an error to have track and new_upstream together.

The remainder of [Patch 1/3] looked entirely sensible, including the
proposed log message (modulo missing sign-off).

Thanks.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 16:52 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
@ 2012-07-10 17:08   ` Matthieu Moy
  2012-07-10 17:26   ` Junio C Hamano
  2012-07-10 19:13   ` Jonathan Nieder
  2 siblings, 0 replies; 27+ messages in thread
From: Matthieu Moy @ 2012-07-10 17:08 UTC (permalink / raw)
  To: Carlos Martín Nieto; +Cc: git, jrnieder, gitster

Carlos Martín Nieto <cmn@elego.de> writes:

> The new options allows us to type
>
>     git branch --set-upstream-to origin/master

This is cool :-).

>  Documentation/git-branch.txt |    9 ++++++++-
>  builtin/branch.c             |   15 +++++++++++++--

I think this deserves a few new tests (probably in t/t3200-branch.sh).

> +-u <upstream>::
> +--set-upstream-to=<upstream>::
> +	Set up <branchname>'s tracking information so <upstream> is
> +	considered <branchname>'s upstream branch. If no branch is
> +	specified it defaults to the current branch.

Perhaps "if <branchname> is not specified, then it defaults to the
current branch.". The current wording does not make it very clear if "no
branch is specified" refers to <branchname> or <upstream> (although the
second option would be plain silly).

> +	} else if (new_upstream) {
> +		struct branch *branch = branch_get(argv[0]);
> +
> +		if (!ref_exists(branch->refname))
> +		  die(_("branch '%s' does not exist"), branch->name);

Indentation (2 spaces -> tab).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/3] branch: introduce --set-upstream-to
  2012-07-10 16:52 [PATCH 0/3] A better way of handling upstream information in git-branch Carlos Martín Nieto
@ 2012-07-10 16:52 ` Carlos Martín Nieto
  2012-07-10 17:08   ` Matthieu Moy
                     ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Carlos Martín Nieto @ 2012-07-10 16:52 UTC (permalink / raw)
  To: git; +Cc: jrnieder, gitster

The existing --set-uptream option can cause confusion, as it uses the
usual branch convention of assuming a starting point of HEAD if none
is specified, causing

    git branch --set-upstream origin/master

to create a new local branch 'origin/master' that tracks the current
branch. As --set-upstream already exists, we can't simply change its
behaviour. To work around this, introduce --set-upstream-to which
accepts a compulsory argument indicating what the new upstream branch
should be and one optinal argument indicating which branch to change,
defaulting to HEAD.

The new options allows us to type

    git branch --set-upstream-to origin/master

to set the current branch's upstream to be origin's master.
---
 Documentation/git-branch.txt |    9 ++++++++-
 builtin/branch.c             |   15 +++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 47235be..0f33fc7 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -13,6 +13,7 @@ SYNOPSIS
 	[--column[=<options>] | --no-column]
 	[(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
+'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
 'git branch' (-m | -M) [<oldbranch>] <newbranch>
 'git branch' (-d | -D) [-r] <branchname>...
 'git branch' --edit-description [<branchname>]
@@ -48,7 +49,7 @@ branch so that 'git pull' will appropriately merge from
 the remote-tracking branch. This behavior may be changed via the global
 `branch.autosetupmerge` configuration flag. That setting can be
 overridden by using the `--track` and `--no-track` options, and
-changed later using `git branch --set-upstream`.
+changed later using `git branch --set-upstream-to`.
 
 With a `-m` or `-M` option, <oldbranch> will be renamed to <newbranch>.
 If <oldbranch> had a corresponding reflog, it is renamed to match
@@ -173,6 +174,12 @@ start-point is either a local or remote-tracking branch.
 	like `--track` would when creating the branch, except that where
 	branch points to is not changed.
 
+-u <upstream>::
+--set-upstream-to=<upstream>::
+	Set up <branchname>'s tracking information so <upstream> is
+	considered <branchname>'s upstream branch. If no branch is
+	specified it defaults to the current branch.
+
 --edit-description::
 	Open an editor and edit the text to explain what the branch is
 	for, to be used by various other commands (e.g. `request-pull`).
diff --git a/builtin/branch.c b/builtin/branch.c
index 0e060f2..c886fc0 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -713,6 +713,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	int verbose = 0, abbrev = -1, detached = 0;
 	int reflog = 0, edit_description = 0;
 	int quiet = 0;
+	const char *new_upstream = NULL;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
 	struct commit_list *with_commit = NULL;
@@ -726,6 +727,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			BRANCH_TRACK_EXPLICIT),
 		OPT_SET_INT( 0, "set-upstream",  &track, "change upstream info",
 			BRANCH_TRACK_OVERRIDE),
+		OPT_STRING('u', "set-upstream-to", &new_upstream, "upstream", "change the upstream info"),
 		OPT__COLOR(&branch_use_color, "use colored output"),
 		OPT_SET_INT('r', "remotes",     &kinds, "act on remote-tracking branches",
 			REF_REMOTE_BRANCH),
@@ -794,10 +796,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
 			     0);
 
-	if (!delete && !rename && !edit_description && argc == 0)
+	if (!delete && !rename && !edit_description && !new_upstream && argc == 0)
 		list = 1;
 
-	if (!!delete + !!rename + !!force_create + !!list > 1)
+	if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > 1)
 		usage_with_options(builtin_branch_usage, options);
 
 	if (abbrev == -1)
@@ -852,6 +854,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			rename_branch(argv[0], argv[1], rename > 1);
 		else
 			usage_with_options(builtin_branch_usage, options);
+	} else if (new_upstream) {
+		struct branch *branch = branch_get(argv[0]);
+
+		if (!ref_exists(branch->refname))
+		  die(_("branch '%s' does not exist"), branch->name);
+
+		/* create_branch takes care of setting up the tracking
+		   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) {
 		if (kinds != REF_LOCAL_BRANCH)
 			die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
-- 
1.7.10.2.1.g8c77c3c

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2012-09-01 15:14 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-30 17:23 [PATCHv2 0/3] Improve branch UI for setting upstream information Carlos Martín Nieto
2012-08-30 17:23 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
2012-08-30 17:51   ` Ralf Thielow
2012-08-31 15:22     ` Carlos Martín Nieto
2012-08-31 15:30       ` Ralf Thielow
2012-08-31 17:09         ` Junio C Hamano
2012-09-01 15:13           ` Carlos Martín Nieto
2012-08-30 17:23 ` [PATCH 2/3] branch: add --unset-upstream option Carlos Martín Nieto
2012-08-30 17:23 ` [PATCH 3/3] branch: deprecate --set-upstream and show help if we detect possible mistaken use Carlos Martín Nieto
2012-08-30 17:37 ` [PATCHv2 0/3] Improve branch UI for setting upstream information Junio C Hamano
2012-08-30 18:57   ` Carlos Martín Nieto
2012-08-30 20:12     ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2012-08-20 13:47 [PATCH " Carlos Martín Nieto
2012-08-20 13:47 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
2012-07-10 16:52 [PATCH 0/3] A better way of handling upstream information in git-branch Carlos Martín Nieto
2012-07-10 16:52 ` [PATCH 1/3] branch: introduce --set-upstream-to Carlos Martín Nieto
2012-07-10 17:08   ` Matthieu Moy
2012-07-10 17:26   ` Junio C Hamano
2012-07-10 19:13   ` Jonathan Nieder
2012-07-10 19:49     ` Junio C Hamano
2012-07-10 20:11       ` Jonathan Nieder
2012-07-10 20:49         ` Junio C Hamano
2012-07-10 21:09           ` Jonathan Nieder
2012-07-10 23:13             ` Junio C Hamano
2012-07-10 23:47               ` Jonathan Nieder
2012-07-11  1:20                 ` Junio C Hamano
2012-07-11  1:37                   ` Jonathan Nieder
2012-07-12  8:41                   ` Miles Bader
2012-07-12 16:58                     ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.