diff --git a/bin/git/git-node b/bin/git/git-node new file mode 100755 index 00000000..196af8e5 --- /dev/null +++ b/bin/git/git-node @@ -0,0 +1,22 @@ +#!/usr/bin/env node +'use strict'; + +const CMD = process.argv[2]; +const path = require('path'); +const { execSync } = require('child_process'); +const fs = require('fs'); + +if (!CMD) { + console.log('Run `git node help` to see how to use this'); + process.exit(1); +} + +const script = path.join(__dirname, `git-node-${CMD}`); +if (!fs.existsSync(script)) { + console.log(`No such command: git node ${CMD}`); + process.exit(1); +} + +execSync(script, process.argv.slice(2), { + stdio: 'inherit' +}); diff --git a/bin/git/git-node-ammend b/bin/git/git-node-ammend new file mode 100755 index 00000000..d120c63b --- /dev/null +++ b/bin/git/git-node-ammend @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [[ $1 -eq 0 ]] ; then + echo 'no patch number specified!' + exit 1 +fi + +set -x; +REV=$(git rev-parse HEAD) +SHORT_REV=${REV:0:7} +MSG=.ncu/msg-$SHORT_REV.txt + +if [ ! -e $MSG ] ; then + git node msg $1; +fi; + +git show $REV -s --format=%B | git node check-msg $MSG +if [ ! $? -eq 0 ]; then + echo "commit message is already ammended" +else + git commit --amend -F $MSG +fi + diff --git a/bin/git/git-node-apply b/bin/git/git-node-apply new file mode 100755 index 00000000..26e723e1 --- /dev/null +++ b/bin/git/git-node-apply @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -x; + +if [[ $1 -eq 0 ]] ; then + echo 'no patch number specified!' + exit 1 +fi + +curl -L "https://github.com/nodejs/node/pull/$1.patch" | git am --whitespace=fix diff --git a/bin/git/git-node-check-msg b/bin/git/git-node-check-msg new file mode 100755 index 00000000..6808257d --- /dev/null +++ b/bin/git/git-node-check-msg @@ -0,0 +1,14 @@ +#!/usr/bin/env node + +const fs = require('fs'); + +const file = process.argv[2]; +const msg = fs.readFileSync(0, 'utf8'); +const toAmmend = fs.readFileSync(file, 'utf8'); +const META_RE = /PR-URL:|Reviewed-By:/; + +for (const line of msg.split('\n')) { + if (line.match(META_RE)) { + throw new Error(`Found ${line}`); + } +} diff --git a/bin/git/git-node-final b/bin/git/git-node-final new file mode 100755 index 00000000..ddd7727b --- /dev/null +++ b/bin/git/git-node-final @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +UPSTREAM=$(git node-rc upstream) +BRANCH=$(git rev-parse --abbrev-ref HEAD) +git rev-list $UPSTREAM/$BRANCH...HEAD | xargs core-validate-commit + +# clean up when it passes +# rm .ncu/msg-*.txt .ncu/metadata-*.txt + diff --git a/bin/git/git-node-help b/bin/git/git-node-help new file mode 100755 index 00000000..4e581e13 --- /dev/null +++ b/bin/git/git-node-help @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +echo " +1) To land single a commit: + git node just + +2) To land multiple commits: + git node apply + git rebase -i upstream/master # edit every commit that's gonna stay + # on each stay + git node ammend + git rebase --continue + # when the rebase is done + git node final" diff --git a/bin/git/git-node-just b/bin/git/git-node-just new file mode 100755 index 00000000..6d073e7b --- /dev/null +++ b/bin/git/git-node-just @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +if [[ $1 -eq 0 ]] ; then + echo 'no patch number specified!' + exit 1 +fi + +set -x + +# grab the patch +mkdir -p .ncu +PATCH=.ncu/patch-$1.patch +curl -L "https://github.com/nodejs/node/pull/$1.patch" > $PATCH +NUM_COMMITS=`cat $PATCH | grep -c "Subject: \[PATCH\]"` + +if [[ ! $NUM_COMMITS -eq 1 ]] ; then + echo 'There are multiple commits in this patch, can not land using `git node just`' + exit 1 +fi + +# abort any previous session +git am --abort + +# apply the patch +cat $PATCH | git am --whitespace=fix + +# build message +git node msg $1; + +REV=$(git rev-parse HEAD) +SHORT_REV=${REV:0:7} +MSG=.ncu/msg-$SHORT_REV.txt +META=.ncu/metadata-$1.txt; + +# ammend the message +git show $REV -s --format=%B | git node check-msg $MSG +if [ ! $? -eq 0 ]; then + echo "commit message is already ammended" +else + git commit --amend -F $MSG +fi + +rm $MSG $PATCH $META \ No newline at end of file diff --git a/bin/git/git-node-meta b/bin/git/git-node-meta new file mode 100755 index 00000000..cb7a9e69 --- /dev/null +++ b/bin/git/git-node-meta @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +if [[ $1 -eq 0 ]] ; then + echo 'no patch number specified!' + exit 1 +fi + +mkdir -p .ncu +META=.ncu/metadata-$1.txt; +get-metadata $1 -f $META diff --git a/bin/git/git-node-msg b/bin/git/git-node-msg new file mode 100755 index 00000000..00e84c25 --- /dev/null +++ b/bin/git/git-node-msg @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +if [[ $1 -eq 0 ]] ; then + echo 'no patch number specified!' + exit 1 +fi + +META=.ncu/metadata-$1.txt; + +if [ ! -e $META ] ; then + git node meta $1 -f $META +fi; + +set -x; +UPSTREAM=$(git node-rc upstream) +BRANCH=$(git rev-parse --abbrev-ref HEAD) +REV=$(git rev-parse HEAD) +#REVS=$(git rev-list $UPSTREAM/$BRANCH...HEAD) + +#for rev in $REVS; do +SHORT_REV=${REV:0:7} +MSG=.ncu/msg-$SHORT_REV.txt +echo -e "$(git show $rev -s --format=%B)\n\n$(cat $META)" > $MSG; +#done + diff --git a/bin/git/git-node-rc b/bin/git/git-node-rc new file mode 100755 index 00000000..8a286755 --- /dev/null +++ b/bin/git/git-node-rc @@ -0,0 +1,14 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const os = require('os'); +const path = require('path'); + +const field = process.argv[2]; +if (!field) { + throw Error('no field specified!'); +} + +const ncurcPath = path.join(os.homedir(), '.ncurc'); +const ncurc = JSON.parse(fs.readFileSync(ncurcPath, 'utf8')); +console.log(ncurc[field]); diff --git a/package.json b/package.json index 3890d78d..2301bb15 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Utilities for Node.js core collaborators", "main": "./bin/metadata.js", "bin": { - "get-metadata": "./bin/get_metadata.js" + "get-metadata": "./bin/get_metadata.js", + "git-node": "./bin/git/git-node" }, "scripts": { "test": "npm run test-unit && npm run lint",