acp-push 2.3.0 → 2.3.1
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 +9 -2
- package/bin/acp.js +63 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,8 @@ npm install -g acp-push
|
|
|
30
30
|
| `-ua`, `--upstream-allow` (or `--upstream-merge`) | Same as `-u`, then merge the pull request if you have write access to `upstream` |
|
|
31
31
|
| `-bpa`, `--branch-pr-auto` | Push to a new branch on `origin`, open a pull request into the default branch, merge it, then delete the branch |
|
|
32
32
|
| `-bopa`, `--branch-origin-pr-auto` | Same as `-bpa` |
|
|
33
|
+
| `-ua-o`, `--upstream-allow-origin` | Same as `-bpa`: the pull request goes to `origin` itself and is merged there |
|
|
34
|
+
| `-ua-om`, `--upstream-allow-origin-main` | Push your current branch (not `main`) to `origin`, open a PR into `main`, merge it, then pull `main` back into your branch. The branch is kept. Stops if you are on `main` |
|
|
33
35
|
| `-b`, `--branch <name>` | Push to `<name>` instead of `main` (`-b-<name>` works too, e.g. `-b-nida`) |
|
|
34
36
|
| `-m`, `--message <text>` | Use your own commit message instead of a random one |
|
|
35
37
|
| `-c`, `--chunks` | Split your changes into 10 smaller commits (by change, not by file), then push |
|
|
@@ -44,10 +46,15 @@ acp -u # git push origin main, then open a PR to upstream
|
|
|
44
46
|
acp -ua # same, then merge the PR if you have write access
|
|
45
47
|
acp -bpa # new branch, PR into main, merge, delete the branch
|
|
46
48
|
acp -bopa # same as -bpa
|
|
49
|
+
acp -ua-o # same as -bpa
|
|
50
|
+
acp -c -ua-o # per chunk: commit, push, PR into origin, merge, pull main
|
|
51
|
+
acp -ua-om # on branch nida: push nida, PR into main, merge, pull main into nida
|
|
52
|
+
acp -c -ua-om # same, once per chunk (refuses to run on main)
|
|
47
53
|
acp -b dev # git push origin dev
|
|
48
54
|
acp --branch=dev # same as above
|
|
49
55
|
acp -b-nida # same as -b nida, git push origin nida
|
|
50
56
|
acp -c -b-nida # commit in 10 chunks, then push to origin nida
|
|
57
|
+
acp -c-nida # same as above
|
|
51
58
|
acp -u -b fix # git push origin fix, then open a PR to upstream
|
|
52
59
|
acp -m "Fix login bug" # custom message
|
|
53
60
|
acp -c # 10 smaller commits, then push
|
|
@@ -87,9 +94,9 @@ gh pr merge <pr> --merge
|
|
|
87
94
|
- Of your logged-in `gh` accounts, `acp` uses one that can push to `upstream` (the owner's account first) for the push, the pull request and the merge.
|
|
88
95
|
- The branch is not deleted after the merge.
|
|
89
96
|
|
|
90
|
-
## One repo: branch, PR, merge, delete (`-bpa` / `-bopa`)
|
|
97
|
+
## One repo: branch, PR, merge, delete (`-bpa` / `-bopa` / `-ua-o`)
|
|
91
98
|
|
|
92
|
-
`acp -bpa` (or `acp -bopa`) does the whole branch workflow in the repo you are in, with no fork or `upstream` needed:
|
|
99
|
+
`acp -bpa` (or `acp -bopa` or `acp -ua-o`) does the whole branch workflow in the repo you are in, with no fork or `upstream` needed:
|
|
93
100
|
|
|
94
101
|
```bash
|
|
95
102
|
git add .
|
package/bin/acp.js
CHANGED
|
@@ -30,11 +30,20 @@ Options:
|
|
|
30
30
|
(-b <name> picks the branch name)
|
|
31
31
|
-bopa, --branch-origin-pr-auto
|
|
32
32
|
Same as -bpa
|
|
33
|
+
-ua-o, --upstream-allow-origin
|
|
34
|
+
Same as -bpa: the pull request goes to origin itself
|
|
35
|
+
and is merged there (no upstream or fork needed)
|
|
36
|
+
-ua-om, --upstream-allow-origin-main
|
|
37
|
+
Push your current branch (not main) to origin, open a
|
|
38
|
+
pull request into main, merge it, then pull main back
|
|
39
|
+
into your branch. The branch is kept. Fails on main
|
|
40
|
+
(-b-<name> picks another branch to push)
|
|
33
41
|
-b, --branch <name> Push to <name> instead of "main"
|
|
34
42
|
(-b-<name> works too, e.g. -b-nida)
|
|
35
43
|
-m, --message <text> Use your own commit message instead of a random one
|
|
36
44
|
-c, --chunks Split your changes into 10 smaller commits. With -u or
|
|
37
45
|
-ua, each commit is pushed with its own pull request
|
|
46
|
+
(-c-<name> is -c plus -b <name>, e.g. -c-nida)
|
|
38
47
|
-h, --help Show this help
|
|
39
48
|
-v, --version Show the version
|
|
40
49
|
|
|
@@ -75,9 +84,14 @@ Examples:
|
|
|
75
84
|
acp -ua ${dim('# same, then merge the PR if you can')}
|
|
76
85
|
acp -bpa ${dim('# push a new branch, PR into main, merge, delete the branch')}
|
|
77
86
|
acp -bopa ${dim('# same as -bpa')}
|
|
87
|
+
acp -ua-o ${dim('# same as -bpa: PR into origin, merge it, delete the branch')}
|
|
88
|
+
acp -c -ua-o ${dim('# each chunk: commit, push, PR into origin, merge, pull main')}
|
|
89
|
+
acp -ua-om ${dim('# on branch nida: push nida, PR into main, merge, pull main')}
|
|
90
|
+
acp -c -ua-om ${dim('# same, once per chunk (not allowed while on main)')}
|
|
78
91
|
acp -b dev ${dim('# push to origin/dev')}
|
|
79
92
|
acp -b-nida ${dim('# same as -b nida: push to origin/nida')}
|
|
80
93
|
acp -c -b-nida ${dim('# commit in 10 chunks, then push to origin/nida')}
|
|
94
|
+
acp -c-nida ${dim('# same as above')}
|
|
81
95
|
acp -u --branch fix ${dim('# push to origin/fix, open a PR to upstream')}
|
|
82
96
|
acp -m "Fix login bug" ${dim('# custom message, push to origin/main')}
|
|
83
97
|
acp -c ${dim('# commit in 10 chunks, then push')}
|
|
@@ -92,7 +106,7 @@ function fail(message) {
|
|
|
92
106
|
|
|
93
107
|
// ---------- argument parsing ----------
|
|
94
108
|
function parseArgs(argv) {
|
|
95
|
-
const options = { branch: 'main', branchGiven: false, message: null, pr: false, merge: false, chunks: false, bpa: false };
|
|
109
|
+
const options = { branch: 'main', branchGiven: false, message: null, pr: false, merge: false, chunks: false, bpa: false, originMain: false };
|
|
96
110
|
|
|
97
111
|
for (let i = 0; i < argv.length; i++) {
|
|
98
112
|
let flag = argv[i];
|
|
@@ -123,6 +137,15 @@ function parseArgs(argv) {
|
|
|
123
137
|
continue;
|
|
124
138
|
}
|
|
125
139
|
|
|
140
|
+
// Shorthand: -c-nida is the same as -c -b nida (chunks, pushed to nida).
|
|
141
|
+
if (flag.startsWith('-c-')) {
|
|
142
|
+
if (flag.length === 3) fail('-c- needs a branch name, like -c-nida');
|
|
143
|
+
options.chunks = true;
|
|
144
|
+
options.branch = flag.slice(3);
|
|
145
|
+
options.branchGiven = true;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
126
149
|
switch (flag) {
|
|
127
150
|
case '-u':
|
|
128
151
|
case '--upstream':
|
|
@@ -138,10 +161,18 @@ function parseArgs(argv) {
|
|
|
138
161
|
case '--branch-pr-auto':
|
|
139
162
|
case '-bopa':
|
|
140
163
|
case '--branch-origin-pr-auto':
|
|
164
|
+
case '-ua-o':
|
|
165
|
+
case '--upstream-allow-origin':
|
|
141
166
|
options.bpa = true;
|
|
142
167
|
options.pr = true;
|
|
143
168
|
options.merge = true;
|
|
144
169
|
break;
|
|
170
|
+
case '-ua-om':
|
|
171
|
+
case '--upstream-allow-origin-main':
|
|
172
|
+
options.originMain = true;
|
|
173
|
+
options.pr = true;
|
|
174
|
+
options.merge = true;
|
|
175
|
+
break;
|
|
145
176
|
case '-b':
|
|
146
177
|
case '--branch':
|
|
147
178
|
options.branch = takeValue();
|
|
@@ -443,7 +474,9 @@ function pullRequestTarget(originUrl, baseRemote = 'upstream') {
|
|
|
443
474
|
// With `fresh` (-bpa) it is always a new acp-<date> branch unless -b names one,
|
|
444
475
|
// because the branch is deleted after the merge.
|
|
445
476
|
// Also stores the default branch as target.base.
|
|
446
|
-
|
|
477
|
+
// With `strict` (-ua-om) it never invents a branch: being on the default
|
|
478
|
+
// branch without -b is an error.
|
|
479
|
+
function directBranch(target, requested, fresh = false, strict = false) {
|
|
447
480
|
const result = run('gh', ['api', `repos/${target.repo}`, '--jq', '.default_branch'], { quiet: true, env: target.env });
|
|
448
481
|
const base = result.status === 0 ? result.stdout.trim() : '';
|
|
449
482
|
if (!base) fail(`Could not read the default branch of ${target.repo} with gh. Is gh logged in?`);
|
|
@@ -457,6 +490,12 @@ function directBranch(target, requested, fresh = false) {
|
|
|
457
490
|
if (!fresh) {
|
|
458
491
|
const current = git(['rev-parse', '--abbrev-ref', 'HEAD'], { quiet: true }).stdout.trim();
|
|
459
492
|
if (current && current !== 'HEAD' && current !== base) return current;
|
|
493
|
+
if (strict) {
|
|
494
|
+
fail(
|
|
495
|
+
`-ua-om needs a branch other than ${base}, but you are on ${current === 'HEAD' ? 'no branch' : current}. ` +
|
|
496
|
+
`Switch to another branch, or pick one with -b-<name>.`
|
|
497
|
+
);
|
|
498
|
+
}
|
|
460
499
|
}
|
|
461
500
|
|
|
462
501
|
const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
|
|
@@ -552,6 +591,20 @@ function pullRequest(target, branch, merge) {
|
|
|
552
591
|
return true;
|
|
553
592
|
}
|
|
554
593
|
|
|
594
|
+
// -ua-om, after the merge: the branch is kept, and main (which now holds the
|
|
595
|
+
// merge) is pulled into it so the next round starts from the merged result.
|
|
596
|
+
function syncWithBase(remote, base, auth) {
|
|
597
|
+
const extraArgs = auth.extraArgs || [];
|
|
598
|
+
console.log(cyan(`› git pull --no-rebase --no-edit ${remote} ${base}`));
|
|
599
|
+
const pulled = git([...extraArgs, 'pull', '--no-rebase', '--no-edit', remote, base], {
|
|
600
|
+
env: auth.env,
|
|
601
|
+
stdio: ['inherit', 'inherit', 'pipe'],
|
|
602
|
+
});
|
|
603
|
+
if (pulled.status === 0) return;
|
|
604
|
+
if (pulled.stderr) process.stderr.write(pulled.stderr);
|
|
605
|
+
console.log(yellow(`⚠ Could not pull ${base} into your branch, run: git pull ${remote} ${base}`));
|
|
606
|
+
}
|
|
607
|
+
|
|
555
608
|
// -bpa, after the merge: deletes the pull request's branch on the remote and,
|
|
556
609
|
// when you are on the default branch, fast-forwards it to the merged result.
|
|
557
610
|
// The pull request is already merged, so problems here only warn.
|
|
@@ -769,7 +822,9 @@ function branchPrAutoPairs(targets, branch) {
|
|
|
769
822
|
|
|
770
823
|
// ---------- main ----------
|
|
771
824
|
function main() {
|
|
772
|
-
const { branch: requestedBranch, branchGiven, message, pr, merge, chunks, bpa } = parseArgs(
|
|
825
|
+
const { branch: requestedBranch, branchGiven, message, pr, merge, chunks, bpa, originMain } = parseArgs(
|
|
826
|
+
process.argv.slice(2)
|
|
827
|
+
);
|
|
773
828
|
let branch = requestedBranch;
|
|
774
829
|
let remote = 'origin';
|
|
775
830
|
|
|
@@ -783,6 +838,7 @@ function main() {
|
|
|
783
838
|
let target;
|
|
784
839
|
let pairs;
|
|
785
840
|
if (multi) {
|
|
841
|
+
if (originMain) fail('-ua-om does not work with git-multi-commit projects. Use -bpa instead.');
|
|
786
842
|
console.log(cyan(`• Found ${MULTI_COMMIT_CONFIG}, pushing with git-multi-commit instead of git push.`));
|
|
787
843
|
if (bpa) {
|
|
788
844
|
requireMultiCommit();
|
|
@@ -814,7 +870,7 @@ function main() {
|
|
|
814
870
|
remote = 'upstream';
|
|
815
871
|
remoteUrl = upstream;
|
|
816
872
|
target = pullRequestTarget(null);
|
|
817
|
-
} else if (bpa) {
|
|
873
|
+
} else if (bpa || originMain) {
|
|
818
874
|
// One repo: the branch and the pull request both live on origin.
|
|
819
875
|
target = pullRequestTarget(null, 'origin');
|
|
820
876
|
} else if (pr) {
|
|
@@ -823,8 +879,8 @@ function main() {
|
|
|
823
879
|
}
|
|
824
880
|
|
|
825
881
|
if (target && target.direct) {
|
|
826
|
-
branch = directBranch(target, branchGiven ? requestedBranch : null, bpa);
|
|
827
|
-
if (bpa) console.log(cyan(`• Using branch "${branch}"`));
|
|
882
|
+
branch = directBranch(target, branchGiven ? requestedBranch : null, bpa, originMain);
|
|
883
|
+
if (bpa || originMain) console.log(cyan(`• Using branch "${branch}"`));
|
|
828
884
|
}
|
|
829
885
|
|
|
830
886
|
if (multi && chunks) console.log(yellow('⚠ -c is ignored for git-multi-commit.'));
|
|
@@ -843,6 +899,7 @@ function main() {
|
|
|
843
899
|
const openPullRequest = () => {
|
|
844
900
|
const merged = pullRequest(target, branch, merge);
|
|
845
901
|
if (bpa && merged) cleanUp(remote, branch, target.base, auth);
|
|
902
|
+
if (originMain && merged) syncWithBase(remote, target.base, auth);
|
|
846
903
|
};
|
|
847
904
|
|
|
848
905
|
// With -c and -u/-ua, every chunk is pushed and gets its own pull request
|