From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 2995013828B for ; Fri, 27 May 2016 22:44:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 906C621C012; Fri, 27 May 2016 22:44:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3B7B721C012 for ; Fri, 27 May 2016 22:44:32 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2F081340B66 for ; Fri, 27 May 2016 22:44:31 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 1FBC7971 for ; Fri, 27 May 2016 22:44:28 +0000 (UTC) From: "M. B." To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "M. B." Message-ID: <1464389038.9d76cbba4afb91b51374316a87fc4135808051f4.tomboy64@gentoo> Subject: [gentoo-commits] repo/user/tbc:master commit in: tools/ X-VCS-Repository: repo/user/tbc X-VCS-Files: tools/ortrta.sh X-VCS-Directories: tools/ X-VCS-Committer: tomboy64 X-VCS-Committer-Name: M. B. X-VCS-Revision: 9d76cbba4afb91b51374316a87fc4135808051f4 X-VCS-Branch: master Date: Fri, 27 May 2016 22:44:28 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 70bf8830-46fb-48ab-a8cc-70908f051f25 X-Archives-Hash: a21ac79d33620b1c42fd9076fcea8158 commit: 9d76cbba4afb91b51374316a87fc4135808051f4 Author: Matthew Brewer sina cn> AuthorDate: Fri May 27 22:43:58 2016 +0000 Commit: M. B. sina 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 ` +# 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