acp-push 2.0.0 → 2.2.0
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 +39 -2
- package/bin/acp.js +169 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,8 @@ npm install -g acp-push
|
|
|
27
27
|
| Flag | Description |
|
|
28
28
|
| --- | --- |
|
|
29
29
|
| `-u`, `--upstream` | Push to `origin`, then open a pull request to `upstream` |
|
|
30
|
-
| `-ua`, `--upstream-merge` | Same as `-u`, then merge the pull request if you have write access to `upstream` |
|
|
30
|
+
| `-ua`, `--upstream-allow` (or `--upstream-merge`) | Same as `-u`, then merge the pull request if you have write access to `upstream` |
|
|
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 |
|
|
31
32
|
| `-b`, `--branch <name>` | Push to `<name>` instead of `main` |
|
|
32
33
|
| `-m`, `--message <text>` | Use your own commit message instead of a random one |
|
|
33
34
|
| `-c`, `--chunks` | Split your changes into 10 smaller commits (by change, not by file), then push |
|
|
@@ -40,6 +41,7 @@ npm install -g acp-push
|
|
|
40
41
|
acp # git push origin main
|
|
41
42
|
acp -u # git push origin main, then open a PR to upstream
|
|
42
43
|
acp -ua # same, then merge the PR if you have write access
|
|
44
|
+
acp -bpa # new branch, PR into main, merge, delete the branch
|
|
43
45
|
acp -b dev # git push origin dev
|
|
44
46
|
acp --branch=dev # same as above
|
|
45
47
|
acp -u -b fix # git push origin fix, then open a PR to upstream
|
|
@@ -67,6 +69,41 @@ gh pr create --repo <upstream owner>/<repo> --head <your account>:main
|
|
|
67
69
|
- For the merge, `acp` checks two `gh` accounts for write access: the one named like the owner of `upstream` (if you're logged in to it), then the one that opened the pull request. It merges with the first that has it.
|
|
68
70
|
- If the merge fails, the pull request stays open and `acp` prints its link.
|
|
69
71
|
|
|
72
|
+
### No `origin`, only `upstream`
|
|
73
|
+
|
|
74
|
+
If the repo has an `upstream` remote but no `origin`, `acp -u` / `acp -ua` push a branch straight to `upstream`, open a pull request from it into `upstream`'s default branch, and (with `-ua`) merge it:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git push upstream HEAD:<branch>
|
|
78
|
+
gh pr create --repo <upstream owner>/<repo> --head <upstream owner>:<branch>
|
|
79
|
+
gh pr merge <pr> --merge
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- `<branch>` is `-b <name>` if you gave one, otherwise the branch you are on. On `upstream`'s default branch (a pull request can't go from a branch into itself) `acp` creates a new `acp-<date>` branch instead.
|
|
83
|
+
- 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.
|
|
84
|
+
- The branch is not deleted after the merge.
|
|
85
|
+
|
|
86
|
+
## One repo: branch, PR, merge, delete (`-bpa`)
|
|
87
|
+
|
|
88
|
+
`acp -bpa` does the whole branch workflow in the repo you are in, with no fork or `upstream` needed:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
git add .
|
|
92
|
+
git commit -m "<one of 25 random messages>"
|
|
93
|
+
git push origin HEAD:acp-<date>
|
|
94
|
+
gh pr create --repo <owner>/<repo> --head <owner>:acp-<date>
|
|
95
|
+
gh pr merge <pr> --merge
|
|
96
|
+
git push origin --delete acp-<date>
|
|
97
|
+
git pull --ff-only origin <default branch> # only if you are on the default branch
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- You need the [GitHub CLI](https://cli.github.com) (`gh`) and an `origin` remote on GitHub.
|
|
101
|
+
- The branch is `acp-<date>` unless you pass `-b <name>`. It only exists on the remote, so no local branch is created or left behind.
|
|
102
|
+
- The pull request goes into the default branch of `origin`. Its title is your last commit message.
|
|
103
|
+
- If your account can't merge (no write access), the pull request stays open and the branch is **not** deleted.
|
|
104
|
+
- If the branch was already deleted (for example by the repo's "automatically delete head branches" setting), `acp` just says so.
|
|
105
|
+
- Works with `-c` (each chunk gets its own branch round trip). Not supported with git-multi-commit projects.
|
|
106
|
+
|
|
70
107
|
## Multiple GitHub accounts
|
|
71
108
|
|
|
72
109
|
If you have the [GitHub CLI](https://cli.github.com) (`gh`) installed, `acp` picks the right account for each repo automatically:
|
|
@@ -96,7 +133,7 @@ git commit -m "<one of 25 random messages>"
|
|
|
96
133
|
git-multi-commit
|
|
97
134
|
```
|
|
98
135
|
|
|
99
|
-
No `origin` remote is needed in this case. With `-u` / `-ua`, `acp`
|
|
136
|
+
No `origin` remote is needed in this case. With `-u` / `-ua`, `acp` looks for an `upstream` remote: if it exists, it also pushes the branch (to `origin`, or straight to `upstream` when there is no `origin`) and opens (and with `-ua`, merges) the pull request after `git-multi-commit` finishes. If `upstream` is missing, it prints a warning and skips that part. `-b` only applies when the pull request step runs. Install it with `npm install -g git-multi-commit`.
|
|
100
137
|
|
|
101
138
|
## Notes
|
|
102
139
|
|
package/bin/acp.js
CHANGED
|
@@ -23,7 +23,11 @@ Usage: acp [options]
|
|
|
23
23
|
|
|
24
24
|
Options:
|
|
25
25
|
-u, --upstream Push to origin, then open a pull request to "upstream"
|
|
26
|
-
-ua, --upstream-
|
|
26
|
+
-ua, --upstream-allow Same as -u, then merge it if you have write access
|
|
27
|
+
(--upstream-merge works too)
|
|
28
|
+
-bpa, --branch-pr-auto Push to a new branch on origin, open a pull request into
|
|
29
|
+
the default branch, merge it, then delete the branch
|
|
30
|
+
(-b <name> picks the branch name)
|
|
27
31
|
-b, --branch <name> Push to <name> instead of "main"
|
|
28
32
|
-m, --message <text> Use your own commit message instead of a random one
|
|
29
33
|
-c, --chunks Split your changes into 10 smaller commits. With -u or
|
|
@@ -42,24 +46,35 @@ Pull requests:
|
|
|
42
46
|
branch of upstream. If one is already open, the push just updates it.
|
|
43
47
|
-ua only merges if your account can write to upstream (write, maintain
|
|
44
48
|
or admin role). Otherwise the pull request is left open.
|
|
49
|
+
Without an "origin" remote, acp pushes the branch straight to upstream
|
|
50
|
+
and opens the pull request from there. The branch is your current one,
|
|
51
|
+
-b <name>, or a new acp-<date> branch when you are on upstream's default.
|
|
52
|
+
|
|
53
|
+
One repo (-bpa):
|
|
54
|
+
Needs the GitHub CLI (gh) and an "origin" remote on GitHub. The branch is
|
|
55
|
+
named acp-<date> unless you give -b <name>. The merge needs write access to
|
|
56
|
+
origin; without it the pull request stays open and the branch is kept.
|
|
57
|
+
If you are on the default branch, it is updated after the merge.
|
|
45
58
|
|
|
46
59
|
git-multi-commit:
|
|
47
60
|
If the repo root has a .git-multi-commit.json file, acp still adds and
|
|
48
61
|
commits locally, then runs git-multi-commit instead of git push.
|
|
49
|
-
With -u or -ua
|
|
50
|
-
|
|
51
|
-
merges) the pull request.
|
|
52
|
-
part. -b only applies when the pull request step runs.
|
|
62
|
+
With -u or -ua and an "upstream" remote, acp also pushes <branch> (to
|
|
63
|
+
origin, or straight to upstream when there is no origin) and opens (and
|
|
64
|
+
with -ua merges) the pull request. Without "upstream" it warns and skips
|
|
65
|
+
that part. -b only applies when the pull request step runs.
|
|
53
66
|
|
|
54
67
|
Examples:
|
|
55
68
|
acp ${dim('# push to origin/main')}
|
|
56
69
|
acp -u ${dim('# push to origin/main, open a PR to upstream')}
|
|
57
70
|
acp -ua ${dim('# same, then merge the PR if you can')}
|
|
71
|
+
acp -bpa ${dim('# push a new branch, PR into main, merge, delete the branch')}
|
|
58
72
|
acp -b dev ${dim('# push to origin/dev')}
|
|
59
73
|
acp -u --branch fix ${dim('# push to origin/fix, open a PR to upstream')}
|
|
60
74
|
acp -m "Fix login bug" ${dim('# custom message, push to origin/main')}
|
|
61
75
|
acp -c ${dim('# commit in 10 chunks, then push')}
|
|
62
76
|
acp -c -ua ${dim('# each chunk: push, open a PR, merge it')}
|
|
77
|
+
acp -ua ${dim('# only "upstream" set: push a branch there, PR + merge')}
|
|
63
78
|
`;
|
|
64
79
|
|
|
65
80
|
function fail(message) {
|
|
@@ -69,7 +84,7 @@ function fail(message) {
|
|
|
69
84
|
|
|
70
85
|
// ---------- argument parsing ----------
|
|
71
86
|
function parseArgs(argv) {
|
|
72
|
-
const options = { branch: 'main', message: null, pr: false, merge: false, chunks: false };
|
|
87
|
+
const options = { branch: 'main', branchGiven: false, message: null, pr: false, merge: false, chunks: false, bpa: false };
|
|
73
88
|
|
|
74
89
|
for (let i = 0; i < argv.length; i++) {
|
|
75
90
|
let flag = argv[i];
|
|
@@ -98,13 +113,21 @@ function parseArgs(argv) {
|
|
|
98
113
|
options.pr = true;
|
|
99
114
|
break;
|
|
100
115
|
case '-ua':
|
|
116
|
+
case '--upstream-allow':
|
|
101
117
|
case '--upstream-merge':
|
|
102
118
|
options.pr = true;
|
|
103
119
|
options.merge = true;
|
|
104
120
|
break;
|
|
121
|
+
case '-bpa':
|
|
122
|
+
case '--branch-pr-auto':
|
|
123
|
+
options.bpa = true;
|
|
124
|
+
options.pr = true;
|
|
125
|
+
options.merge = true;
|
|
126
|
+
break;
|
|
105
127
|
case '-b':
|
|
106
128
|
case '--branch':
|
|
107
129
|
options.branch = takeValue();
|
|
130
|
+
options.branchGiven = true;
|
|
108
131
|
break;
|
|
109
132
|
case '-m':
|
|
110
133
|
case '--message':
|
|
@@ -294,7 +317,9 @@ function ghToken(login, isActive) {
|
|
|
294
317
|
|
|
295
318
|
// Works out which gh account to push with and returns the extra git
|
|
296
319
|
// arguments + env needed to use it. Returns null to use normal git login.
|
|
297
|
-
|
|
320
|
+
// With `writeRepo` ("owner/name"), an account that can push to that repo is
|
|
321
|
+
// preferred, because the owner's account may not exist (an organisation).
|
|
322
|
+
function githubAuth(remoteUrl, writeRepo) {
|
|
298
323
|
if (/^(ssh:\/\/)?git@github\.com[:/]/i.test(remoteUrl)) {
|
|
299
324
|
console.log(dim('• SSH remote, using your SSH key.'));
|
|
300
325
|
return null;
|
|
@@ -312,10 +337,22 @@ function githubAuth(remoteUrl) {
|
|
|
312
337
|
|
|
313
338
|
// GitHub usernames are case-insensitive (Gobibahu === GobiBahu).
|
|
314
339
|
const match = gh.accounts.find((a) => a.toLowerCase() === owner.toLowerCase());
|
|
315
|
-
|
|
340
|
+
let account = match || gh.active;
|
|
341
|
+
let writer = null;
|
|
342
|
+
|
|
343
|
+
if (writeRepo) {
|
|
344
|
+
const candidates = [match, gh.active, ...gh.accounts].filter(Boolean);
|
|
345
|
+
writer = candidates.find((a) => {
|
|
346
|
+
const token = ghToken(a, a === gh.active);
|
|
347
|
+
return token && canPush(writeRepo, { GH_TOKEN: token });
|
|
348
|
+
});
|
|
349
|
+
if (writer) account = writer;
|
|
350
|
+
}
|
|
316
351
|
|
|
317
|
-
if (match) {
|
|
352
|
+
if (match && account === match) {
|
|
318
353
|
console.log(cyan(`• Using GitHub account "${account}" (owner of this repo)`));
|
|
354
|
+
} else if (writer) {
|
|
355
|
+
console.log(cyan(`• Using GitHub account "${account}" (has write access to ${writeRepo})`));
|
|
319
356
|
} else {
|
|
320
357
|
console.log(cyan(`• No gh account for "${owner}", using last used account "${account}"`));
|
|
321
358
|
}
|
|
@@ -350,21 +387,62 @@ function githubAuth(remoteUrl) {
|
|
|
350
387
|
// ---------- pull requests (via gh CLI) ----------
|
|
351
388
|
// Checks everything -u needs before anything is committed. Returns the
|
|
352
389
|
// upstream repo ("owner/name") plus the owners of upstream and the fork.
|
|
353
|
-
|
|
354
|
-
|
|
390
|
+
// With no originUrl there is no fork: the branch goes straight to upstream
|
|
391
|
+
// (`direct`), so the pull request's head and base are the same repo.
|
|
392
|
+
// `baseRemote` is the remote the pull request goes into ("upstream", or
|
|
393
|
+
// "origin" for -bpa, where the branch and the pull request live in one repo).
|
|
394
|
+
function pullRequestTarget(originUrl, baseRemote = 'upstream') {
|
|
395
|
+
const upstreamUrl = git(['remote', 'get-url', baseRemote], { quiet: true });
|
|
355
396
|
if (upstreamUrl.status !== 0) {
|
|
356
|
-
fail(
|
|
397
|
+
fail(`Remote "${baseRemote}" does not exist. Add it with: git remote add ${baseRemote} <url>`);
|
|
357
398
|
}
|
|
358
399
|
|
|
359
|
-
const head = githubRepo(originUrl);
|
|
400
|
+
const head = originUrl ? githubRepo(originUrl) : null;
|
|
360
401
|
const base = githubRepo(upstreamUrl.stdout.trim());
|
|
361
|
-
if (!
|
|
402
|
+
if (!base || (originUrl && !head)) {
|
|
403
|
+
fail(
|
|
404
|
+
originUrl
|
|
405
|
+
? 'Pull requests need "origin" and "upstream" to both be GitHub repos.'
|
|
406
|
+
: `Pull requests need "${baseRemote}" to be a GitHub repo.`
|
|
407
|
+
);
|
|
408
|
+
}
|
|
362
409
|
|
|
363
410
|
if (run('gh', ['--version'], { quiet: true }).status !== 0) {
|
|
364
411
|
fail('Pull requests need the GitHub CLI (gh). Install it from https://cli.github.com');
|
|
365
412
|
}
|
|
366
413
|
|
|
367
|
-
return {
|
|
414
|
+
return {
|
|
415
|
+
repo: `${base.owner}/${base.name}`,
|
|
416
|
+
baseOwner: base.owner,
|
|
417
|
+
headOwner: head ? head.owner : base.owner,
|
|
418
|
+
direct: !originUrl,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// The branch to push to upstream when there is no fork: -b if given, else the
|
|
423
|
+
// branch you are on, else a new acp-<date> one (a pull request can't go from
|
|
424
|
+
// upstream's default branch into itself).
|
|
425
|
+
// With `fresh` (-bpa) it is always a new acp-<date> branch unless -b names one,
|
|
426
|
+
// because the branch is deleted after the merge.
|
|
427
|
+
// Also stores the default branch as target.base.
|
|
428
|
+
function directBranch(target, requested, fresh = false) {
|
|
429
|
+
const result = run('gh', ['api', `repos/${target.repo}`, '--jq', '.default_branch'], { quiet: true });
|
|
430
|
+
const base = result.status === 0 ? result.stdout.trim() : '';
|
|
431
|
+
if (!base) fail(`Could not read the default branch of ${target.repo} with gh. Is gh logged in?`);
|
|
432
|
+
target.base = base;
|
|
433
|
+
|
|
434
|
+
if (requested) {
|
|
435
|
+
if (requested === base) fail(`-b ${requested} is the default branch of ${target.repo}, a pull request needs another one.`);
|
|
436
|
+
return requested;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (!fresh) {
|
|
440
|
+
const current = git(['rev-parse', '--abbrev-ref', 'HEAD'], { quiet: true }).stdout.trim();
|
|
441
|
+
if (current && current !== 'HEAD' && current !== base) return current;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
|
|
445
|
+
return `acp-${stamp}`;
|
|
368
446
|
}
|
|
369
447
|
|
|
370
448
|
// True when the gh account behind `env` has write access to `repo`
|
|
@@ -393,7 +471,7 @@ function pullRequest(target, branch, merge) {
|
|
|
393
471
|
return token ? { GH_TOKEN: token } : undefined;
|
|
394
472
|
};
|
|
395
473
|
|
|
396
|
-
const opener = accountFor(target.headOwner);
|
|
474
|
+
const opener = target.opener || accountFor(target.headOwner);
|
|
397
475
|
const head = `${target.headOwner}:${branch}`;
|
|
398
476
|
const title = git(['log', '-1', '--pretty=%s'], { quiet: true }).stdout.trim();
|
|
399
477
|
|
|
@@ -417,7 +495,7 @@ function pullRequest(target, branch, merge) {
|
|
|
417
495
|
} else {
|
|
418
496
|
console.log(yellow(`• Pull request already open, updated by this push: ${url}`));
|
|
419
497
|
}
|
|
420
|
-
if (!merge) return;
|
|
498
|
+
if (!merge) return false;
|
|
421
499
|
|
|
422
500
|
// Only merge with write access to upstream (write, maintain or admin).
|
|
423
501
|
// The fork's owner often doesn't have it, so the gh account that owns
|
|
@@ -433,7 +511,7 @@ function pullRequest(target, branch, merge) {
|
|
|
433
511
|
}
|
|
434
512
|
if (!allowed) {
|
|
435
513
|
console.log(yellow(`• No write access to ${target.repo}, so the pull request stays open for a maintainer to merge.`));
|
|
436
|
-
return;
|
|
514
|
+
return false;
|
|
437
515
|
}
|
|
438
516
|
if (merger && merger !== opener) {
|
|
439
517
|
console.log(cyan(`• Merging with GitHub account "${merger}" (owner of upstream)`));
|
|
@@ -453,6 +531,35 @@ function pullRequest(target, branch, merge) {
|
|
|
453
531
|
fail(`"gh pr merge" failed (exit code ${merged.status}).`);
|
|
454
532
|
}
|
|
455
533
|
console.log(green(`✔ Merged into ${target.repo}`));
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// -bpa, after the merge: deletes the pull request's branch on the remote and,
|
|
538
|
+
// when you are on the default branch, fast-forwards it to the merged result.
|
|
539
|
+
// The pull request is already merged, so problems here only warn.
|
|
540
|
+
function cleanUp(remote, branch, base, auth) {
|
|
541
|
+
const extraArgs = auth.extraArgs || [];
|
|
542
|
+
const quietly = (args) => git([...extraArgs, ...args], { env: auth.env, stdio: ['inherit', 'inherit', 'pipe'] });
|
|
543
|
+
|
|
544
|
+
console.log(cyan(`› git push ${remote} --delete ${branch}`));
|
|
545
|
+
const deleted = quietly(['push', remote, '--delete', branch]);
|
|
546
|
+
if (deleted.status === 0) {
|
|
547
|
+
console.log(green(`✔ Deleted ${remote}/${branch}`));
|
|
548
|
+
} else if (/remote ref does not exist/i.test(deleted.stderr || '')) {
|
|
549
|
+
console.log(dim(`• ${remote}/${branch} was already deleted.`));
|
|
550
|
+
} else {
|
|
551
|
+
if (deleted.stderr) process.stderr.write(deleted.stderr);
|
|
552
|
+
console.log(yellow(`⚠ Could not delete ${remote}/${branch}, delete it yourself.`));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const current = git(['rev-parse', '--abbrev-ref', 'HEAD'], { quiet: true }).stdout.trim();
|
|
556
|
+
if (current !== base) return;
|
|
557
|
+
|
|
558
|
+
console.log(cyan(`› git pull --ff-only ${remote} ${base}`));
|
|
559
|
+
const pulled = quietly(['pull', '--ff-only', remote, base]);
|
|
560
|
+
if (pulled.status === 0) return;
|
|
561
|
+
if (pulled.stderr) process.stderr.write(pulled.stderr);
|
|
562
|
+
console.log(yellow(`⚠ Could not update local ${base}, run: git pull ${remote} ${base}`));
|
|
456
563
|
}
|
|
457
564
|
|
|
458
565
|
// ---------- git-multi-commit ----------
|
|
@@ -482,44 +589,65 @@ function multiCommit() {
|
|
|
482
589
|
|
|
483
590
|
// ---------- main ----------
|
|
484
591
|
function main() {
|
|
485
|
-
const { branch, message, pr, merge, chunks } = parseArgs(process.argv.slice(2));
|
|
486
|
-
|
|
592
|
+
const { branch: requestedBranch, branchGiven, message, pr, merge, chunks, bpa } = parseArgs(process.argv.slice(2));
|
|
593
|
+
let branch = requestedBranch;
|
|
594
|
+
let remote = 'origin';
|
|
487
595
|
|
|
488
596
|
if (git(['rev-parse', '--is-inside-work-tree'], { quiet: true }).status !== 0) {
|
|
489
597
|
fail('Not inside a git repository.');
|
|
490
598
|
}
|
|
491
599
|
|
|
600
|
+
const remoteUrlOf = (name) => git(['remote', 'get-url', name], { quiet: true });
|
|
492
601
|
const multi = usesMultiCommit();
|
|
493
602
|
let remoteUrl;
|
|
494
603
|
let target;
|
|
495
604
|
if (multi) {
|
|
605
|
+
if (bpa) fail('-bpa does not work with git-multi-commit.');
|
|
496
606
|
console.log(cyan(`• Found ${MULTI_COMMIT_CONFIG}, pushing with git-multi-commit instead of git push.`));
|
|
497
607
|
if (pr) {
|
|
498
608
|
// git-multi-commit pushes to its own repos, so -u/-ua only apply when
|
|
499
|
-
//
|
|
500
|
-
const hasOrigin =
|
|
501
|
-
const hasUpstream =
|
|
502
|
-
if (
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
609
|
+
// "upstream" exists. Without "origin" the branch goes straight to it.
|
|
610
|
+
const hasOrigin = remoteUrlOf('origin');
|
|
611
|
+
const hasUpstream = remoteUrlOf('upstream');
|
|
612
|
+
if (hasUpstream.status === 0) {
|
|
613
|
+
if (hasOrigin.status !== 0) remote = 'upstream';
|
|
614
|
+
remoteUrl = hasOrigin.status === 0 ? hasOrigin : hasUpstream;
|
|
615
|
+
target = pullRequestTarget(hasOrigin.status === 0 ? remoteUrl.stdout.trim() : null);
|
|
616
|
+
console.log(cyan(`• Found remote "upstream", will also push to ${remote} and open a pull request.`));
|
|
506
617
|
} else {
|
|
507
|
-
|
|
508
|
-
console.log(yellow(`⚠ Remote "${missing}" does not exist, skipping -u/-ua (git-multi-commit only).`));
|
|
618
|
+
console.log(yellow('⚠ Remote "upstream" does not exist, skipping -u/-ua (git-multi-commit only).'));
|
|
509
619
|
}
|
|
510
620
|
}
|
|
511
621
|
if (!target && branch !== 'main') console.log(yellow('⚠ -b is ignored for git-multi-commit.'));
|
|
512
622
|
} else {
|
|
513
|
-
remoteUrl =
|
|
623
|
+
remoteUrl = remoteUrlOf('origin');
|
|
514
624
|
if (remoteUrl.status !== 0) {
|
|
515
|
-
|
|
625
|
+
const upstream = pr && !bpa ? remoteUrlOf('upstream') : null;
|
|
626
|
+
if (!upstream || upstream.status !== 0) {
|
|
627
|
+
fail(`Remote "${remote}" does not exist. Add it with: git remote add ${remote} <url>`);
|
|
628
|
+
}
|
|
629
|
+
console.log(cyan('• No "origin" remote, pushing a branch straight to "upstream".'));
|
|
630
|
+
remote = 'upstream';
|
|
631
|
+
remoteUrl = upstream;
|
|
632
|
+
target = pullRequestTarget(null);
|
|
633
|
+
} else if (bpa) {
|
|
634
|
+
// One repo: the branch and the pull request both live on origin.
|
|
635
|
+
target = pullRequestTarget(null, 'origin');
|
|
636
|
+
} else if (pr) {
|
|
637
|
+
target = pullRequestTarget(remoteUrl.stdout.trim());
|
|
516
638
|
}
|
|
517
|
-
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (target && target.direct) {
|
|
642
|
+
branch = directBranch(target, branchGiven ? requestedBranch : null, bpa);
|
|
643
|
+
if (bpa) console.log(cyan(`• Using branch "${branch}"`));
|
|
518
644
|
}
|
|
519
645
|
|
|
520
646
|
if (multi && chunks) console.log(yellow('⚠ -c is ignored for git-multi-commit.'));
|
|
521
647
|
|
|
522
|
-
const auth = remoteUrl ? githubAuth(remoteUrl.stdout.trim()) || {} : null;
|
|
648
|
+
const auth = remoteUrl ? githubAuth(remoteUrl.stdout.trim(), target && target.direct ? target.repo : null) || {} : null;
|
|
649
|
+
// Without a fork, the account that pushed the branch also opens the pull request.
|
|
650
|
+
if (target && target.direct && auth && auth.env) target.opener = auth.env.ACP_GH_USER;
|
|
523
651
|
|
|
524
652
|
// "HEAD:<branch>" pushes whatever branch you're on (main, master, anything)
|
|
525
653
|
// to <branch> on the remote, so the default always lands on "main".
|
|
@@ -528,6 +656,11 @@ function main() {
|
|
|
528
656
|
console.log(green(`✔ Pushed to ${remote}/${branch}`));
|
|
529
657
|
};
|
|
530
658
|
|
|
659
|
+
const openPullRequest = () => {
|
|
660
|
+
const merged = pullRequest(target, branch, merge);
|
|
661
|
+
if (bpa && merged) cleanUp(remote, branch, target.base, auth);
|
|
662
|
+
};
|
|
663
|
+
|
|
531
664
|
// With -c and -u/-ua, every chunk is pushed and gets its own pull request
|
|
532
665
|
// (merged right away with -ua), instead of one push at the end.
|
|
533
666
|
let pushedPerChunk = false;
|
|
@@ -537,7 +670,7 @@ function main() {
|
|
|
537
670
|
? (n, count) => {
|
|
538
671
|
console.log(cyan(`• Chunk ${n}/${count}`));
|
|
539
672
|
push();
|
|
540
|
-
|
|
673
|
+
openPullRequest();
|
|
541
674
|
}
|
|
542
675
|
: undefined;
|
|
543
676
|
const done = commitInChunks(message, afterCommit);
|
|
@@ -559,7 +692,7 @@ function main() {
|
|
|
559
692
|
console.log(green('✔ Pushed with git-multi-commit'));
|
|
560
693
|
if (target) {
|
|
561
694
|
push();
|
|
562
|
-
|
|
695
|
+
openPullRequest();
|
|
563
696
|
}
|
|
564
697
|
return;
|
|
565
698
|
}
|
|
@@ -567,7 +700,7 @@ function main() {
|
|
|
567
700
|
if (pushedPerChunk) return;
|
|
568
701
|
|
|
569
702
|
push();
|
|
570
|
-
if (pr)
|
|
703
|
+
if (pr) openPullRequest();
|
|
571
704
|
}
|
|
572
705
|
|
|
573
706
|
main();
|