Skip to content

Commit

Permalink
Save and restore WIP state while executing clear-local
Browse files Browse the repository at this point in the history
As `clear-local` manipulates with branches, all uncommitted changes have
to be stashed prior to its execution. Also, the stash has to be applied
back to the correct branch. That's why the branch, which was a current one
before the command execution, has to be checkout.
  • Loading branch information
extsoft committed Sep 29, 2019
1 parent 6dc3330 commit eb5fffa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ removes them by invoking `git branch -d`. If there are unmerged branches, you
have to choose either batch or one-by-one deletion procedure using
`git branch -D`.

Prior to the execution, a current state is saved (a branch with modifications).
After the successful accepting a work, the state will be restored. In the case
of a failure, you need to go to the desired branch and apply a stash if needed.

Approximate commands flow is
```bash
==>> git elegant clear-local
Expand Down
10 changes: 9 additions & 1 deletion libexec/git-elegant-clear-local
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ removes them by invoking \`git branch -d\`. If there are unmerged branches, you
have to choose either batch or one-by-one deletion procedure using
\`git branch -D\`.
Prior to the execution, a current state is saved (a branch with modifications).
After the successful accepting a work, the state will be restored. In the case
of a failure, you need to go to the desired branch and apply a stash if needed.
Approximate commands flow is
\`\`\`bash
==>> git elegant clear-local
Expand All @@ -30,7 +34,7 @@ git branch -D task-1
MESSAGE
}

default() {
--clear-local-logic() {
git-verbose checkout ${MASTER}
local cmd="git branch -lvv | grep gone | awk {'print \$1'}"
__loop "git-verbose branch -d" $(eval "$cmd") || \
Expand All @@ -40,3 +44,7 @@ default() {
__batch "Do you want to delete all unmerged branches?" "Delete this?" "git-verbose branch -D" $(eval "$cmd")
)
}

default() {
stash-pipe branch-pipe --clear-local-logic
}
10 changes: 10 additions & 0 deletions tests/git-elegant-clear-local.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ teardown() {
check git-elegant clear-local
[[ "${status}" -eq 0 ]]
}

@test "'clear-local': save WIP prior cleaning and restore after it" {
gitrepo "git checkout -b other"
gitrepo "echo stash >> ${FILE_TO_MODIFY}"
check git-elegant clear-local
[[ "${status}" -eq 0 ]]
[[ "${lines[@]}" =~ "git stash push" ]]
[[ "${lines[@]}" =~ "git stash pop" ]]
[[ "${lines[@]}" =~ "git checkout other" ]]
}

0 comments on commit eb5fffa

Please sign in to comment.