a7426f0b38817bf7cd7000a5d378b7cfb059884f

Author
Kat R. <signe@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(git-prompt): use `--git-common-dir` to load stash count (#13072)

Diff

 1diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py
 2index 94774d828ae57e63b0b58a7a9de23d5157ca3b02..7cd8f54e20498e4ecc447021c26be2e258265066 100644
 3--- a/plugins/git-prompt/gitstatus.py
 4+++ b/plugins/git-prompt/gitstatus.py
 5@@ -23,9 +23,10 @@ def get_tagname_or_hash():
 6         return hash_
 7     return None
 8 
 9-# Re-use method from https://github.com/magicmonty/bash-git-prompt to get stashs count
10+# Re-use method from https://github.com/magicmonty/bash-git-prompt to get stash count
11+# Use `--git-common-dir` to avoid problems with git worktrees, which don't have individual stashes
12 def get_stash():
13-    cmd = Popen(['git', 'rev-parse', '--git-dir'], stdout=PIPE, stderr=PIPE)
14+    cmd = Popen(['git', 'rev-parse', '--git-common-dir'], stdout=PIPE, stderr=PIPE)
15     so, se = cmd.communicate()
16     stash_file = '%s%s' % (so.decode('utf-8').rstrip(), '/logs/refs/stash')
17 
18@@ -35,7 +36,6 @@ def get_stash():
19     except IOError:
20         return 0
21 
22-
23 # `git status --porcelain --branch` can collect all information
24 # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind
25 po = Popen(['git', 'status', '--porcelain', '--branch'], env=dict(os.environ, LANG="C"), stdout=PIPE, stderr=PIPE)