From 493c30954bae3da4ccd80333b807a8d37c131da8 Mon Sep 17 00:00:00 2001 From: Oliver Baumann Date: Mon, 30 Apr 2018 16:25:02 +0200 Subject: 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 --- plugins/git-prompt/gitstatus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/git-prompt/gitstatus.py') diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py index a8eb8284b..14d875973 100644 --- a/plugins/git-prompt/gitstatus.py +++ b/plugins/git-prompt/gitstatus.py @@ -41,7 +41,7 @@ ahead, behind = 0, 0 status = [(line[0], line[1], line[2:]) for line in stdout.decode('utf-8').splitlines()] for st in status: if st[0] == '#' and st[1] == '#': - if re.search('Initial commit on', st[2]): + if re.search('Initial commit on', st[2]) or re.search('No commits yet on', st[2]): branch = st[2].split(' ')[-1] elif re.search('no branch', st[2]): # detached status branch = get_tagname_or_hash() -- cgit v1.2.3-70-g09d2 From 5fa7824ea59ec12a976f348a83399e66699456ea Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Sun, 29 Jul 2018 11:45:35 -0400 Subject: git-prompt: fix error when multiple tags exist (#6998) When a commit has multiple tags associated to it, the git-prompt will throw the following error: git_super_status:[:4: integer expression expected: v0.21.x\ntags/v0.21.5, git_super_status:[:7: integer expression expected: origin/v0.21.x, git_super_status:[:11: integer expression expected: origin/v0.21.x, git_super_status:[:14: integer expression expected: v0.21.x git_super_status:[:23: integer expression expected: v0.21.x This is due to the prompt expecting the tag field to be a single word with no spaces in between but if there are multiple tags the python script returns a string with ', ' space separated list of tags. This throws off the parser. The solution is to ensure that the python script returns a space-less string ensuring the git-prompt parser to properly parse the data. Signed-off-by: Thanh Ha --- plugins/git-prompt/gitstatus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/git-prompt/gitstatus.py') diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py index 14d875973..a4d07cde6 100644 --- a/plugins/git-prompt/gitstatus.py +++ b/plugins/git-prompt/gitstatus.py @@ -22,7 +22,7 @@ def get_tagname_or_hash(): tagname = 'tags/' + output[m.start()+len('tag: '): m.end()-1] if tagname: - return tagname + return tagname.replace(' ', '') elif hash_: return hash_ return None -- cgit v1.2.3-70-g09d2 From 3cfcf5e0aa71bddcf7ab45d3880f142654f22266 Mon Sep 17 00:00:00 2001 From: sheveko <28670374+sheveko@users.noreply.github.com> Date: Sun, 7 Apr 2019 20:21:54 +0200 Subject: git-prompt: run git status with LANG=C (#6087) As described in #6086 there will be an error when one set another language than English. --- plugins/git-prompt/gitstatus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/git-prompt/gitstatus.py') diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py index a4d07cde6..5243af23c 100644 --- a/plugins/git-prompt/gitstatus.py +++ b/plugins/git-prompt/gitstatus.py @@ -30,7 +30,7 @@ def get_tagname_or_hash(): # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind -po = Popen(['git', 'status', '--porcelain', '--branch'], stdout=PIPE, stderr=PIPE) +po = Popen(['git', 'status', '--porcelain', '--branch'], env={"LANG": "C"}, stdout=PIPE, stderr=PIPE) stdout, sterr = po.communicate() if po.returncode != 0: sys.exit(0) # Not a git repository -- cgit v1.2.3-70-g09d2 From 3c8f73c312d1639826a3a5cc499197f423508833 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 10 Apr 2019 20:30:30 +0200 Subject: git-prompt: fix LANG override for git status call The previous version modified the whole environment leading to problems (see #7757). This version *adds* LANG=C to the current env, without overriding it completely. Fixes #7757. --- plugins/git-prompt/gitstatus.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins/git-prompt/gitstatus.py') diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py index 5243af23c..390a50a6f 100644 --- a/plugins/git-prompt/gitstatus.py +++ b/plugins/git-prompt/gitstatus.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from __future__ import print_function +import os import sys import re import shlex @@ -30,7 +31,7 @@ def get_tagname_or_hash(): # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind -po = Popen(['git', 'status', '--porcelain', '--branch'], env={"LANG": "C"}, stdout=PIPE, stderr=PIPE) +po = Popen(['git', 'status', '--porcelain', '--branch'], env=dict(os.environ, LANG="C"), stdout=PIPE, stderr=PIPE) stdout, sterr = po.communicate() if po.returncode != 0: sys.exit(0) # Not a git repository -- cgit v1.2.3-70-g09d2