acp-push 2.2.1 → 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.
Files changed (3) hide show
  1. package/README.md +14 -3
  2. package/bin/acp.js +75 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -29,7 +29,10 @@ npm install -g acp-push
29
29
  | `-u`, `--upstream` | Push to `origin`, then open a pull request to `upstream` |
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
- | `-b`, `--branch <name>` | Push to `<name>` instead of `main` |
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` |
35
+ | `-b`, `--branch <name>` | Push to `<name>` instead of `main` (`-b-<name>` works too, e.g. `-b-nida`) |
33
36
  | `-m`, `--message <text>` | Use your own commit message instead of a random one |
34
37
  | `-c`, `--chunks` | Split your changes into 10 smaller commits (by change, not by file), then push |
35
38
  | `-h`, `--help` | Show help |
@@ -42,8 +45,16 @@ acp # git push origin main
42
45
  acp -u # git push origin main, then open a PR to upstream
43
46
  acp -ua # same, then merge the PR if you have write access
44
47
  acp -bpa # new branch, PR into main, merge, delete the branch
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)
45
53
  acp -b dev # git push origin dev
46
54
  acp --branch=dev # same as above
55
+ acp -b-nida # same as -b nida, git push origin nida
56
+ acp -c -b-nida # commit in 10 chunks, then push to origin nida
57
+ acp -c-nida # same as above
47
58
  acp -u -b fix # git push origin fix, then open a PR to upstream
48
59
  acp -m "Fix login bug" # custom message
49
60
  acp -c # 10 smaller commits, then push
@@ -83,9 +94,9 @@ gh pr merge <pr> --merge
83
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.
84
95
  - The branch is not deleted after the merge.
85
96
 
86
- ## One repo: branch, PR, merge, delete (`-bpa`)
97
+ ## One repo: branch, PR, merge, delete (`-bpa` / `-bopa` / `-ua-o`)
87
98
 
88
- `acp -bpa` 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:
89
100
 
90
101
  ```bash
91
102
  git add .
package/bin/acp.js CHANGED
@@ -30,10 +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"
42
+ (-b-<name> works too, e.g. -b-nida)
34
43
  -m, --message <text> Use your own commit message instead of a random one
35
44
  -c, --chunks Split your changes into 10 smaller commits. With -u or
36
45
  -ua, each commit is pushed with its own pull request
46
+ (-c-<name> is -c plus -b <name>, e.g. -c-nida)
37
47
  -h, --help Show this help
38
48
  -v, --version Show the version
39
49
 
@@ -74,8 +84,15 @@ Examples:
74
84
  acp -ua ${dim('# same, then merge the PR if you can')}
75
85
  acp -bpa ${dim('# push a new branch, PR into main, merge, delete the branch')}
76
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)')}
77
91
  acp -b dev ${dim('# push to origin/dev')}
78
- acp -u --branch fix ${dim('# push to origin/fix, open a PR to upstream')}
92
+ acp -b-nida ${dim('# same as -b nida: push to origin/nida')}
93
+ acp -c -b-nida ${dim('# commit in 10 chunks, then push to origin/nida')}
94
+ acp -c-nida ${dim('# same as above')}
95
+ acp -u --branch fix ${dim('# push to origin/fix, open a PR to upstream')}
79
96
  acp -m "Fix login bug" ${dim('# custom message, push to origin/main')}
80
97
  acp -c ${dim('# commit in 10 chunks, then push')}
81
98
  acp -c -ua ${dim('# each chunk: push, open a PR, merge it')}
