From 8ab3d4890d8ef13279763b8f107586015f1c2402 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Tue, 2 Feb 2016 15:14:35 +0100 Subject: Rewrite commit message to close PR --- git-merge-pr | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/git-merge-pr b/git-merge-pr index 07a8386..1d72442 100755 --- a/git-merge-pr +++ b/git-merge-pr @@ -7,7 +7,7 @@ REMOTE= case "$PR" in *@*) REMOTE=${PR#*@} - PR=${PR%%@*};; + PR=${PR%%@*} esac shift @@ -17,7 +17,17 @@ PROJECT=${URL%.git} PROJECT=${PROJECT##*:} PROJECT=${PROJECT#//github.com/} -PATCH=$(mktemp) +PATCH="$(mktemp)" trap "rm -f $PATCH" INT TERM EXIT -wget -nv -O "$PATCH" https://github.com/$PROJECT/pull/$PR.patch +wget -nv -O "$PATCH" https://github.com/$PROJECT/pull/"$PR".patch git am "$@" "$PATCH" + +if [ "$(git config --bool --get merge-pr.autoclose)" = false ]; then + exit 0 +fi + +# Rewrite last commit message to close GitHub issue. +EDITOR='sh -c '\''git -c trailer.closes.ifExists=replace interpret-trailers \ + --trailer "Closes: #'"$PR"' [via git-merge-pr]" "$1" > "$1-" && + mv "$1-" "$1"'\'' -' \ +git commit --quiet --amend -- cgit 1.4.1