starcraftman / zsh-git-prompt

[Active Fork] Informative git prompt for zsh
MIT License
58 stars 15 forks source link

Fix case when branch has no commits #33

Closed whwright closed 5 years ago

whwright commented 6 years ago

Fix for https://github.com/starcraftman/zsh-git-prompt/issues/31

user@computer  ~  
↪ cd empty-repo
user@computer ~/empty-repo  (master|✔)
↪ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
whwright commented 5 years ago

Any interest in this?

jpo-joyent commented 5 years ago

How do you reproduce the erroneous case?

~ 1% cd $(mktemp -d) 
/tmp/tmp.ZFXcapLMo6% git init
Initialized empty Git repository in /tmp/tmp.ZFXcapLMo6/.git/
/tmp/tmp.ZFXcapLMo6 (master L|✔)% cd .
/tmp/tmp.ZFXcapLMo6 (master L|✔)% git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
/tmp/tmp.ZFXcapLMo6 (master L|✔) 126% git status --porcelain --branch | ~/src/zsh-git-prompt/gitstatus.py 
master 0 0 0 0 0 0 0 1 .. 0 0%

looks fine to me!

whwright commented 5 years ago

This should work (I'm currently using my fork locally, but can confirm later):

↪ git clone git@github.com:whwright/empty-repo.git
Cloning into 'empty-repo'...
warning: You appear to have cloned an empty repository.
↪ cd empty-repo 
whwright commented 5 years ago

Yes I still get the error on master branch of this repo (using my public empty-repo)

↪ cd empty-repo 
git_super_status:[:23: integer expression expected: yet                                                                                                      
git_super_status:[:23: integer expression expected: commits
git_super_status:[:26: integer expression expected: yet
git_super_status:[:29: integer expression expected: commits
git_super_status:[:35: integer expression expected: on
git_super_status:[:39: integer expression expected: master
jpo-joyent commented 5 years ago

yep, reproduced. thanks!

jpo-joyent commented 5 years ago

Hmm, this seems like a bug with https://github.com/starcraftman/zsh-git-prompt/blob/11b83ba3b85d14c66cf2ab79faefab6d838da28e/gitstatus.py#L97-L98

jpo-joyent commented 5 years ago

@whwright see if https://github.com/starcraftman/zsh-git-prompt/pull/37 fixes it for you. I think that's a better fix.

whwright commented 5 years ago

Ah good find. I admittedly was debugging the bash and not the python.

It appears that it is because

↪ cd empty-repo 
↪ git status --branch --porcelain
## No commits yet on master...origin/master [gone]

has the ... first and the first if statement is executed

jpo-joyent commented 5 years ago

Yep. We've come to the same conclusion :)

whwright commented 5 years ago

Yes I agree your solution is much cleaner. Thanks for taking a look.