diff options
author | Ihor <kopach@users.noreply.github.com> | 2023-06-17 13:28:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-17 13:28:55 +0200 |
commit | f5cb9a6c978693c9570206f4267ba2589bef1b4c (patch) | |
tree | 3ba2cccd4864776692dfa6de7f106109944b329b | |
parent | 42b86327ed875ee182f8fc394b90ae9328a5ac00 (diff) | |
download | zsh-f5cb9a6c978693c9570206f4267ba2589bef1b4c.tar.gz zsh-f5cb9a6c978693c9570206f4267ba2589bef1b4c.tar.bz2 zsh-f5cb9a6c978693c9570206f4267ba2589bef1b4c.zip |
fix(git): `gunwipall` now only resets once (#11758)
Closes #11750
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
-rw-r--r-- | plugins/git/README.md | 2 | ||||
-rw-r--r-- | plugins/git/git.plugin.zsh | 18 |
2 files changed, 8 insertions, 12 deletions
diff --git a/plugins/git/README.md b/plugins/git/README.md index bf4b19f39..05cba8586 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -254,7 +254,7 @@ These features allow to pause a branch development and switch to another one (_" | work_in_progress | Echoes a warning if the current branch is a wip | | gwip | Commit wip branch | | gunwip | Uncommit wip branch | -| gunwipall | Uncommit `--wip--` commits recursively | +| gunwipall | Uncommit all recent `--wip--` commits | ### Deprecated functions diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 192124301..66877df4f 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -27,18 +27,14 @@ function work_in_progress() { command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" } -# Same as `gunwip` but recursive -# "Unwips" all recent `--wip--` commits in loop until there is no left +# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one function gunwipall() { - while true; do - commit_message=$(git rev-list --max-count=1 --format="%s" HEAD) - if [[ $commit_message =~ "--wip--" ]]; then - git reset "HEAD~1" - (( $? )) && return 1 - else - break - fi - done + local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H) + + # Check if a commit without "--wip--" was found and it's not the same as HEAD + if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then + git reset $_commit || return 1 + fi } # Check if main exists and use instead of master |