From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Subject: [PATCH 1/3] branch: introduce --set-upstream-to Date: Mon, 20 Aug 2012 15:47:38 +0200 Message-ID: <1345470460-28734-2-git-send-email-cmn@elego.de> References: <1345470460-28734-1-git-send-email-cmn@elego.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Mon Aug 20 16:01:40 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T3SXy-0003Bz-Ff for gcvg-git-2@plane.gmane.org; Mon, 20 Aug 2012 16:01:39 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756509Ab2HTOAS convert rfc822-to-quoted-printable (ORCPT ); Mon, 20 Aug 2012 10:00:18 -0400 Received: from hessy.cmartin.tk ([78.47.67.53]:47720 "EHLO hessy.dwim.me" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755100Ab2HTN4R (ORCPT ); Mon, 20 Aug 2012 09:56:17 -0400 X-Greylist: delayed 515 seconds by postgrey-1.27 at vger.kernel.org; Mon, 20 Aug 2012 09:56:16 EDT Received: from flaca.cmartin.tk (i59F7870A.versanet.de [89.247.135.10]) by hessy.dwim.me (Postfix) with ESMTPA id 0A6C7805D0 for ; Mon, 20 Aug 2012 15:47:41 +0200 (CEST) Received: (nullmailer pid 28775 invoked by uid 1000); Mon, 20 Aug 2012 13:47:40 -0000 X-Mailer: git-send-email 1.7.11.1.104.ge7b44f1 In-Reply-To: <1345470460-28734-1-git-send-email-cmn@elego.de> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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=C3=ADn Nieto --- 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.tx= t index 47235be..e41c4b5 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -13,6 +13,7 @@ SYNOPSIS [--column[=3D] | --no-column] [(--merged | --no-merged | --contains) []] [...] 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] [] +'git branch' (--set-upstream-to=3D | -u ) [] 'git branch' (-m | -M) [] 'git branch' (-d | -D) [-r] ... 'git branch' --edit-description [] @@ -48,7 +49,7 @@ branch so that 'git pull' will appropriately merge fr= om the remote-tracking branch. This behavior may be changed via the globa= l `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`. =20 With a `-m` or `-M` option, will be renamed to = =2E If had a corresponding reflog, it is renamed to match @@ -173,6 +174,12 @@ start-point is either a local or remote-tracking b= ranch. like `--track` would when creating the branch, except that where branch points to is not changed. =20 +-u :: +--set-upstream-to=3D:: + Set up 's tracking information so is + considered 's upstream branch. If no + 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 c= har *prefix) int verbose =3D 0, abbrev =3D -1, detached =3D 0; int reflog =3D 0, edit_description =3D 0; int quiet =3D 0; + const char *new_upstream =3D NULL; enum branch_track track; int kinds =3D REF_LOCAL_BRANCH; struct commit_list *with_commit =3D NULL; @@ -726,6 +727,7 @@ int cmd_branch(int argc, const char **argv, const c= har *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", "chang= e the upstream info"), OPT__COLOR(&branch_use_color, "use colored output"), OPT_SET_INT('r', "remotes", &kinds, "act on remote-tracking bran= ches", REF_REMOTE_BRANCH), @@ -794,10 +796,10 @@ int cmd_branch(int argc, const char **argv, const= char *prefix) argc =3D parse_options(argc, argv, prefix, options, builtin_branch_us= age, 0); =20 - if (!delete && !rename && !edit_description && argc =3D=3D 0) + if (!delete && !rename && !edit_description && !new_upstream && argc = =3D=3D 0) list =3D 1; =20 - if (!!delete + !!rename + !!force_create + !!list > 1) + if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > = 1) usage_with_options(builtin_branch_usage, options); =20 if (abbrev =3D=3D -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 =3D 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, BRAN= CH_TRACK_OVERRIDE); } else if (argc > 0 && argc <=3D 2) { if (kinds !=3D REF_LOCAL_BRANCH) die(_("-a and -r options to 'git branch' do not make sense with a b= ranch 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' =20 +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)" =3D "." && + test "$(git config branch.master.merge)" =3D "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)" =3D "." && + test "$(git config branch.my13.merge)" =3D "refs/heads/master"' + # Keep this test last, as it changes the current branch cat >expect < 1117150200 +000= 0 branch: Created from master --=20 1.7.11.1.104.ge7b44f1