Skip to content

Instantly share code, notes, and snippets.

@chrisforbes
Created August 14, 2014 09:35
Show Gist options
  • Save chrisforbes/bec9ae191b6fe18095ca to your computer and use it in GitHub Desktop.
Save chrisforbes/bec9ae191b6fe18095ca to your computer and use it in GitHub Desktop.
erk
#!/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.
@chrisforbes
Copy link
Author

Quick howto:

Put aliases in your ~/.erkmap like so:

hacker   J. Random Hacker <[email protected]>

Then this is useful for tacking on r-b etc while doing an interactive rebase:

pick <some commit>
x erk r-b hacker
pick <some other commit>
x erk r-b hacker

At the conclusion of the interactive rebase, both commits will have gained a line in the final paragraph of their commit message:

Reviewed-by: J. Random Hacker <[email protected]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment