[ create a new paste ] login | about

Link: http://codepad.org/DRsESBYb    [ raw code | fork ]

Plain Text, pasted on Sep 9:
#!/bin/bash

ghp="$1"; shift
commit="$1"; shift

die() {
    echo "$@" >&2
    exit 1
}

[ -n "$commit" ] || die "Usage: $0 [github-pull-number] commit-hash"

tmpfile=$(tempfile) || die "tempfile failed"
trap "rm -f -- '$tmpfile'" EXIT

fullcommithash=$(git show --format="format:%H" -s "$commit")
gitlogmsg=$(git show --format="format:%B" -s "$commit")
if ! { [ -n "$gitlogmsg" ] && [ -n "$fullcommithash" ]; }; then
    die "git-show failed"
fi
{
    echo "${gitlogmsg}"
    echo
    echo "Github-Pull: #${ghp}"
    echo "Rebased-From: ${fullcommithash}"
} >"${tmpfile}"

git cherry-pick "$commit"
rc="$?"
case "$rc" in
0)
    # Success
    git commit --amend -F "${tmpfile}" -q
    ;;
1)
    # cherry-pick has conflicts, just update MERGE_MSG
    [ -e .git/MERGE_MSG ] || die 'No MERGE_MSG??'
    cat "${tmpfile}" >.git/MERGE_MSG
    ;;
*)
    die 'Cherry-pick FAILED'
    ;;
esac


Create a new paste based on this one


Comments: