Skip to content

Instantly share code, notes, and snippets.

@sandrocarval
Last active September 6, 2016 16:26
Show Gist options
  • Save sandrocarval/c9c7852a2e7e23cf40c0 to your computer and use it in GitHub Desktop.
Save sandrocarval/c9c7852a2e7e23cf40c0 to your computer and use it in GitHub Desktop.
Script that lists the commit messages that were commited in a new branch, and also displays the Phabricator revision number from each commit
#!/bin/bash
while [[ $# > 1 ]]
do
key="$1"
case $key in
-f|--from)
FROM="$2"
shift
;;
-t|--to)
TO="$2"
shift
;;
*)
;;
esac
shift
done
if [ -z "$FROM" ] || [ -z "$TO" ]; then
echo "Please specify the FROM and TO branches (-f or --from, -t or --to)!"
else
# First, do the opposite to find out the cherry picks, in order to ignore the original commits in the list,
# and put them in an array
CP_TEMPFILE=$(mktemp)
CP_DIFF_NUMBERS=()
git log --pretty=format:'%h %s' --abbrev-commit --date=relative $TO..$FROM > $CP_TEMPFILE
while read CP_LINE; do
CP_COMMIT_HASH=$(echo "$CP_LINE" | awk '{print $1}')
CP_DIFF_NUMBER=$(git show -s --format=%B $CP_COMMIT_HASH | tail -2 | head -1 | awk -F "/" '{print $4}')
CP_DIFF_NUMBERS=("${CP_DIFF_NUMBERS[@]}" "$CP_DIFF_NUMBER")
done < $CP_TEMPFILE
# Now finds the new commits.
# For each one, if the cherry pick list contains the diff revision number, then it is not displayed.
TEMPFILE=$(mktemp)
git log --pretty=format:'%h %s' --abbrev-commit --date=relative $FROM..$TO > $TEMPFILE
while read LINE; do
COMMIT_HASH=$(echo "$LINE" | awk '{print $1}')
DIFF_NUMBER=$(git show -s --format=%B $COMMIT_HASH | tail -2 | head -1 | awk -F "/" '{print $4}')
if [[ ! " ${CP_DIFF_NUMBERS[@]} " =~ " ${DIFF_NUMBER} " ]]; then
echo "$LINE ($DIFF_NUMBER)"
fi
done < $TEMPFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment