-
-
Save chrisforbes/bec9ae191b6fe18095ca to your computer and use it in GitHub Desktop.
erk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Attach reviewed-by etc tags to the latest commit. | |
# | |
set -e | |
progname=$(basename "$0") | |
function usage () { | |
echo "usage: $progname (r-b|a-b|t-b) (alias)" 1>&2 | |
exit 1 | |
} | |
if [ "$#" != 2 ]; then | |
usage | |
fi | |
function parse_tag_type () { | |
case $1 in | |
r-b) echo 'Reviewed-by:' ;; | |
t-b) echo 'Tested-by:' ;; | |
a-b) echo 'Acked-by:' ;; | |
*) usage; exit 1 ;; | |
esac | |
} | |
function parse_tag_name () { | |
grep -oP "^$1\s+\K.*$" ~/.erkmap || usage | |
} | |
tag="$(parse_tag_type $1) $(parse_tag_name $2)" | |
if git show | grep -F "$tag" > /dev/null; then | |
echo 'Tag already present.' | |
exit 0 # successfully did nothing. | |
fi | |
filter="cat && echo '"$tag"'" | |
echo "$tag" | |
git filter-branch -f --msg-filter "$filter" HEAD^..HEAD > /dev/null | |
exit 0 # successfully added the tag. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick howto:
Put aliases in your ~/.erkmap like so:
Then this is useful for tacking on r-b etc while doing an interactive rebase:
At the conclusion of the interactive rebase, both commits will have gained a line in the final paragraph of their commit message: