diff --git a/README.md b/README.md index b013280..fb0f38d 100644 --- a/README.md +++ b/README.md @@ -84,10 +84,24 @@ git pre-commit check failed: file core/core.services.yml should be 644 not 777 4. Decide if there are any additional branches to merge to 5. Run the command: ```` - git drmr [additional_branches] + git drmr [--apply|--commit] [additional_branches] ```` The merge request ID can be either the numeric ID (e.g. `9395`) or the full GitLab URL (e.g. `https://git.drupalcode.org/project/drupal/-/merge_requests/9395`). +### Flags + +By default the command applies the MR diff and immediately commits. Two flags allow splitting these steps: + +- `--apply` — Applies the MR diff to the current branch and exits without committing. Useful when you want to review or amend the changes before committing. The contribution record does not need to be updated before using this flag. +- `--commit` — Skips applying the diff and goes straight to creating the commit message, committing to the current branch, and cherry-picking to any additional branches. Use this after `--apply` once the contribution record is ready. + +Example two-step workflow: +```` +git drmr --apply fix 9395 +# Review changes, update contribution record on drupal.org... +git drmr --commit fix 9395 11.x,10.3.x +```` + ## Troubleshooting ### Using core's Coder dev dependency diff --git a/git-drmr b/git-drmr index c2d64d4..fbfcee8 100755 --- a/git-drmr +++ b/git-drmr @@ -2,12 +2,30 @@ set -euo pipefail +MODE="default" + +while [[ $# -gt 0 ]]; do + case "$1" in + --apply) + MODE="apply" + shift + ;; + --commit) + MODE="commit" + shift + ;; + *) + break + ;; + esac +done + if [ $# -lt 2 ]; then - echo "Usage: git drmr [additional_branches]" 1>&2 + echo "Usage: git drmr [--apply|--commit] [additional_branches]" 1>&2 exit 1 fi -if [ ! -z "$(git status --untracked-files=no --porcelain)" ]; then +if [ "$MODE" != "commit" ] && [ ! -z "$(git status --untracked-files=no --porcelain)" ]; then echo "Error: Working directory is not clean." 1>&2 exit 1 fi @@ -36,6 +54,15 @@ PROJECT=$(curl --silent https://git.drupalcode.org/api/v4/projects/project%2Fdru ISSUE=$(curl --silent "https://git.drupalcode.org/api/v4/projects/${PROJECT}" | jq -r '.path | capture("(?[0-9]+)$").id') echo "Issue: https://www.drupal.org/project/drupal/issues/${ISSUE}" +MRURL="https://git.drupalcode.org/project/drupal/-/merge_requests/${MR}" + +if [ "$MODE" = "apply" ]; then + echo "Applying patch from $MRURL" + echo + curl --silent --fail ${MRURL}.diff | git apply -v --index + exit 0 +fi + CRURL=$(curl -Ls -w %{url_effective} -o /dev/null https://new.drupal.org/contribution-record?source_link=https%3A//www.drupal.org/node/${ISSUE}) CRDATA=$(curl --silent --globoff "https://www.drupal.org/jsonapi/node/contribution_record?filter[nid]=${CRURL##*/}&include=field_contributors,field_contributors.field_contributor_user" --cookie _cachebuster=$(date +%s)) AUTHORS=$(echo $CRDATA | jq -r ' @@ -50,11 +77,12 @@ if [ -z "$AUTHORS" ]; then exit 1 fi -MRURL="https://git.drupalcode.org/project/drupal/-/merge_requests/${MR}" -echo "Applying patch from $MRURL" -echo -curl --silent --fail ${MRURL}.diff | git apply -v --index -echo +if [ "$MODE" = "default" ]; then + echo "Applying patch from $MRURL" + echo + curl --silent --fail ${MRURL}.diff | git apply -v --index + echo +fi MESSAGE="${TYPE}: #${ISSUE} $(echo $CRDATA | jq -r .data[0].attributes.title)