-
Notifications
You must be signed in to change notification settings - Fork 115
[WIP] bin: custom git commands #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo " | ||
1) To land single a commit: | ||
git node just <PRID> | ||
|
||
2) To land multiple commits: | ||
git node apply <PRID> | ||
git rebase -i upstream/master # edit every commit that's gonna stay | ||
# on each stay | ||
git node ammend <PRID> | ||
git rebase --continue | ||
# when the rebase is done | ||
git node final" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joyeecheung just want to know am i mistaken or this should be
git-node
instead ofgit node
as we have
git-node
inpackage.json
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The git custom commands work like this: if you have an executable named "git-*" on your path, the it will be run when you do "git *"