Oliver Baumann <baumanno@users.noreply.github.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date
Message
Parse branch-name for fresh repo (#6302)
Inside a fresh git repo, i.e. immediately after a `git init`, usually no
commit template exists yet. In this case, git renders a different
status message than "Initial commit on". We should consider this message
when attempting to parse out the branch name.
Fixes #6301
Diff
1diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py
2index a8eb8284b7ad8ed601890d84f0ffbfe92f6c00a1..14d87597358ef5978fe47478c385414879bf7701 100644
3--- a/plugins/git-prompt/gitstatus.py
4+++ b/plugins/git-prompt/gitstatus.py
5@@ -41,7 +41,7 @@ ahead, behind = 0, 0
6 status = [(line[0], line[1], line[2:]) for line in stdout.decode('utf-8').splitlines()]
7 for st in status:
8 if st[0] == '#' and st[1] == '#':
9- if re.search('Initial commit on', st[2]):
10+ if re.search('Initial commit on', st[2]) or re.search('No commits yet on', st[2]):
11 branch = st[2].split(' ')[-1]
12 elif re.search('no branch', st[2]): # detached status
13 branch = get_tagname_or_hash()