Skip to content

Conversation

@naunga
Copy link

@naunga naunga commented Oct 13, 2016

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

prompt.sh Outdated
find_git_stash() {
local stash
if stash=$(git stash list 2>/dev/null | grep $branch 2> /dev/null); then
if stash=$(git stash list 2>/dev/null | grep "WIP on $branch" 2> /dev/null); then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't include stashes with messages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I did not consider that. I'll correct that shortly.

@naunga
Copy link
Author

naunga commented Oct 13, 2016

@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
Copy link

AaronDMarasco-VSI commented Oct 13, 2016

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
Copy link
Author

naunga commented Oct 13, 2016

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
Copy link

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

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.

3 participants