Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git corrections for bugs in git_prompt_status() #3910

Closed
wants to merge 2 commits into from
Closed

Git corrections for bugs in git_prompt_status() #3910

wants to merge 2 commits into from

Conversation

mbologna
Copy link
Contributor

It seems that git_prompt_status(), a function in git.zsh which is used by 20 themes [1]), is returning incorrect values for:

  • ZSH_THEME_GIT_PROMPT_UNTRACKED
  • ZSH_THEME_GIT_PROMPT_ADDED
  • ZSH_THEME_GIT_PROMPT_MODIFIED

Let's make an example to clarify what I mean by 'incorrect values'.

  • First of all, add git_prompt_status to your omz prompt and set variables mentioned above in your theme or ~/.zshrc file:
PROMPT+='$(git_prompt_status)'
ZSH_THEME_GIT_PROMPT_DIRTY=""
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_UNTRACKED="%"
ZSH_THEME_GIT_PROMPT_MODIFIED="*"
ZSH_THEME_GIT_PROMPT_ADDED="+"
  • Now create a git repo with some cases of the above and test your prompt:
romeo:/tmp $ mkdir demogit && cd demogit && git init                
Initialized empty Git repository in /tmp/demogit/.git/                                                                         
romeo:/tmp/demogit (_here goes my git_prompt_status) $
romeo:/tmp/demogit (_here goes my git_prompt_status) $ touch a b                        
romeo:/tmp/demogit (%) $  
# correct, new untracked file
romeo:/tmp/demogit (%) $ echo "foo" > a                                                                                     
romeo:/tmp/demogit (%) $ git add a                                                                                         
romeo:/tmp/demogit (+%) $ 
# correct, new file added and new untracked file
romeo:/tmp/demogit (+%) $ git commit -m 'initial version'                                                         
romeo:/tmp/demogit (%) $ echo "foooooo" > a                                                                                          
romeo:/tmp/demogit (*%) $ # correct, file modified and new untracked file        
romeo:/tmp/demogit (*%) $ git add a   
romeo:/tmp/demogit (+%) $ echo "bar" >> a                                                    
romeo:/tmp/demogit (+%) $
==> # incorrect, file is modified and also added, and new untracked file.
    # should be: +*% (ZSH_THEME_GIT_PROMPT_MODIFIED, ZSH_THEME_GIT_PROMPT_ADDED, ZSH_THEME_GIT_PROMPT_UNTRACKED)

Let's have another confirmation:

    romeo:/tmp/demogit $ git status                                                                  
    On branch master           
    Changes to be committed:      
    modified:   a  
    Changes not staged for commit:
    modified:   a                  
    Untracked files:  
    b                 
  • To solve this problem, we should change how these three variables are populated (see commit).
  • With commit applied, the three variables are populated correctly:
romeo:/tmp/demogit (*+%) $

[1]

~/.oh-my-zsh/themes $ grep -R -i git_prompt_status | cut -d ':' -f 1 | sort | uniq | wc -l               
20                          

…status():

* STATUS
* ZSH_THEME_GIT_PROMPT_UNTRACKED
* ZSH_THEME_GIT_PROMPT_ADDED
* ZSH_THEME_GIT_PROMPT_MODIFIED

New values are calculated in a different way to actually represent their name, using
only git commands and flags/switches.
@apjanke
Copy link
Contributor

apjanke commented May 20, 2015

Note this covers the same ground as #2054, #2052, #1914. Though those PRs are old enough they're probably moot.

with existing themes that use git_prompt_info()
@mbologna mbologna closed this Aug 1, 2018
@mbologna mbologna deleted the git-corrections branch August 2, 2018 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants