Created
January 3, 2016 04:00
-
-
Save samv/0c50e986afa7410cb470 to your computer and use it in GitHub Desktop.
Git Blame script that resolves revision numbers to GitHub PR #'s, remote tags, remote or local branches
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 | |
# | |
# call with '-i' to initialize the repo | |
self=$(basename "$0") | |
TEMP="$(getopt n:w:i "$@")" | |
eval set -- $TEMP | |
REFS="refs/pr/*" | |
WIDTH=10 | |
while :; do | |
case "$1" in | |
--) shift; | |
break | |
;; | |
-i) init=1 | |
shift | |
;; | |
-n) echo "N=$2" | |
REFS="$2" | |
shift 2 | |
;; | |
-w) echo "W=$2" | |
WIDTH="$2" | |
shift 2 | |
;; | |
*) echo "Bad: $1" | |
exit 1 ;; | |
esac | |
done | |
origin=$(git rev-parse --symbolic-full-name @{upstream} | sed 's!.*remotes/!!;s!/.*!!') | |
if [ -n "$init" ] | |
then | |
[ -z "$origin" ] && origin=origin | |
if [ -n "$(set -x; git config --get-regexp "remote.$origin.fetch" "^\+?refs/pull/\*/head:.*")" ] | |
then | |
echo "Already configured?" | |
(set -x; git config --get-regexp "remote.$origin.fetch") | |
else | |
(set -x; git config --add "remote.$origin.fetch" "+refs/pull/*/head:refs/pr/*") | |
(set -x; git remote show $origin | egrep -i 'remote|refs/pull' ) | | |
(head; echo " ...etc...") | |
(set -x; git fetch --quiet $origin) | |
fi | |
[ -z "$1" ] && exit 0 | |
fi | |
git blame -l "$@" | | |
git name-rev --refs=$REFS --name-only --stdin | | |
git name-rev --refs=refs/tags/* --name-only --stdin | | |
git name-rev --refs=refs/$origin/* --name-only --stdin | | |
git name-rev --refs=refs/heads/* --name-only --stdin | | |
perl -ple 's{^(\S+)( \()}{sprintf("%'"$WIDTH"'s%s", $1, $2)}e' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment