{"thread":{"id":"5945","subject":"[PATCHv2] git-branch: Set branch properties","startedAt":"2006-10-17T14:47:07Z","lastAt":"2006-10-17T14:47:07Z","messageCount":1,"participants":["Santi Béjar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"28967","messageId":"87y7rf80es.fsf@gmail.com","threadId":"5945","inReplyTo":null,"subject":"[PATCHv2] git-branch: Set branch properties","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2006-10-17T14:47:07Z","receivedAt":"2006-10-17T14:47:07Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"\nAdded a flag to git-branch (-c) that makes git-branch to write the\nconfig (branch properties) for the new branch so it will pull the same\nbranch it branched from.\n\nIf you want to work in the 'next' branch of git.git:\n\n$ git clone git://git.kernel.org/pub/scm/git/git.git\n$ cd git\n$ git branch -c mynext origin next\n$ tail -n 3 .git/config\n[branch \"mynext\"]\n        remote = origin\n        merge = refs/heads/next\n$ git branch -c secondnext next\n$ tail -n 3 .git/config\n[branch \"secondnext\"]\n        remote = .\n        merge = next\n\nSigned-off-by: Santi Béjar <sbejar@gmail.com>\n---\n\n Hi,\n\n   it needs the get_ref_for_remote_branch function in\n   git-parse-remote.sh that is with the patch:\n\n   [RFC/PATCH] git-fetch: Use already fetched branch with the --local\n   flag\n\n   Also, this does not apply cleanly in next, the change in next is and\n   the resolution trivial:\n\n <\trm -f \"$GIT_DIR/logs/refs/heads/$branch_name\"\n <\trm -f \"$GIT_DIR/refs/heads/$branch_name\"\n >\tgit update-ref -d \"refs/heads/$branch_name\" \"$branch\"\n\n What I have to do? Send the postimage or what?\n\n Another questions is about rerere: Can it be done at the hunk level? We\n could record the git-patch-id of the conflict and the postimage.\n\n Documentation/git-branch.txt |   12 ++++++++++--\n git-branch.sh                |   30 +++++++++++++++++++++++++++---\n 2 files changed, 37 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex d43ef1d..77bbf81 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -9,7 +9,7 @@ SYNOPSIS\n --------\n [verse]\n 'git-branch' [-r]\n-'git-branch' [-l] [-f] <branchname> [<start-point>]\n+'git-branch' [-l] [-f] [-c] <branchname> [<start-point> | <remote> <remotebranch>]\n 'git-branch' (-d | -D) <branchname>...\n \n DESCRIPTION\n@@ -18,7 +18,8 @@ With no arguments given (or just `-r`) a\n will be shown, the current branch will be highlighted with an asterisk.\n \n In its second form, a new branch named <branchname> will be created.\n-It will start out with a head equal to the one given as <start-point>.\n+It will start out with a head equal to the one given as <start-point>,\n+or from branch <remotebranch> of the repository <remote>.\n If no <start-point> is given, the branch will be created with a head\n equal to that of the currently checked out branch.\n \n@@ -26,9 +27,16 @@ With a `-d` or `-D` option, `<branchname\n specify more than one branch for deletion.  If the branch currently\n has a ref log then the ref log will also be deleted.\n \n+With a `-c` option, the branch properties `branch.<branchname>.remote`\n+and `branch.<branchname>.merge` will be set.\n+\n \n OPTIONS\n -------\n+-c::\n+\tWrite the branch properties `branch.<branchname>.remote`\n+\tand `branch.<branchname>.merge`.\n+\n -d::\n \tDelete a branch. The branch must be fully merged.\n \ndiff --git a/git-branch.sh b/git-branch.sh\nindex 4f31903..afd768a 100755\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -1,9 +1,10 @@\n #!/bin/sh\n \n-USAGE='[-l] [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r'\n+USAGE='[-l] [(-d | -D) <branchname>] | [[-f] [-c] <branchname> [<start-point> | <remote> <remotebranch>]] | -r'\n LONG_USAGE='If no arguments, show available branches and mark current branch with a star.\n If one argument, create a new branch <branchname> based off of current HEAD.\n-If two arguments, create a new branch <branchname> based off of <start-point>.'\n+If two arguments, create a new branch <branchname> based off of <start-point>.\n+If three arguments, create a new branch <branchname> based off the branch <remotebranch> of the repository <remote>.'\n \n SUBDIRECTORY_OK='Yes'\n . git-sh-setup\n@@ -44,6 +45,8 @@ If you are sure you want to delete it, r\n \tesac\n \trm -f \"$GIT_DIR/logs/refs/heads/$branch_name\"\n \trm -f \"$GIT_DIR/refs/heads/$branch_name\"\n+\tgit repo-config --unset branch.\"$branchname\".remote\n+\tgit repo-config --unset-all branch.\"$branchname\".merge\n \techo \"Deleted branch $branch_name.\"\n     done\n     exit 0\n@@ -71,6 +74,9 @@ do\n \t-f)\n \t\tforce=\"$1\"\n \t\t;;\n+\t-c)\n+\t\tconfig=\"yes\"\n+\t\t;;\n \t-l)\n \t\tcreate_log=\"yes\"\n \t\t;;\n@@ -101,9 +107,21 @@ case \"$#\" in\n \tdone\n \texit 0 ;;\n 1)\n+\tremote=\".\"\n+\tremote_branch=\"$headref\"\n \thead=HEAD ;;\n 2)\n+\tremote=\".\"\n+\tremote_branch=\"$2\"\n \thead=\"$2^0\" ;;\n+3)\n+\tremote=\"$2\"\n+\tremote_branch=\"$3\"\n+\t. git-parse-remote\n+\tref=$(get_ref_for_remote_branch \"$remote\" \"$remote_branch\")\n+\t[ -z \"$ref\" ] && remote_branch=\"refs/heads/$remote_branch\" && \\\n+\t\tref=$(get_ref_for_remote_branch \"$remote\" \"$remote_branch\")\n+\thead=\"$ref^0\";;\n esac\n branchname=\"$1\"\n \n@@ -137,4 +155,10 @@ then\n \tmkdir -p $(dirname \"$GIT_DIR/logs/refs/heads/$branchname\")\n \ttouch \"$GIT_DIR/logs/refs/heads/$branchname\"\n fi\n-git update-ref -m \"branch: Created from $head\" \"refs/heads/$branchname\" $rev\n+git update-ref -m \"branch: Created from $head\" \"refs/heads/$branchname\" $rev || exit $?\n+\n+if test \"$config\" = \"yes\"\n+then\n+\tgit repo-config branch.\"$branchname\".remote \"$remote\"\n+\tgit repo-config branch.\"$branchname\".merge \"$remote_branch\"\n+fi\n-- \n1.4.2.4.g687a-dirty\n"}]}