115cee17015e4b5665e16dc4fd15c53e06a22f9a
- Author
- Ihor <kopach@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
feat(git): add `gunwipall` function (#11725)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diff
1diff --git a/plugins/git/README.md b/plugins/git/README.md
2index 2742aa5393331b7cc5ae6dca8b8f4cab495c3225..bf4b19f3983ff02563df3d3a9bc1e835f6540e06 100644
3--- a/plugins/git/README.md
4+++ b/plugins/git/README.md
5@@ -254,6 +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
11 ### Deprecated functions
12
13diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
14index 4be865f6af92190a0019890e79e42f049fab6186..19212430150037afc38484ebbb016eac50b88a89 100644
15--- a/plugins/git/git.plugin.zsh
16+++ b/plugins/git/git.plugin.zsh
17@@ -27,6 +27,20 @@ function work_in_progress() {
18 command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
19 }
20
21+# Same as `gunwip` but recursive
22+# "Unwips" all recent `--wip--` commits in loop until there is no left
23+function gunwipall() {
24+ while true; do
25+ commit_message=$(git rev-list --max-count=1 --format="%s" HEAD)
26+ if [[ $commit_message =~ "--wip--" ]]; then
27+ git reset "HEAD~1"
28+ (( $? )) && return 1
29+ else
30+ break
31+ fi
32+ done
33+}
34+
35 # Check if main exists and use instead of master
36 function git_main_branch() {
37 command git rev-parse --git-dir &>/dev/null || return