Skip to content

Commit 44d1c32

Browse files
committed
bin: custom git commands
1 parent 74e257c commit 44d1c32

File tree

14 files changed

+268
-3
lines changed

14 files changed

+268
-3
lines changed

bin/git-node

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const CMD = process.argv[2];
5+
const path = require('path');
6+
const { run } = require('../../lib/run');
7+
const fs = require('fs');
8+
9+
if (!CMD) {
10+
console.log('Run `git node help` to see how to use this');
11+
process.exit(1);
12+
}
13+
14+
const script = path.join(
15+
__dirname, '..', 'components', 'git', `git-node-${CMD}`);
16+
if (!fs.existsSync(script)) {
17+
console.error(`No such command: git node ${CMD}`);
18+
process.exit(1);
19+
}
20+
21+
run(script, process.argv.slice(3));

components/git/git-node-ammend

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $1 -eq 0 ]] ; then
4+
echo 'no patch number specified!'
5+
exit 1
6+
fi
7+
8+
set -x;
9+
REV=$(git rev-parse HEAD)
10+
SHORT_REV=${REV:0:7}
11+
MSG=.ncu/msg-$SHORT_REV.txt
12+
13+
if [ ! -e $MSG ] ; then
14+
git node msg $1;
15+
fi;
16+
17+
git show $REV -s --format=%B | git node check-msg $MSG
18+
if [ ! $? -eq 0 ]; then
19+
echo "commit message is already ammended"
20+
else
21+
git commit --amend -F $MSG
22+
fi
23+

components/git/git-node-apply

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const PRID = parseInt(process.argv[2]);
5+
const Request = require('../../lib/request');
6+
const paths = require('../../lib/paths');
7+
const { run, runAsync } = require('../../lib/run');
8+
const fs = require('fs');
9+
const CLI = require('../../lib/cli');
10+
const cli = new CLI(process.stderr);
11+
12+
if (!PRID) {
13+
cli.error('No patch number specified!');
14+
process.exit(1);
15+
}
16+
17+
async function main() {
18+
cli.startSpinner(`Downloading patch for ${PRID}`);
19+
// TODO: support other repos/owners later?
20+
const patch = await new Request().promise({
21+
url: `https://github.com/nodejs/node/pull/${PRID}.patch`
22+
});
23+
const patchName = paths.patch(PRID);
24+
fs.writeFileSync(patchName, patch, 'utf8');
25+
cli.stopSpinner(`Downloaded patch to ${patchName}`);
26+
return run('git', ['am', '--whitespace=fix', patchName]);
27+
}
28+
29+
runAsync(main());

components/git/git-node-check-msg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
5+
const file = process.argv[2];
6+
const msg = fs.readFileSync(0, 'utf8');
7+
const toAmmend = fs.readFileSync(file, 'utf8');
8+
const META_RE = /PR-URL:|Reviewed-By:/;
9+
10+
for (const line of msg.split('\n')) {
11+
if (line.match(META_RE)) {
12+
throw new Error(`Found ${line}`);
13+
}
14+
}

components/git/git-node-final

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
UPSTREAM=$(git node-rc upstream)
4+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
5+
git rev-list $UPSTREAM/$BRANCH...HEAD | xargs core-validate-commit
6+
7+
# clean up when it passes
8+
# rm .ncu/msg-*.txt .ncu/metadata-*.txt
9+

components/git/git-node-help

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
echo "
4+
1) To land single a commit:
5+
git node just <PRID>
6+
7+
2) To land multiple commits:
8+
git node apply <PRID>
9+
git rebase -i upstream/master # edit every commit that's gonna stay
10+
# on each stay
11+
git node ammend <PRID>
12+
git rebase --continue
13+
# when the rebase is done
14+
git node final"

components/git/git-node-just

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $1 -eq 0 ]] ; then
4+
echo 'no patch number specified!'
5+
exit 1
6+
fi
7+
8+
set -x
9+
10+
# grab the patch
11+
mkdir -p .ncu
12+
PATCH=.ncu/patch-$1.patch
13+
curl -L "https://github.com/nodejs/node/pull/$1.patch" > $PATCH
14+
NUM_COMMITS=`cat $PATCH | grep -c "Subject: \[PATCH\]"`
15+
16+
if [[ ! $NUM_COMMITS -eq 1 ]] ; then
17+
echo 'There are multiple commits in this patch, can not land using `git node just`'
18+
exit 1
19+
fi
20+
21+
# abort any previous session
22+
git am --abort
23+
24+
# apply the patch
25+
cat $PATCH | git am --whitespace=fix
26+
27+
# build message
28+
git node msg $1;
29+
30+
REV=$(git rev-parse HEAD)
31+
SHORT_REV=${REV:0:7}
32+
MSG=.ncu/msg-$SHORT_REV.txt
33+
META=.ncu/metadata-$1.txt;
34+
35+
# ammend the message
36+
git show $REV -s --format=%B | git node check-msg $MSG
37+
if [ ! $? -eq 0 ]; then
38+
echo "commit message is already ammended"
39+
else
40+
git commit --amend -F $MSG
41+
fi
42+
43+
rm $MSG $PATCH $META

components/git/git-node-meta

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $1 -eq 0 ]] ; then
4+
echo 'no patch number specified!'
5+
exit 1
6+
fi
7+
8+
mkdir -p .ncu
9+
META=.ncu/metadata-$1.txt;
10+
get-metadata $1 -f $META

components/git/git-node-msg

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $1 -eq 0 ]] ; then
4+
echo 'no patch number specified!'
5+
exit 1
6+
fi
7+
8+
META=.ncu/metadata-$1.txt;
9+
10+
if [ ! -e $META ] ; then
11+
git node meta $1 -f $META
12+
fi;
13+
14+
set -x;
15+
UPSTREAM=$(git node-rc upstream)
16+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
17+
REV=$(git rev-parse HEAD)
18+
#REVS=$(git rev-list $UPSTREAM/$BRANCH...HEAD)
19+
20+
#for rev in $REVS; do
21+
SHORT_REV=${REV:0:7}
22+
MSG=.ncu/msg-$SHORT_REV.txt
23+
echo -e "$(git show $rev -s --format=%B)\n\n$(cat $META)" > $MSG;
24+
#done
25+

components/git/git-node-rc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const os = require('os');
5+
const path = require('path');
6+
7+
const field = process.argv[2];
8+
if (!field) {
9+
throw Error('no field specified!');
10+
}
11+
12+
const ncurcPath = path.join(os.homedir(), '.ncurc');
13+
const ncurc = JSON.parse(fs.readFileSync(ncurcPath, 'utf8'));
14+
console.log(ncurc[field]);

0 commit comments

Comments
 (0)