Thread (9 messages) 9 messages, 4 authors, 2016-06-15

Re: [PATCH 2/2] [TopGit] Portability: Don't use alternation ("|") in sed regular expressions

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:22

Brian Campbell [off-list ref] writes:
+current_branch()
+{
+	echo "$(git symbolic-ref HEAD | sed -e 's#^refs/heads/##' -e 's#^refs/top-bases/##')"
+}
Two micronits.

 - what happens when you are on a detached HEAD?

 - You will be utterly confused by a local branch whose name is
   "refs/top-bases/foo"

To fix these, you might want to do something like:

	if head_=$(git symbolic-ref HEAD)
        then
                case "$head_" in
                refs/heads/*)
                        echo "${head_#refs/heads/}"
                        ;;
                refs/top-bases/*)
                        echo "${head_#refs/top-bases/}"
                        ;;
                *)
                        echo "$head_"
                        ;;
                esac
	else
        	whatever you want to do on a detached HEAD
	fi
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help