acp-push 1.2.0 → 1.3.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 +12 -0
- package/bin/acp.js +53 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,18 @@ gh auth login # run again for the second account
|
|
|
62
62
|
|
|
63
63
|
`acp` switches gh's active account to whichever one it used, so "last used" is always the most recent one. The token is only used for that one push and doesn't replace your saved git login. SSH remotes and non-GitHub remotes use your normal git login.
|
|
64
64
|
|
|
65
|
+
## git-multi-commit projects
|
|
66
|
+
|
|
67
|
+
If your repo root contains a `.git-multi-commit.json` file (created by [`git-multi-commit --config`](https://www.npmjs.com/package/git-multi-commit)), `acp` still runs `git add .` and `git commit` locally, but then runs `git-multi-commit` instead of `git push`:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
git add .
|
|
71
|
+
git commit -m "<one of 25 random messages>"
|
|
72
|
+
git-multi-commit
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
No `origin` remote is needed in this case, and `-u` / `-b` are ignored. Install it with `npm install -g git-multi-commit`.
|
|
76
|
+
|
|
65
77
|
## Notes
|
|
66
78
|
|
|
67
79
|
- If there is nothing new to commit, `acp` skips the commit and still pushes, so any commits you made earlier get sent.
|
package/bin/acp.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const { spawnSync } = require('child_process');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
5
7
|
const messages = require('../lib/messages');
|
|
6
8
|
const pkg = require('../package.json');
|
|
7
9
|
|
|
@@ -31,6 +33,11 @@ GitHub accounts:
|
|
|
31
33
|
the repo owner (github.com/<owner>/...). If none matches, it uses the
|
|
32
34
|
account you used last. Log in to each account once with: gh auth login
|
|
33
35
|
|
|
36
|
+
git-multi-commit:
|
|
37
|
+
If the repo root has a .git-multi-commit.json file, acp still adds and
|
|
38
|
+
commits locally, then runs git-multi-commit instead of git push.
|
|
39
|
+
-u and -b are ignored in that case.
|
|
40
|
+
|
|
34
41
|
Examples:
|
|
35
42
|
acp ${dim('# push to origin/main')}
|
|
36
43
|
acp -u ${dim('# push to upstream/main')}
|
|
@@ -102,12 +109,14 @@ function parseArgs(argv) {
|
|
|
102
109
|
|
|
103
110
|
// ---------- process helpers ----------
|
|
104
111
|
// Arguments are passed as an array (no shell), so commit messages with
|
|
105
|
-
// quotes, spaces or special characters are always safe.
|
|
106
|
-
|
|
112
|
+
// quotes, spaces or special characters are always safe. Only pass
|
|
113
|
+
// `shell: true` for commands that take no user input.
|
|
114
|
+
function run(cmd, args, { quiet = false, env, stdio, shell = false } = {}) {
|
|
107
115
|
return spawnSync(cmd, args, {
|
|
108
116
|
stdio: stdio || (quiet ? 'pipe' : 'inherit'),
|
|
109
117
|
encoding: 'utf8',
|
|
110
118
|
env: env ? { ...process.env, ...env } : process.env,
|
|
119
|
+
shell,
|
|
111
120
|
});
|
|
112
121
|
}
|
|
113
122
|
|
|
@@ -131,7 +140,7 @@ function step(args, { extraArgs = [], env, hint } = {}) {
|
|
|
131
140
|
});
|
|
132
141
|
if (hint && result.stderr) process.stderr.write(result.stderr);
|
|
133
142
|
if (result.status !== 0) {
|
|
134
|
-
const authError = /\b403\b|permission|denied|authentication failed|could not read username/i;
|
|
143
|
+
const authError = /\b403\b|permission|denied|authentication failed|could not read username|repository not found/i;
|
|
135
144
|
if (hint && authError.test(result.stderr || '')) console.error(yellow(hint));
|
|
136
145
|
fail(`"git ${args[0]}" failed (exit code ${result.status}).`);
|
|
137
146
|
}
|
|
@@ -239,6 +248,31 @@ function githubAuth(remoteUrl) {
|
|
|
239
248
|
};
|
|
240
249
|
}
|
|
241
250
|
|
|
251
|
+
// ---------- git-multi-commit ----------
|
|
252
|
+
// Projects set up with git-multi-commit keep this file in the repo root
|
|
253
|
+
// (the same place git-multi-commit looks for it). For those, acp runs
|
|
254
|
+
// git-multi-commit instead of git push.
|
|
255
|
+
const MULTI_COMMIT_CONFIG = '.git-multi-commit.json';
|
|
256
|
+
|
|
257
|
+
function usesMultiCommit() {
|
|
258
|
+
const root = git(['rev-parse', '--show-toplevel'], { quiet: true }).stdout.trim();
|
|
259
|
+
return fs.existsSync(path.join(root, MULTI_COMMIT_CONFIG));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function multiCommit() {
|
|
263
|
+
const notInstalled = 'git-multi-commit is not installed. Install it with: npm install -g git-multi-commit';
|
|
264
|
+
// npm installs global CLIs as .cmd shims on Windows, which only start
|
|
265
|
+
// through a shell. No arguments are passed, so no user input reaches it.
|
|
266
|
+
// cmd.exe's "not found" exit code isn't reliable, so look it up first.
|
|
267
|
+
const isWindows = process.platform === 'win32';
|
|
268
|
+
if (isWindows && run('where', ['git-multi-commit'], { quiet: true }).status !== 0) fail(notInstalled);
|
|
269
|
+
|
|
270
|
+
console.log(cyan('› git-multi-commit'));
|
|
271
|
+
const result = run('git-multi-commit', [], { shell: isWindows });
|
|
272
|
+
if (result.error) fail(result.error.code === 'ENOENT' ? notInstalled : result.error.message);
|
|
273
|
+
if (result.status !== 0) fail(`"git-multi-commit" failed (exit code ${result.status}).`);
|
|
274
|
+
}
|
|
275
|
+
|
|
242
276
|
// ---------- main ----------
|
|
243
277
|
function main() {
|
|
244
278
|
const { remote, branch, message } = parseArgs(process.argv.slice(2));
|
|
@@ -247,9 +281,16 @@ function main() {
|
|
|
247
281
|
fail('Not inside a git repository.');
|
|
248
282
|
}
|
|
249
283
|
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
284
|
+
const multi = usesMultiCommit();
|
|
285
|
+
let remoteUrl;
|
|
286
|
+
if (multi) {
|
|
287
|
+
console.log(cyan(`• Found ${MULTI_COMMIT_CONFIG}, pushing with git-multi-commit instead of git push.`));
|
|
288
|
+
if (remote !== 'origin' || branch !== 'main') console.log(yellow('⚠ -u and -b are ignored for git-multi-commit.'));
|
|
289
|
+
} else {
|
|
290
|
+
remoteUrl = git(['remote', 'get-url', remote], { quiet: true });
|
|
291
|
+
if (remoteUrl.status !== 0) {
|
|
292
|
+
fail(`Remote "${remote}" does not exist. Add it with: git remote add ${remote} <url>`);
|
|
293
|
+
}
|
|
253
294
|
}
|
|
254
295
|
|
|
255
296
|
step(['add', '.']);
|
|
@@ -261,6 +302,12 @@ function main() {
|
|
|
261
302
|
step(['commit', '-m', message || randomMessage()]);
|
|
262
303
|
}
|
|
263
304
|
|
|
305
|
+
if (multi) {
|
|
306
|
+
multiCommit();
|
|
307
|
+
console.log(green('✔ Pushed with git-multi-commit'));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
264
311
|
const auth = githubAuth(remoteUrl.stdout.trim()) || {};
|
|
265
312
|
|
|
266
313
|
// "HEAD:<branch>" pushes whatever branch you're on (main, master, anything)
|