about summary refs log tree commit diff
path: root/Misc
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-13 13:56:36 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2021-04-20 22:34:34 +0000
commitd9ac5916ba17889abf094c1ac45d88f431338d9c (patch)
treedfa1971942d8cbcbbe05f63fbc09654fe30c3e3d /Misc
parentc231a2394f59a691edb3d2daf9d9aefe5fce19da (diff)
downloadzsh-d9ac5916ba17889abf094c1ac45d88f431338d9c.tar.gz
zsh-d9ac5916ba17889abf094c1ac45d88f431338d9c.tar.xz
zsh-d9ac5916ba17889abf094c1ac45d88f431338d9c.zip
48528/0001: vcs_info git docs: ahead/behind commits: Don't run rev-list when that would fail
Diffstat (limited to 'Misc')
-rw-r--r--Misc/vcs_info-examples3
1 files changed, 3 insertions, 0 deletions
diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index d33d0ceed..065ea6cb3 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -179,6 +179,9 @@ function +vi-git-st() {
     local ahead behind
     local -a gitstatus
 
+    # Exit early in case the worktree is on a detached HEAD
+    git rev-parse ${hook_com[branch]}@{upstream} >/dev/null 2>&1 || return 0
+
     ahead=$(git rev-list --count ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null)
     (( $ahead )) && gitstatus+=( "+${ahead}" )