acp-push 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/acp.js +32 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ acp --branch=dev # same as above
|
|
|
45
45
|
acp -u -b fix # git push origin fix, then open a PR to upstream
|
|
46
46
|
acp -m "Fix login bug" # custom message
|
|
47
47
|
acp -c # 10 smaller commits, then push
|
|
48
|
+
acp -c -ua # 10 commits, each pushed with its own PR, merged right away
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
## Pull requests to upstream
|
package/bin/acp.js
CHANGED
|
@@ -26,7 +26,8 @@ Options:
|
|
|
26
26
|
-ua, --upstream-merge Same as -u, then merge it if you have write access
|
|
27
27
|
-b, --branch <name> Push to <name> instead of "main"
|
|
28
28
|
-m, --message <text> Use your own commit message instead of a random one
|
|
29
|
-
-c, --chunks Split your changes into 10 smaller commits
|
|
29
|
+
-c, --chunks Split your changes into 10 smaller commits. With -u or
|
|
30
|
+
-ua, each commit is pushed with its own pull request
|
|
30
31
|
-h, --help Show this help
|
|
31
32
|
-v, --version Show the version
|
|
32
33
|
|
|
@@ -54,7 +55,8 @@ Examples:
|
|
|
54
55
|
acp -b dev ${dim('# push to origin/dev')}
|
|
55
56
|
acp -u --branch fix ${dim('# push to origin/fix, open a PR to upstream')}
|
|
56
57
|
acp -m "Fix login bug" ${dim('# custom message, push to origin/main')}
|
|
57
|
-
acp -c ${dim('# commit in
|
|
58
|
+
acp -c ${dim('# commit in 10 chunks, then push')}
|
|
59
|
+
acp -c -ua ${dim('# each chunk: push, open a PR, merge it')}
|
|
58
60
|
`;
|
|
59
61
|
|
|
60
62
|
function fail(message) {
|
|
@@ -209,8 +211,8 @@ function stage(unit) {
|
|
|
209
211
|
|
|
210
212
|
// Commits the changes as MAX_CHUNKS commits (fewer if there are fewer separate
|
|
211
213
|
// changes), splitting the individual changes (hunks) as evenly as possible,
|
|
212
|
-
// even within one file. Returns false when there was nothing to commit.
|
|
213
|
-
function commitInChunks(message) {
|
|
214
|
+
// even within one file. afterCommit runs after each commit. Returns false when there was nothing to commit.
|
|
215
|
+
function commitInChunks(message, afterCommit) {
|
|
214
216
|
// Start from a clean index so each commit holds only its own chunk.
|
|
215
217
|
git(['reset', '-q'], { quiet: true });
|
|
216
218
|
|
|
@@ -235,6 +237,7 @@ function commitInChunks(message) {
|
|
|
235
237
|
text = pool.length ? pool.splice(Math.floor(Math.random() * pool.length), 1)[0] : randomMessage();
|
|
236
238
|
}
|
|
237
239
|
step(['commit', '-m', text]);
|
|
240
|
+
if (afterCommit) afterCommit(i + 1, count);
|
|
238
241
|
}
|
|
239
242
|
return true;
|
|
240
243
|
}
|
|
@@ -499,8 +502,30 @@ function main() {
|
|
|
499
502
|
|
|
500
503
|
if (multi && chunks) console.log(yellow('⚠ -c is ignored for git-multi-commit.'));
|
|
501
504
|
|
|
505
|
+
const auth = multi ? null : githubAuth(remoteUrl.stdout.trim()) || {};
|
|
506
|
+
|
|
507
|
+
// "HEAD:<branch>" pushes whatever branch you're on (main, master, anything)
|
|
508
|
+
// to <branch> on the remote, so the default always lands on "main".
|
|
509
|
+
const push = () => {
|
|
510
|
+
step(['push', remote, `HEAD:${branch}`], auth);
|
|
511
|
+
console.log(green(`✔ Pushed to ${remote}/${branch}`));
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
// With -c and -u/-ua, every chunk is pushed and gets its own pull request
|
|
515
|
+
// (merged right away with -ua), instead of one push at the end.
|
|
516
|
+
let pushedPerChunk = false;
|
|
517
|
+
|
|
502
518
|
if (chunks && !multi) {
|
|
503
|
-
|
|
519
|
+
const afterCommit = pr
|
|
520
|
+
? (n, count) => {
|
|
521
|
+
console.log(cyan(`• Chunk ${n}/${count}`));
|
|
522
|
+
push();
|
|
523
|
+
pullRequest(target, branch, merge);
|
|
524
|
+
}
|
|
525
|
+
: undefined;
|
|
526
|
+
const done = commitInChunks(message, afterCommit);
|
|
527
|
+
pushedPerChunk = done && pr;
|
|
528
|
+
if (!done) console.log(yellow('• Nothing new to commit, pushing existing commits.'));
|
|
504
529
|
} else {
|
|
505
530
|
step(['add', '.']);
|
|
506
531
|
|
|
@@ -518,13 +543,9 @@ function main() {
|
|
|
518
543
|
return;
|
|
519
544
|
}
|
|
520
545
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
// "HEAD:<branch>" pushes whatever branch you're on (main, master, anything)
|
|
524
|
-
// to <branch> on the remote, so the default always lands on "main".
|
|
525
|
-
step(['push', remote, `HEAD:${branch}`], auth);
|
|
526
|
-
console.log(green(`✔ Pushed to ${remote}/${branch}`));
|
|
546
|
+
if (pushedPerChunk) return;
|
|
527
547
|
|
|
548
|
+
push();
|
|
528
549
|
if (pr) pullRequest(target, branch, merge);
|
|
529
550
|
}
|
|
530
551
|
|