summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-07-05 23:19:37 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2007-07-09 01:12:56 (GMT)
commit311e02a4a5c7b82c996214f06d58e2b51b3ecc22 (patch)
tree6036fbe6fc3fe2a621ba7d7cf235ab6d987947f6
parentba1964be26b8b9e3441591257a2c87f5811d6b50 (diff)
downloadgit-311e02a4a5c7b82c996214f06d58e2b51b3ecc22.zip
git-311e02a4a5c7b82c996214f06d58e2b51b3ecc22.tar.gz
git-311e02a4a5c7b82c996214f06d58e2b51b3ecc22.tar.bz2
git-gui: Better handling of detached HEAD
If the current branch is not a symbolic-ref that points to a name in the refs/heads/ namespace we now just assume that the head is a detached head. In this case we return the special branch name of HEAD rather than empty string, as HEAD is a valid revision specification and the empty string is not. I have also slightly improved the current-branch function by using string functions to parse the symbolic-ref data. This should be slightly faster than using a regsub. I think the code is clearer too. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rwxr-xr-xgit-gui.sh18
1 files changed, 14 insertions, 4 deletions
diff --git a/git-gui.sh b/git-gui.sh
index 99df2d9..516bd97 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -285,14 +285,24 @@ proc git {args} {
}
proc current-branch {} {
- set ref {}
set fd [open [gitdir HEAD] r]
- if {[gets $fd ref] <16
- || ![regsub {^ref: refs/heads/} $ref {} ref]} {
+ if {[gets $fd ref] < 1} {
set ref {}
}
close $fd
- return $ref
+
+ set pfx {ref: refs/heads/}
+ set len [string length $pfx]
+ if {[string equal -length $len $pfx $ref]} {
+ # We're on a branch. It might not exist. But
+ # HEAD looks good enough to be a branch.
+ #
+ return [string range $ref $len end]
+ } else {
+ # Assume this is a detached head.
+ #
+ return HEAD
+ }
}
auto_load tk_optionMenu