zsh-workers
 help / Atom feed
* [PATCH] vcs_info git: Fix fatal error in VCS_INFO_git_getbranch in corner case
@ 2018-12-09 19:41 Daniel Shahaf
  0 siblings, 0 replies; 1+ messages in thread
From: Daniel Shahaf @ 2018-12-09 19:41 UTC (permalink / raw)
  To: zsh-workers

Before this commit, the following use-case:

    git checkout foo^
    git show foo | git am

would result in a fatal error, with vcs_info_msg_N_ not set:

    VCS_INFO_git_getbranch:18: no such file or directory: .git/rebase-apply/onto

Now they are set correctly, and HEAD's commit hash is used.
---
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 7ae2c0b27..ceb4f978a 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -89,7 +89,7 @@ VCS_INFO_git_getbranch () {
         gitbranch="$(${(z)gitsymref} 2> /dev/null)"
         [[ -z ${gitbranch} ]] && [[ -r ${actiondir}/head-name ]] \
             && gitbranch="$(< ${actiondir}/head-name)"
-        [[ -z ${gitbranch} || ${gitbranch} == 'detached HEAD' ]] \
+        [[ -z ${gitbranch} || ${gitbranch} == 'detached HEAD' ]] && [[ -r ${actiondir}/onto ]] \
             && gitbranch="$(< ${actiondir}/onto)"
 
     elif [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
@@ -112,9 +112,11 @@ VCS_INFO_git_getbranch () {
     ## Commented out because we don't know of a case in which 'describe --contains' fails and 'name-rev --tags' succeeds.
     #elif gitbranch="$(${vcs_comm[cmd]} name-rev --name-only --no-undefined --tags HEAD 2>/dev/null)" ; then
     elif gitbranch="$(${vcs_comm[cmd]} name-rev --name-only --no-undefined --always HEAD 2>/dev/null)" ; then
-    elif gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..." ; then
-    else
-        # Can't happen
+    fi
+
+    if [[ -z ${gitbranch} ]]
+    then
+	gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
     fi
 
     return 0

^ permalink raw reply	[flat|nested] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-09 19:41 [PATCH] vcs_info git: Fix fatal error in VCS_INFO_git_getbranch in corner case Daniel Shahaf

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/ public-inbox