From 308b046875f745abb87b3ef9f0382029fe37b452 Mon Sep 17 00:00:00 2001 From: Gianluca Recchia Date: Sun, 30 Dec 2018 03:10:49 +0100 Subject: [PATCH 1/2] Use stash 'push' or 'save' depending on Git version 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. --- plugins/git/git.plugin.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 2251bae2e..17e4d4b9d 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -33,6 +33,11 @@ function work_in_progress() { fi } +function _omz_git_stash_command() { + [[ `git --version 2>/dev/null` =~ '^git version ([[:digit:]]+.[[:digit:]]+)' && "$match[1]" >= '2.13' ]] \ + && echo push || echo save +} + # # Aliases # (sorted alphabetically) @@ -238,7 +243,7 @@ alias gsps='git show --pretty=short --show-signature' alias gsr='git svn rebase' alias gss='git status -s' alias gst='git status' -alias gsta='git stash save' +alias gsta="git stash $(_omz_git_stash_command)" alias gstaa='git stash apply' alias gstc='git stash clear' alias gstd='git stash drop' From 1bd72f588cb2e4950ea513aa4315ce77c792e43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 9 Apr 2019 18:29:18 +0200 Subject: [PATCH 2/2] Update to inline conditional syntax --- plugins/git/git.plugin.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 17e4d4b9d..fa2487a2c 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -33,11 +33,6 @@ function work_in_progress() { fi } -function _omz_git_stash_command() { - [[ `git --version 2>/dev/null` =~ '^git version ([[:digit:]]+.[[:digit:]]+)' && "$match[1]" >= '2.13' ]] \ - && echo push || echo save -} - # # Aliases # (sorted alphabetically) @@ -243,7 +238,12 @@ alias gsps='git show --pretty=short --show-signature' alias gsr='git svn rebase' alias gss='git status -s' alias gst='git status' -alias gsta="git stash $(_omz_git_stash_command)" + +# use the default stash push on git 2.13 and newer +[[ "$(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' + alias gstaa='git stash apply' alias gstc='git stash clear' alias gstd='git stash drop'