@@ -89,7 +106,7 @@ function fail(message) {
89
106
 
90
107
  // ---------- argument parsing ----------
91
108
  function parseArgs(argv) {
92
- 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 };
93
110
 
94
111
  for (let i = 0; i < argv.length; i++) {
95
112
  let flag = argv[i];
@@ -112,6 +129,23 @@ function parseArgs(argv) {
112
129
  return next;
113
130
  };
114
131
 
132
+ // Shorthand: -b-nida is the same as -b nida (the name may contain dashes).
133
+ if (flag.startsWith('-b-')) {
134
+ if (flag.length === 3) fail('-b- needs a branch name, like -b-nida');
135
+ options.branch = flag.slice(3);
136
+ options.branchGiven = true;
137
+ continue;
138
+ }
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
+
115
149
  switch (flag) {
116
150
  case '-u':
117
151
  case '--upstream':
@@ -127,10 +161,18 @@ function parseArgs(argv) {
127
161
  case '--branch-pr-auto':
128
162
  case '-bopa':
129
163
  case '--branch-origin-pr-auto':
164
+ case '-ua-o':
165
+ case '--upstream-allow-origin':
130
166
  options.bpa = true;
131
167
  options.pr = true;
132
168
  options.merge = true;
133
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;
134
176
  case '-b':
135
177
  case '--branch':
136
178
  options.branch = takeValue();
@@ -432,7 +474,9 @@ function pullRequestTarget(originUrl, baseRemote = 'upstream') {
432
474
  // With `fresh` (-bpa) it is always a new acp-<date> branch unless -b names one,
433
475
  // because the branch is deleted after the merge.
434
476
  // Also stores the default branch as target.base.
435
- function directBranch(target, requested, fresh = false) {
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) {
436
480
  const result = run('gh', ['api', `repos/${target.repo}`, '--jq', '.default_branch'], { quiet: true, env: target.env });
437
481
  const base = result.status === 0 ? result.stdout.trim() : '';
438
482
  if (!base) fail(`Could not read the default branch of ${target.repo} with gh. Is gh logged in?`);
@@ -446,6 +490,12 @@ function directBranch(target, requested, fresh = false) {
446
490
  if (!fresh) {
447
491
  const current = git(['rev-parse', '--abbrev-ref', 'HEAD'], { quiet: true }).stdout.trim();
448
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
+ }
449
499
  }
450
500
 
451
501
  const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
@@ -541,6 +591,20 @@ function pullRequest(target, branch, merge) {
541
591
  return true;
542
592
  }
543
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
+
544
608
  // -bpa, after the merge: deletes the pull request's branch on the remote and,
545
609
  // when you are on the default branch, fast-forwards it to the merged result.
546
610
  // The pull request is already merged, so problems here only warn.
@@ -758,7 +822,9 @@ function branchPrAutoPairs(targets, branch) {
758
822
 
759
823
  // ---------- main ----------
760
824
  function main() {
761
- const { branch: requestedBranch, branchGiven, message, pr, merge, chunks, bpa } = parseArgs(process.argv.slice(2));
825
+ const { branch: requestedBranch, branchGiven, message, pr, merge, chunks, bpa, originMain } = parseArgs(
826
+ process.argv.slice(2)
827
+ );
762
828
  let branch = requestedBranch;
763
829
  let remote = 'origin';
764
830
 
@@ -772,6 +838,7 @@ function main() {
772
838
  let target;
773
839
  let pairs;
774
840
  if (multi) {
841
+ if (originMain) fail('-ua-om does not work with git-multi-commit projects. Use -bpa instead.');
775
842
  console.log(cyan(`• Found ${MULTI_COMMIT_CONFIG}, pushing with git-multi-commit instead of git push.`));
776
843
  if (bpa) {
777
844
  requireMultiCommit();
@@ -803,7 +870,7 @@ function main() {
803
870
  remote = 'upstream';
804
871
  remoteUrl = upstream;
805
872
  target = pullRequestTarget(null);
806
- } else if (bpa) {
873
+ } else if (bpa || originMain) {
807
874
  // One repo: the branch and the pull request both live on origin.
808
875
  target = pullRequestTarget(null, 'origin');
809
876
  } else if (pr) {
@@ -812,8 +879,8 @@ function main() {
812
879
  }
813
880
 
814
881
  if (target && target.direct) {
815
- branch = directBranch(target, branchGiven ? requestedBranch : null, bpa);
816
- 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}"`));
817
884
  }
818
885
 
819
886
  if (multi && chunks) console.log(yellow('⚠ -c is ignored for git-multi-commit.'));
@@ -832,6 +899,7 @@ function main() {
832
899
  const openPullRequest = () => {
833
900
  const merged = pullRequest(target, branch, merge);
834
901
  if (bpa && merged) cleanUp(remote, branch, target.base, auth);
902
+ if (originMain && merged) syncWithBase(remote, target.base, auth);
835
903
  };
836
904
 
837
905
  // With -c and -u/-ua, every chunk is pushed and gets its own pull request
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acp-push",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "git add, commit (with a random message) and push in one command: acp",
5
5
  "bin": {
6
6
  "acp": "bin/acp.js"