Skip to content

Instantly share code, notes, and snippets.

@chx
Last active December 16, 2023 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chx/16ba3426ec21fbedf3b2bd2db250acae to your computer and use it in GitHub Desktop.
Save chx/16ba3426ec21fbedf3b2bd2db250acae to your computer and use it in GitHub Desktop.
Use this script to push a patch into a drupal.org issue fork

Only once:

  1. Have a Drupal core checkout somewhere
  2. set up a DRUPALREPO variable pointing it, for example add to ~/.profile: export DRUPALREPO=~/drupal

Now:

  1. File issue as normal
  2. Press Create issue fork button
  3. Copy the checkout command https://i.imgur.com/Ek1uQvi.png
  4. push-patch.sh paste_the_above_as_is /path/to/patch
#!/bin/bash
set -e
if [ "$#" -lt 7 ]; then
echo "copy-paste the git checkout command under 'Check out this branch'"
echo "as arguments to this script and add the path to the patch as the last one"
echo "Example:"
echo "$0 git checkout -b '3409154-testing-issue-ignore' --track drupal-3409154/'3409154-testing-issue-ignore' ~/patches/foo.patch"
exit 1
fi
[[ -z "$DRUPALREPO" ]] && { echo "set the DRUPALREPO variable to a path of a local Drupal checkout, for eg.: export DRUPALREPO=~/drupal" ; exit 1; }
PATCH=${@:7}
[[ -s "$PATCH" ]] || { echo "$PATCH does not exist or it is empty" ; exit 1; }
NID=$(echo $6|cut -d- -f2|cut -d/ -f1)
[[ -z "NID" ]] && { echo "can't find the node ID" ; exit 1; }
TMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'TMPDIR')
[[ -z "TMPDIR" ]] && { echo "Temporary directory creation failed" ; exit 1; }
cd $TMPDIR
git clone $DRUPALREPO
cd $(basename $DRUPALREPO)
git remote add drupal-$NID git@git.drupal.org:issue/drupal-$NID.git
git fetch drupal-$NID
git checkout $4
git apply "$PATCH"
git commit -am $(basename "$PATCH")
git push
echo "Done. To clean up:"
echo "rm -rf $TMPDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment