Last active
October 25, 2017 10:36
-
-
Save adrienverge/753bdfbc4ba4b6620215 to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -e | |
usage() { | |
cat >&2 <<EOF | |
usage: $0 RANGE | |
Use this script to generate GitHub-pastable pull request descrition | |
from your last commits. Example: | |
### This is commit title number 1 | |
This is commit description. | |
--- | |
### Update README | |
--- | |
### Replace deprecated sysctl() by write to /proc/sys | |
As the manual says: "Do not use this system call" | |
EOF | |
exit 1 | |
} | |
if [ $# -lt 1 ]; then | |
# Find the "master" branch (usually master) | |
git rev-parse --verify master &>/dev/null && branch=master || | |
{ git rev-parse --verify devel &>/dev/null && branch=devel; } || | |
usage | |
range="$(git merge-base $branch HEAD)..HEAD" | |
elif [ $# -eq 1 ] && [ ! -z "${1##*[!0-9]*}" ]; then | |
# show N last commits | |
range="HEAD~$1..HEAD" | |
elif [ $# -eq 1 ] && git log "$1" &>/dev/null; then | |
# show RANGE, e.g. f7e2b61..2ad187f | |
range="$1" | |
else | |
usage | |
fi | |
git log --reverse "$range" \ | |
| sed 's/^commit .*$/---/' \ | |
| sed '/^[^ \-]/d' \ | |
| sed 's/^ //' \ | |
| sed ':a;N;$!ba;s/---\n\n/---\n\n### /g' \ | |
| tail -n +3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment