From 806889d155a7b21bf5ccef84786a80bb4b78a6a7 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Sat, 22 Jul 2017 23:51:58 +0200 Subject: [PATCH 1/2] Add separator to status only if something follow it --- gitprompt.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index b85da609..537f937a 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -551,13 +551,15 @@ function updatePrompt() { } __chk_gitvar_status 'REMOTE' '-n' - __add_status "$GIT_PROMPT_SEPARATOR" - __chk_gitvar_status 'STAGED' '-ne 0' - __chk_gitvar_status 'CONFLICTS' '-ne 0' - __chk_gitvar_status 'CHANGED' '-ne 0' - __chk_gitvar_status 'UNTRACKED' '-ne 0' - __chk_gitvar_status 'STASHED' '-ne 0' - __chk_gitvar_status 'CLEAN' '-eq 1' - + if [[ $GIT_CLEAN -eq 0 ]] || [[ $GIT_PROMPT_CLEAN != "" ]]; then + __add_status "$GIT_PROMPT_SEPARATOR" + __chk_gitvar_status 'STAGED' '-ne 0' + __chk_gitvar_status 'CONFLICTS' '-ne 0' + __chk_gitvar_status 'CHANGED' '-ne 0' + __chk_gitvar_status 'UNTRACKED' '-ne 0' + __chk_gitvar_status 'STASHED' '-ne 0' + __chk_gitvar_status 'CLEAN' '-eq 1' - + fi __add_status "$ResetColor$GIT_PROMPT_SUFFIX" NEW_PROMPT="$(gp_add_virtualenv_to_prompt)$PROMPT_START$($prompt_callback)$STATUS_PREFIX$STATUS$PROMPT_END" From 1d6089e80bda47f5690ab871f5aebc9b031843fa Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Tue, 8 Aug 2017 12:00:25 +0200 Subject: [PATCH 2/2] Made compatible with git 2.14 on empty repo --- gitstatus.py | 3 ++- gitstatus.sh | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gitstatus.py b/gitstatus.py index e049d084..bf1d1d95 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -89,6 +89,8 @@ def get_stash(): if st[0] == '#' and st[1] == '#': if re.search('Initial commit on', st[2]): branch = st[2].split(' ')[-1] + elif re.search('No commits yet on', st[2]): + branch = st[2].split(' ')[-1] elif re.search('no branch', st[2]): # detached status branch = get_tag_or_hash() elif len(st[2].strip().split('...')) == 1: @@ -150,4 +152,3 @@ def get_stash(): Print(out.encode('utf-8')) else: Print(out) - diff --git a/gitstatus.sh b/gitstatus.sh index 713c5db8..9ec99ce0 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -72,6 +72,10 @@ if [[ "$branch" == *"Initial commit on"* ]]; then IFS=" " read -ra fields <<< "$branch" branch="${fields[3]}" remote="_NO_REMOTE_TRACKING_" +elif [[ "$branch" == *"No commits yet on"* ]]; then + IFS=" " read -ra fields <<< "$branch" + branch="${fields[4]}" + remote="_NO_REMOTE_TRACKING_" elif [[ "$branch" == *"no branch"* ]]; then tag=$( git describe --tags --exact-match ) if [[ -n "$tag" ]]; then