jimeh / git-aware-prompt

Display current Git branch name in your terminal prompt when in a Git working directory.
Creative Commons Zero v1.0 Universal
2.16k stars 340 forks source link

Hasstash #46

Open naunga opened 8 years ago

naunga commented 8 years ago

Adds the option to indicate if there are any stashes associated with the current branch.

naunga commented 8 years ago

@AaronDMarasco-VSI avoiding the pipe is certainly desirable. I'll admit I'm not familiar with --grep-reflog so I'll have to get educated on that.

heh, I started out thinking, "Oh man this super simple feature would be helpful!" and threw it together in the midst of doing actual work... I should know better.

I'll keep hacking.

Thanks for the suggestions / code reviews.

AaronDMarasco-VSI commented 8 years ago

git help stash says "The command takes options applicable to the git log command to control what is shown and how." I just got it from there. --grep without the reflog may be better anyway, I'm not sure enough how stash works internally to compare the two options. In theory adding -F would go even faster since you are not using regexes.

And yeah, I know how it is for hacking away and then realizing there's prolly a better way.

naunga commented 8 years ago

The first thing I've run into is the matter of return codes. If I do git stash list | grep "${branch}" I get an empty string returned and a non-zero return code. This means that the if statement will not be entered into.

On the other hand, doing git stash list --grep-reflog="${branch}:" gives a zero return code regardless of the success of the grep, because the return code is for the actual git command and not the grep. This means the if statement is "true" and the script incorrectly reports that there is a stash for the branch.

I may not be able to avoid the pipe, but I'll keep wrestling with it.

AaronDMarasco-VSI commented 8 years ago

if [ -n "$(git stash ...)" ]; then do_something_because_string_is_not_blank; fi