diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 18142f55b3..ee4cdfd9ef 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -29,6 +29,18 @@ If any tests do not pass, or relevant tests are not included, the patch will not If you are working on a bug or feature listed in Jira, please include the ticket number prefixed with GODRIVER in the commit message and GitHub pull request title, (e.g. GODRIVER-123). For the patch commit message itself, please follow the [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/) guide. +### Cherry-picking between branches + +If a Pull Request needs to be cherry-picked to a new branch, get the sha of the commit in the base branch, and then run + +```bash +bash etc/cherry-picker.sh +``` + +The cherry-picker script is configured to use `v1` as the base branch and `master` as the target branch. +It will create a new checkout in a temp dir, create a new branch, perform the cherry-pick, and then +prompt before creating a PR to the target branch. + ## Testing / Development The driver tests can be run against several database configurations. The most simple configuration is a standalone mongod with no auth, no ssl, and no compression. To run these basic driver tests, make sure a standalone MongoDB server instance is running at localhost:27017. To run the tests, you can run `make` (on Windows, run `nmake`). This will run coverage, run go-lint, run go-vet, and build the examples. diff --git a/etc/cherry-picker.sh b/etc/cherry-picker.sh new file mode 100755 index 0000000000..54786b5bb8 --- /dev/null +++ b/etc/cherry-picker.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +sha=$1 +base=v1 +target=master +dirname="/tmp/go-driver-$(openssl rand -hex 12)" +mkdir -p $dirname +git clone git@github.com:mongodb/mongo-go-driver.git $dirname +cd $dirname +branch="cherry-pick-$sha" +git fetch origin $base +git fetch origin $target +git checkout -b $branch origin/$target +git cherry-pick -x $sha + +old_title=$(git --no-pager log -1 --pretty=%B | head -n 1) +ticket=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+).*/\1/') +echo "ticket $ticket" +text=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+) (.*) \(#[0-9]*\)/\2/') +echo "text $text" +pr_number=$(echo $old_title| sed -r 's/.*(#[0-9]*)\)/\1/') +echo "pr number: $pr_number" +title="$ticket [$target] $text" +body="Cherry-pick of $pr_number from $base to $target" + +echo +echo "Creating PR..." +echo "Title: $title" +echo "Body: $body" +echo + +read -p 'Push changes? (Y/n) ' choice +if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then + gh pr create --title "$title" --base $target --body "$body" +fi