Skip to content

Instantly share code, notes, and snippets.

@morozov
Last active December 6, 2018 09:49
Show Gist options
  • Save morozov/b2d8d8e5c0660872c0b835f7586eec47 to your computer and use it in GitHub Desktop.
Save morozov/b2d8d8e5c0660872c0b835f7586eec47 to your computer and use it in GitHub Desktop.
A shell script for back-porting Doctrine DBAL pull requests from master to older branches
#!/usr/bin/env bash
set -eu
if [ $# -ne 2 ]; then
echo "Usage: `basename $0` <pull> <branch>";
exit 1;
fi
PULL="$1"
TARGET_BRANCH="$2"
TOPIC_BRANCH="bpo/$TARGET_BRANCH/#$PULL"
git fetch -f upstream "pull/$PULL/head:$TOPIC_BRANCH"
git checkout "$TOPIC_BRANCH"
# https://stackoverflow.com/a/30563070/146187
MERGE_BASE=$(diff -u \
<(git rev-list --first-parent upstream/master) \
<(git rev-list --first-parent HEAD) \
| sed -ne "s/^ //p" \
| head -1
)
git rebase "$MERGE_BASE" --onto "$TARGET_BRANCH"
git checkout "$TARGET_BRANCH"
git merge "$TOPIC_BRANCH" --no-ff --no-edit
git branch -D "$TOPIC_BRANCH"
@morozov
Copy link
Author

morozov commented Dec 6, 2018

The remote pointing to the https://github.com/doctrine/dbal repository is expected to be named upstream.

Example usage: ./backport.sh 3385 2.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment