{"thread":{"id":"1526","subject":"[PATCH] Add git-branches-script","startedAt":"2005-08-15T20:44:30Z","lastAt":"2005-08-17T20:37:58Z","messageCount":7,"participants":["Amos Waterland","Kalle Valo","Junio C Hamano","Miguel Bazdresch"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7313","messageId":"20050815204430.GA77829@rossby.metr.ou.edu","threadId":"1526","inReplyTo":null,"subject":"[PATCH] Add git-branches-script","fromName":"Amos Waterland","fromEmail":"apw@rossby.metr.ou.edu","sentAt":"2005-08-15T20:44:30Z","receivedAt":"2005-08-15T20:44:30Z","isPatch":true,"sender":{"key":"apw@debian.org","avatar":null},"body":"For people whose workflow involves switching back and forth between a\nlot of branches, it can be really helpful to be able to quickly tell\nwhich branch you are on and which ones are available.  This patch\nintroduces a small script that when invoked as `git branches' prints a\nlist of available branches with a star in front of the one you are on:\n\n $ cd linux-2.6/\n $ git checkout -b ppc64-cleanups\n $ git checkout -b ppc64-new-devel\n $ git checkout -b ppc64-all-merge\n $ git branches\n   master\n * ppc64-all-merge\n   ppc64-cleanups\n   ppc64-new-devel\n\nSigned-off-by: Amos Waterland <apw@rossby.metr.ou.edu>\n\n---\n\n git-branches-script |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n create mode 100755 git-branches-script\n\n12ab86f36137c4ffd1fb9b878479b9befe4cf2d4\ndiff --git a/git-branches-script b/git-branches-script\nnew file mode 100755\n--- /dev/null\n+++ b/git-branches-script\n@@ -0,0 +1,8 @@\n+#!/bin/sh\n+\n+. git-sh-setup-script || die \"Not a git archive\"\n+\n+current=$(basename $(readlink $GIT_DIR/HEAD))\n+\n+cd $GIT_DIR/refs/heads &&\n+ls | sed -e \"s/^/  /\" -e \"s/  $current/* $current/\"\n"},{"id":"7369","messageId":"87hddplqdu.fsf@litku.valo.iki.fi","threadId":"1526","inReplyTo":"20050815204430.GA77829@rossby.metr.ou.edu","subject":"Re: [PATCH] Add git-branches-script","fromName":"Kalle Valo","fromEmail":"kalle.valo@iki.fi","sentAt":"2005-08-16T17:53:49Z","receivedAt":"2005-08-16T17:53:49Z","isPatch":true,"sender":{"key":"kalle.valo@iki.fi","avatar":null},"body":"Amos Waterland <apw@rossby.metr.ou.edu> writes:\n\n> For people whose workflow involves switching back and forth between a\n> lot of branches, it can be really helpful to be able to quickly tell\n> which branch you are on and which ones are available.  This patch\n> introduces a small script that when invoked as `git branches' prints a\n> list of available branches with a star in front of the one you are on:\n>\n>  $ cd linux-2.6/\n>  $ git checkout -b ppc64-cleanups\n>  $ git checkout -b ppc64-new-devel\n>  $ git checkout -b ppc64-all-merge\n>  $ git branches\n>    master\n>  * ppc64-all-merge\n>    ppc64-cleanups\n>    ppc64-new-devel\n\nI would prefer to using some git command compared to 'ls -l\n.git/refs/heads/'. In my opinion there is a need for this command and\nit should be included.\n\nBut my immediate concern was that there is already 'git branch'\ncommand and 'git branches' is too similar. I think they should be\nmerged. I have a patch coming up.\n\n-- \nKalle Valo\n"},{"id":"7370","messageId":"87d5odlq6l.fsf_-_@litku.valo.iki.fi","threadId":"1526","inReplyTo":"87hddplqdu.fsf@litku.valo.iki.fi","subject":"[PATCH] Change git-branch to list branches","fromName":"Kalle Valo","fromEmail":"kalle.valo@iki.fi","sentAt":"2005-08-16T17:58:10Z","receivedAt":"2005-08-16T17:58:10Z","isPatch":true,"sender":{"key":"kalle.valo@iki.fi","avatar":null},"body":"If no argument provided to `git branch`, show available branches and\nmark current branch with star.\n\nThis is based on patch written by Amos Waterland <apw@rossby.metr.ou.edu>.\n\nSigned-off-by: Kalle Valo <Kalle.Valo@iki.fi>\n---\n\n git-branch-script |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\n38aca3bb4ad4e6b0e10e295a87a9f5ce37ff5be4\ndiff --git a/git-branch-script b/git-branch-script\n--- a/git-branch-script\n+++ b/git-branch-script\n@@ -11,7 +11,13 @@ case \"$2\" in\n esac\n rev=$(git-rev-parse --revs-only --verify \"$head\") || exit\n \n-[ -z \"$branchname\" ] && die \"git branch: I want a branch name\"\n+if [ -z \"$branchname\" ]; then\n+    current=$(basename $(readlink $GIT_DIR/HEAD))\n+    cd $GIT_DIR/refs/heads &&\n+    ls | sed -e \"s/^/  /\" -e \"s/  $current/* $current/\"\n+    exit\n+fi\n+\n [ -e \"$GIT_DIR/refs/heads/$branchname\" ] && die \"$branchname already exists\"\n \n echo $rev > \"$GIT_DIR/refs/heads/$branchname\"\n"},{"id":"7382","messageId":"7vslx98ua0.fsf@assigned-by-dhcp.cox.net","threadId":"1526","inReplyTo":"87d5odlq6l.fsf_-_@litku.valo.iki.fi","subject":"Re: [PATCH] Change git-branch to list branches","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-16T21:08:07Z","receivedAt":"2005-08-16T21:08:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kalle Valo <Kalle.Valo@iki.fi> writes:\n\n> If no argument provided to `git branch`, show available branches and\n> mark current branch with star.\n\nI like the general direction, but this particular implementation\nmay be a bit troublesome.\n\n> +if [ -z \"$branchname\" ]; then\n> +    current=$(basename $(readlink $GIT_DIR/HEAD))\n> +    cd $GIT_DIR/refs/heads &&\n> +    ls | sed -e \"s/^/  /\" -e \"s/  $current/* $current/\"\n> +    exit\n> +fi\n\nI do not think we have agreed to limit ourselves to a flat\nnamespace under refs/heads without subdirectories.  Something\nlike what git-show-branches-script does when $# == 0, perhaps?\n"},{"id":"7461","messageId":"87br3w73at.fsf@litku.valo.iki.fi","threadId":"1526","inReplyTo":"7vslx98ua0.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Change git-branch to list branches","fromName":"Kalle Valo","fromEmail":"kalle.valo@iki.fi","sentAt":"2005-08-17T19:48:26Z","receivedAt":"2005-08-17T19:48:26Z","isPatch":true,"sender":{"key":"kalle.valo@iki.fi","avatar":null},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> I do not think we have agreed to limit ourselves to a flat\n> namespace under refs/heads without subdirectories.  Something\n> like what git-show-branches-script does when $# == 0, perhaps?\n\nI didn't realise this. I'll send a revised patch soon.\n\n-- \nKalle Valo\n"},{"id":"7467","messageId":"871x4s7221.fsf@litku.valo.iki.fi","threadId":"1526","inReplyTo":"87br3w73at.fsf@litku.valo.iki.fi","subject":"Re: [PATCH] Change git-branch to list branches","fromName":"Kalle Valo","fromEmail":"kalle.valo@iki.fi","sentAt":"2005-08-17T20:15:18Z","receivedAt":"2005-08-17T20:15:18Z","isPatch":true,"sender":{"key":"kalle.valo@iki.fi","avatar":null},"body":"Kalle Valo <Kalle.Valo@iki.fi> writes:\n\n> Junio C Hamano <junkio@cox.net> writes:\n>\n>> I do not think we have agreed to limit ourselves to a flat\n>> namespace under refs/heads without subdirectories.  Something\n>> like what git-show-branches-script does when $# == 0, perhaps?\n>\n> I didn't realise this. I'll send a revised patch soon.\n\nAh, but you fixed it already. Thanks!\n\n-- \nKalle Valo\n"},{"id":"7469","messageId":"20050817203758.GA1332@localhost.domain.invalid","threadId":"1526","inReplyTo":"20050815204430.GA77829@rossby.metr.ou.edu","subject":"Re: [PATCH] Add git-branches-script","fromName":"Miguel Bazdresch","fromEmail":"monotone-01@thewizardstower.org","sentAt":"2005-08-17T20:37:58Z","receivedAt":"2005-08-17T20:37:58Z","isPatch":true,"sender":{"key":"monotone-01@thewizardstower.org","avatar":null},"body":"* Amos Waterland <apw@rossby.metr.ou.edu> [2005-08-16 00:48]:\n> For people whose workflow involves switching back and forth between a\n> lot of branches, it can be really helpful to be able to quickly tell\n> which branch you are on and which ones are available.  This patch\n> introduces a small script that when invoked as `git branches' prints a\n> list of available branches with a star in front of the one you are on:\n> \n>  $ cd linux-2.6/\n>  $ git checkout -b ppc64-cleanups\n>  $ git checkout -b ppc64-new-devel\n>  $ git checkout -b ppc64-all-merge\n>  $ git branches\n>    master\n>  * ppc64-all-merge\n>    ppc64-cleanups\n>    ppc64-new-devel\n\nSome might find it useful to put Amos' script in a bash function and\nthen put the current branch in the prompt. What I did was to put this\nfunction in my .bashrc:\n\ngitbranch () {\n\t. git-sh-setup-script &&\n\tbranch=$(basename $(readlink $GIT_DIR/HEAD)) &&\n\techo -n \"\" $branch \"\"\n}\n\nThen I modified my bash prompt:\n\nexport PS1='\\[\\033[1;31m\\]\\j$(gitbranch)[\\w]\\$ \\[\\033[0m\\]'\n                            ^^^^^^^^^^^\n\nNow, if my current dir is not a git repo, I have my regular prompt. As\nsoon as I cd into a git repo, I get the current branch in the prompt, as\nfollows:\n\n0[~]$ cd gitrepo\n0 master [~/gitrepo]$ git checkout branch1\n0 branch1 [~/gitrepo]$ cd ..\n0[~]$\n\n-- \nMiguel Bazdresch\nhttp://thewizardstower.org/\n"}]}