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 plugin] Use stash 'push' instead of the deprecated 'save' #7486
Conversation
I'm using 2.11.0 and it's very possible that many other people still use versions below 2.13. As I said in #7474 (comment), maybe we can just use I've also checked that flags passed to |
Yeah, sounds good! I'm going to force-push with the change in a minute. EDIT: @mcornella unfortunately that's not the case for me. I did a quick test:
The command is rejected if I pass the |
Ok, here's what I came up with, based on ( cd -q $ZSH; git stash undef_command_to_show_usage 2>&1 | grep -q '\[push' ) && alias gsta='git stash push' || alias gsta='git stash save' It's supper ugly, but it works. I'm not yet satisfied with the solution though. For the moment you can redefine the alias in your zshrc so you don't have to see the deprecation warning. |
I'm currently working on a solution. I'm almost there. |
I think this is a more flexible solution. The script now parses the git version number and sets the |
I made a change so that the function no longer spawns a |
A utility function now parses the output of git --version and set the alias for git stash to 'git stash push' iff the current version of Git is greater than 2.13; it falls back to 'git stash save' otherwise.
I get [[ "$(git --version 2>/dev/null)" =~ '^git version ([0-9]+.[0-9]+)' && "$match" -ge "2.13" ]] \
&& alias gsta='git stash push' \
|| alias gsta='git stash save' Other two options:
|
I had changed it already to an inline if comparison, in my later commits. [[ "$(git --version 2>/dev/null)" =~ '^git version ([0-9]+.[0-9]+)' && "$match" -ge "2.13" ]] \
&& alias gsta='git stash push' \
|| alias gsta='git stash save' Also, minor nitpicking, I don't use double-quotes where I don't need stuff to be expanded (i.e. a string literal) so I would personally write it as |
It's the kind of thing I would care about so don't worry there haha I've pushed the first version then, thanks for your help! |
Meh, I copy-pasted badly and missed a backslash. Fixed! |
No problem! Thank you for merging this in! |
It turns out it doesn't work for certain versions because it makes floating point comparisons: #7754. I'll push the |
CC: @ncanceill
The Pro Git book, in the chapter about Stashing and Cleaning, now reports the above note. The new command was introduced with Git 2.13, which came out 2 years ago. I'm using the latest version of Git and although
stash save
is still present in thegit-stash
's man page,stash push
has taken its place in the command synopsis, as a sign that the latter should be preferred.The two commands have mostly the same interface, except that with
stash push
the message is supplied via the-m
/--message
flag, while withstash save
the message is the main argument of thestash
command and requires no flags.For this reason I think it's pretty safe to change the
gsta
alias togit stash push
: the switch should be pretty seamless and hard to misuse asstash push
will complain if a message is supplied with no flags as it expects a list of pathspecs.Fixes #7474