diff options
author | 2016-05-28 00:43:58 +0200 | |
---|---|---|
committer | 2016-05-28 14:01:59 +0200 | |
commit | 446ee0a58356465f62f6f2c69ce86643fee8cc1f (patch) | |
tree | 55ac76bfa07b9cdd66ca14f8eb59ae57891d866a | |
parent | push my new perl6 ebuilds to the overlay (diff) | |
download | tbc-446ee0a58356465f62f6f2c69ce86643fee8cc1f.tar.gz tbc-446ee0a58356465f62f6f2c69ce86643fee8cc1f.tar.bz2 tbc-446ee0a58356465f62f6f2c69ce86643fee8cc1f.zip |
new tool for git-edits step-by-step
-rwxr-xr-x | tools/ortrta.sh | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tools/ortrta.sh b/tools/ortrta.sh new file mode 100755 index 0000000..7b1d950 --- /dev/null +++ b/tools/ortrta.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Shell script to perform `git rebase -i <argument>` +# License: WTFPL2 + +errorout() { + echo "Failed: $1" + exit 1 +} + +repoman_this() { + local ebuilds=( $(git diff --numstat HEAD^ | cut -f3 | grep '\.ebuild') ) + local dirs=() + for i in ${ebuilds[@]}; do + local dir=$(dirname ${i}) + local inIt=0 + for j in ${dirs[@]}; do + if [[ "${j}" == "${dir}" ]]; then + inIt=1 + break; + fi + done + if [[ ${inIt} -eq 0 ]]; then + dirs+="${dir}" + pushd ${dir} + repoman full + popd 2>&1 > /dev/null + fi + done + git add * + git commit --amend --no-edit + echo + git rebase --continue 2>&1 | head -n1 +} + +choose() { + while [[ true ]]; do + echo -n "(e)dit, (r)epoman full all ebuilds, (c)ontinue or e(x)it? " + read -n1 -r response + + printf '\r' + tput el + echo + + case ${response} in + e ) + exit 0 + ;; + c ) + git rebase --continue 2>&1 | head -n1 + return + ;; + r ) + repoman_this + return + ;; + x ) + echo "Aborting rebase..." + git rebase --abort + echo "Exiting." + exit 0 + ;; + * ) + echo "Wrong key. Try again." + ;; + esac + done +} + +resume() { + count=$(GIT_EDITOR='cat' git rebase --edit-todo | grep -v '^#' | wc -l) + while [[ ${count} -ge 0 ]]; do + git diff --color --stat HEAD^ | cat + echo "left: ${count}" + count=$(( count - 1 )) + choose + done + if [[ $(LC_ALL=C git rebase --edit-todo 2>&1 | \ + grep -v '^#\|No rebase in progress?' | \ + wc -l) \ + -eq 0 ]]; then + echo "Done." + else + echo "Something went wrong here, there's still commits to process." + fi +} + +commence() { + input=$1 + START=${input:=master} + GIT_EDITOR='vim -c "%s/pick/edit/g | wq"' git rebase -i ${START} || errorout "git rebase -i ${START}" + resume +} + +STATUS=$(LC_ALL=C git status | head -n1 | grep -c 'interactive rebase in progress') + +case ${STATUS} in + 1) + resume + ;; + 0) + commence $1 + ;; + *) + errorout "Invalid status \"${STATUS}\"." + ;; +esac |