* [PATCH] Add git-branches-script
@ 2005-08-15 20:44 Amos Waterland
2005-08-16 17:53 ` Kalle Valo
2005-08-17 20:37 ` [PATCH] Add git-branches-script Miguel Bazdresch
0 siblings, 2 replies; 7+ messages in thread
From: Amos Waterland @ 2005-08-15 20:44 UTC (permalink / raw)
To: junkio; +Cc: git
For people whose workflow involves switching back and forth between a
lot of branches, it can be really helpful to be able to quickly tell
which branch you are on and which ones are available. This patch
introduces a small script that when invoked as `git branches' prints a
list of available branches with a star in front of the one you are on:
$ cd linux-2.6/
$ git checkout -b ppc64-cleanups
$ git checkout -b ppc64-new-devel
$ git checkout -b ppc64-all-merge
$ git branches
master
* ppc64-all-merge
ppc64-cleanups
ppc64-new-devel
Signed-off-by: Amos Waterland <apw@rossby.metr.ou.edu>
---
git-branches-script | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
create mode 100755 git-branches-script
12ab86f36137c4ffd1fb9b878479b9befe4cf2d4
diff --git a/git-branches-script b/git-branches-script
new file mode 100755
--- /dev/null
+++ b/git-branches-script
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+. git-sh-setup-script || die "Not a git archive"
+
+current=$(basename $(readlink $GIT_DIR/HEAD))
+
+cd $GIT_DIR/refs/heads &&
+ls | sed -e "s/^/ /" -e "s/ $current/* $current/"
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Add git-branches-script
2005-08-15 20:44 [PATCH] Add git-branches-script Amos Waterland
@ 2005-08-16 17:53 ` Kalle Valo
2005-08-16 17:58 ` [PATCH] Change git-branch to list branches Kalle Valo
2005-08-17 20:37 ` [PATCH] Add git-branches-script Miguel Bazdresch
1 sibling, 1 reply; 7+ messages in thread
From: Kalle Valo @ 2005-08-16 17:53 UTC (permalink / raw)
To: Amos Waterland; +Cc: junkio, git
Amos Waterland <apw@rossby.metr.ou.edu> writes:
> For people whose workflow involves switching back and forth between a
> lot of branches, it can be really helpful to be able to quickly tell
> which branch you are on and which ones are available. This patch
> introduces a small script that when invoked as `git branches' prints a
> list of available branches with a star in front of the one you are on:
>
> $ cd linux-2.6/
> $ git checkout -b ppc64-cleanups
> $ git checkout -b ppc64-new-devel
> $ git checkout -b ppc64-all-merge
> $ git branches
> master
> * ppc64-all-merge
> ppc64-cleanups
> ppc64-new-devel
I would prefer to using some git command compared to 'ls -l
.git/refs/heads/'. In my opinion there is a need for this command and
it should be included.
But my immediate concern was that there is already 'git branch'
command and 'git branches' is too similar. I think they should be
merged. I have a patch coming up.
--
Kalle Valo
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] Change git-branch to list branches
2005-08-16 17:53 ` Kalle Valo
@ 2005-08-16 17:58 ` Kalle Valo
2005-08-16 21:08 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Kalle Valo @ 2005-08-16 17:58 UTC (permalink / raw)
To: Amos Waterland; +Cc: junkio, git
If no argument provided to `git branch`, show available branches and
mark current branch with star.
This is based on patch written by Amos Waterland <apw@rossby.metr.ou.edu>.
Signed-off-by: Kalle Valo <Kalle.Valo@iki.fi>
---
git-branch-script | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
38aca3bb4ad4e6b0e10e295a87a9f5ce37ff5be4
diff --git a/git-branch-script b/git-branch-script
--- a/git-branch-script
+++ b/git-branch-script
@@ -11,7 +11,13 @@ case "$2" in
esac
rev=$(git-rev-parse --revs-only --verify "$head") || exit
-[ -z "$branchname" ] && die "git branch: I want a branch name"
+if [ -z "$branchname" ]; then
+ current=$(basename $(readlink $GIT_DIR/HEAD))
+ cd $GIT_DIR/refs/heads &&
+ ls | sed -e "s/^/ /" -e "s/ $current/* $current/"
+ exit
+fi
+
[ -e "$GIT_DIR/refs/heads/$branchname" ] && die "$branchname already exists"
echo $rev > "$GIT_DIR/refs/heads/$branchname"
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Change git-branch to list branches
2005-08-16 17:58 ` [PATCH] Change git-branch to list branches Kalle Valo
@ 2005-08-16 21:08 ` Junio C Hamano
2005-08-17 19:48 ` Kalle Valo
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2005-08-16 21:08 UTC (permalink / raw)
To: Kalle Valo; +Cc: Amos Waterland, junkio, git
Kalle Valo <Kalle.Valo@iki.fi> writes:
> If no argument provided to `git branch`, show available branches and
> mark current branch with star.
I like the general direction, but this particular implementation
may be a bit troublesome.
> +if [ -z "$branchname" ]; then
> + current=$(basename $(readlink $GIT_DIR/HEAD))
> + cd $GIT_DIR/refs/heads &&
> + ls | sed -e "s/^/ /" -e "s/ $current/* $current/"
> + exit
> +fi
I do not think we have agreed to limit ourselves to a flat
namespace under refs/heads without subdirectories. Something
like what git-show-branches-script does when $# == 0, perhaps?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Change git-branch to list branches
2005-08-16 21:08 ` Junio C Hamano
@ 2005-08-17 19:48 ` Kalle Valo
2005-08-17 20:15 ` Kalle Valo
0 siblings, 1 reply; 7+ messages in thread
From: Kalle Valo @ 2005-08-17 19:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano <junkio@cox.net> writes:
> I do not think we have agreed to limit ourselves to a flat
> namespace under refs/heads without subdirectories. Something
> like what git-show-branches-script does when $# == 0, perhaps?
I didn't realise this. I'll send a revised patch soon.
--
Kalle Valo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Change git-branch to list branches
2005-08-17 19:48 ` Kalle Valo
@ 2005-08-17 20:15 ` Kalle Valo
0 siblings, 0 replies; 7+ messages in thread
From: Kalle Valo @ 2005-08-17 20:15 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Kalle Valo <Kalle.Valo@iki.fi> writes:
> Junio C Hamano <junkio@cox.net> writes:
>
>> I do not think we have agreed to limit ourselves to a flat
>> namespace under refs/heads without subdirectories. Something
>> like what git-show-branches-script does when $# == 0, perhaps?
>
> I didn't realise this. I'll send a revised patch soon.
Ah, but you fixed it already. Thanks!
--
Kalle Valo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Add git-branches-script
2005-08-15 20:44 [PATCH] Add git-branches-script Amos Waterland
2005-08-16 17:53 ` Kalle Valo
@ 2005-08-17 20:37 ` Miguel Bazdresch
1 sibling, 0 replies; 7+ messages in thread
From: Miguel Bazdresch @ 2005-08-17 20:37 UTC (permalink / raw)
To: git
* Amos Waterland <apw@rossby.metr.ou.edu> [2005-08-16 00:48]:
> For people whose workflow involves switching back and forth between a
> lot of branches, it can be really helpful to be able to quickly tell
> which branch you are on and which ones are available. This patch
> introduces a small script that when invoked as `git branches' prints a
> list of available branches with a star in front of the one you are on:
>
> $ cd linux-2.6/
> $ git checkout -b ppc64-cleanups
> $ git checkout -b ppc64-new-devel
> $ git checkout -b ppc64-all-merge
> $ git branches
> master
> * ppc64-all-merge
> ppc64-cleanups
> ppc64-new-devel
Some might find it useful to put Amos' script in a bash function and
then put the current branch in the prompt. What I did was to put this
function in my .bashrc:
gitbranch () {
. git-sh-setup-script &&
branch=$(basename $(readlink $GIT_DIR/HEAD)) &&
echo -n "" $branch ""
}
Then I modified my bash prompt:
export PS1='\[\033[1;31m\]\j$(gitbranch)[\w]\$ \[\033[0m\]'
^^^^^^^^^^^
Now, if my current dir is not a git repo, I have my regular prompt. As
soon as I cd into a git repo, I get the current branch in the prompt, as
follows:
0[~]$ cd gitrepo
0 master [~/gitrepo]$ git checkout branch1
0 branch1 [~/gitrepo]$ cd ..
0[~]$
--
Miguel Bazdresch
http://thewizardstower.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-08-17 20:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-15 20:44 [PATCH] Add git-branches-script Amos Waterland
2005-08-16 17:53 ` Kalle Valo
2005-08-16 17:58 ` [PATCH] Change git-branch to list branches Kalle Valo
2005-08-16 21:08 ` Junio C Hamano
2005-08-17 19:48 ` Kalle Valo
2005-08-17 20:15 ` Kalle Valo
2005-08-17 20:37 ` [PATCH] Add git-branches-script Miguel Bazdresch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).