f5cb9a6c978693c9570206f4267ba2589bef1b4c

Author
Ihor <kopach@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(git): `gunwipall` now only resets once (#11758)

Closes #11750 

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Diff

 1diff --git a/plugins/git/README.md b/plugins/git/README.md
 2index bf4b19f3983ff02563df3d3a9bc1e835f6540e06..05cba8586f1d8a68dbe3a81f2ab169b03c304884 100644
 3--- a/plugins/git/README.md
 4+++ b/plugins/git/README.md
 5@@ -254,7 +254,7 @@ These features allow to pause a branch development and switch to another one (_"
 6 | work_in_progress | Echoes a warning if the current branch is a wip |
 7 | gwip             | Commit wip branch                               |
 8 | gunwip           | Uncommit wip branch                             |
 9-| gunwipall        | Uncommit `--wip--` commits recursively          |
10+| gunwipall        | Uncommit all recent `--wip--` commits           |
11 
12 ### Deprecated functions
13 
14diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
15index 19212430150037afc38484ebbb016eac50b88a89..66877df4f3c9d71c1d50fae7cdaac8d298e1e2b5 100644
16--- a/plugins/git/git.plugin.zsh
17+++ b/plugins/git/git.plugin.zsh
18@@ -27,18 +27,14 @@ function work_in_progress() {
19   command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
20 }
21 
22-# Same as `gunwip` but recursive
23-# "Unwips" all recent `--wip--` commits in loop until there is no left
24+# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one
25 function gunwipall() {
26-  while true; do
27-    commit_message=$(git rev-list --max-count=1 --format="%s" HEAD)
28-    if [[ $commit_message =~ "--wip--" ]]; then
29-      git reset "HEAD~1"
30-      (( $? )) && return 1
31-    else
32-      break
33-    fi
34-  done
35+  local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H)
36+  
37+  # Check if a commit without "--wip--" was found and it's not the same as HEAD
38+  if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then
39+    git reset $_commit || return 1
40+  fi
41 }
42 
43 # Check if main exists and use instead of master