commit:     9d76cbba4afb91b51374316a87fc4135808051f4
Author:     Matthew Brewer <tomboy64 <AT> sina <DOT> cn>
AuthorDate: Fri May 27 22:43:58 2016 +0000
Commit:     M. B. <tomboy64 <AT> sina <DOT> cn>
CommitDate: Fri May 27 22:43:58 2016 +0000
URL:        https://gitweb.gentoo.org/repo/user/tbc.git/commit/?id=9d76cbba

new tool for git-edits step-by-step

 tools/ortrta.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

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

Reply via email to