Skip to content

Instantly share code, notes, and snippets.

@mattgrill
Last active December 1, 2016 15:16
Show Gist options
  • Save mattgrill/6fb28f40b84e2e23c24a095b8a510f3f to your computer and use it in GitHub Desktop.
Save mattgrill/6fb28f40b84e2e23c24a095b8a510f3f to your computer and use it in GitHub Desktop.

Fetch-A-Patch

Fetch and apply patches when working with d.o issues.

  • Put fetch-a-patch.js anywhere. There are no dependencies.
  • Create a symlink to a folder included in your $PATH.
    • ln -s ~/Downloads/fetch-a-patch.js /usr/localbin/fetchapatch
  • Fetch an apply a patch, fetchapatch https://www.drupal.org/files/issues/2782915-58.patch
    • Specify a custom file name like so, fetchapatch https://www.drupal.org/files/issues/2782915-58.patch mypatch.patch
#!/usr/bin/env node
const https = require('https');
const fs = require('fs');
const exec = require('child_process').exec;
const args = process.argv;
if (args.length === 2) {
throw new Error('Missing a patch file HTTP path.');
}
const patchUrl = args[2];
const patchFile = args.length === 4 ? args[3] : args[2].split('/').pop();
const download = (url, dest, cb) => {
const file = fs.createWriteStream(`${process.cwd()}/${dest}`);
https.get(url, response => {
response.pipe(file);
file.on('finish', () => file.close(cb));
});
};
download(patchUrl, patchFile, () => {
exec(`git apply ${process.cwd()}/${patchFile}`, (error, stdout, stderr) => {
if (error || stderr) {
return console.log(error, stderr);
}
return console.log(`Applied, ${patchFile}`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment