repown 0.3.0 → 0.5.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/CHANGELOG.md +109 -1
- package/README.md +11 -3
- package/dist/cli.js +4 -4
- package/dist/commands/accounts.js +19 -13
- package/dist/commands/doctor.js +7 -5
- package/dist/commands/fix.js +5 -5
- package/dist/commands/guard.js +7 -5
- package/dist/commands/off.js +4 -4
- package/dist/commands/reauthor.js +64 -0
- package/dist/commands/scan.js +7 -6
- package/dist/commands/setup.js +7 -4
- package/dist/commands/start.js +6 -6
- package/dist/commands/status.js +66 -22
- package/dist/commands/use.js +14 -14
- package/dist/core/blockers.js +133 -0
- package/dist/core/config-snapshot.js +97 -0
- package/dist/core/credential/gcm.js +2 -2
- package/dist/core/credential/gh.js +12 -5
- package/dist/core/credential/repair.js +1 -1
- package/dist/core/git.js +145 -12
- package/dist/core/guard/check.js +48 -8
- package/dist/core/guard/hook.js +1 -1
- package/dist/core/hosts/github.js +11 -5
- package/dist/core/hosts/index.js +21 -3
- package/dist/core/identity.js +1 -1
- package/dist/core/inspect.js +6 -6
- package/dist/core/push-destination.js +82 -0
- package/dist/core/push-state.js +109 -0
- package/dist/core/reauthor.js +145 -0
- package/dist/core/registry.js +1 -1
- package/dist/core/unpushed.js +112 -43
- package/dist/program.js +10 -9
- package/dist/ui/args.js +3 -3
- package/dist/ui/command.js +1 -1
- package/dist/ui/dispatch.js +6 -6
- package/dist/ui/format.js +39 -0
- package/dist/ui/help.js +2 -2
- package/dist/ui/prompt.js +1 -1
- package/dist/wizard/clack.js +56 -21
- package/dist/wizard/engine.js +7 -4
- package/dist/wizard/home-context.js +23 -10
- package/dist/wizard/home-flow.js +33 -11
- package/dist/wizard/home-run.js +85 -44
- package/dist/wizard/home-text.js +14 -3
- package/dist/wizard/plain.js +2 -2
- package/dist/wizard/review-text.js +36 -14
- package/dist/wizard/setup-changes.js +11 -7
- package/dist/wizard/setup-context.js +31 -20
- package/dist/wizard/setup-flow.js +265 -56
- package/dist/wizard/setup-run.js +108 -40
- package/npm-shrinkwrap.json +378 -17
- package/package.json +3 -3
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Re-authoring this branch's unpushed commits by another address (ADR-026).
|
|
2
|
+
//
|
|
3
|
+
// The one place repown rewrites history, so it refuses rather than guesses. It fetches the
|
|
4
|
+
// push destination first and rewrites only commits no remote has, from the parent of the
|
|
5
|
+
// topologically oldest one by another address; a merge in that range, a commit a remote has
|
|
6
|
+
// inside it, or a destination whose branches this clone does not track is a refusal. The
|
|
7
|
+
// rebase runs with no hook at all, without autosquash and without moving other branches,
|
|
8
|
+
// behind a backup ref that is never overwritten, and is checked afterwards: every commit
|
|
9
|
+
// still there, each by the pin. Nothing here pushes.
|
|
10
|
+
import { ok, err } from './result.js';
|
|
11
|
+
import { pushTarget, unknownDestination } from './push-destination.js';
|
|
12
|
+
import { AMEND_COMMAND, isOwn, otherAddresses } from './unpushed.js';
|
|
13
|
+
const IDENTITY_ENV = ['GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL'];
|
|
14
|
+
const IDENTITY_CONFIG = ['author.email', 'committer.email', 'author.name', 'committer.name'];
|
|
15
|
+
/** Null: nothing by another address. An error is a refusal, and nothing was changed. */
|
|
16
|
+
export async function planReauthor(git, email, interactive) {
|
|
17
|
+
const ready = await preconditions(git, interactive);
|
|
18
|
+
if (!ready.ok)
|
|
19
|
+
return ready;
|
|
20
|
+
const { branch, remote } = ready.value;
|
|
21
|
+
const fetched = await git.fetchQuietly(remote);
|
|
22
|
+
if (!fetched.ok)
|
|
23
|
+
return err('could not fetch ' + remote + ' (' + fetched.error + '); nothing rewritten');
|
|
24
|
+
const empty = await destinationEmpty(git, remote);
|
|
25
|
+
if (!empty.ok)
|
|
26
|
+
return empty;
|
|
27
|
+
return foreignRange(git, { branch, remote, email, empty: empty.value });
|
|
28
|
+
}
|
|
29
|
+
async function preconditions(git, interactive) {
|
|
30
|
+
const head = await git.currentBranch();
|
|
31
|
+
if (head?.kind !== 'branch')
|
|
32
|
+
return err('HEAD is detached: switch to a branch first');
|
|
33
|
+
const blocked = await firstRefusal(git, interactive);
|
|
34
|
+
if (blocked)
|
|
35
|
+
return err(blocked);
|
|
36
|
+
const unknown = await unknownDestination(git, head.name);
|
|
37
|
+
if (unknown && unknown.kind !== 'remote')
|
|
38
|
+
return err('this branch does not push to a remote repown can fetch: point the branch at a remote first');
|
|
39
|
+
const target = await pushTarget(git, head.name);
|
|
40
|
+
if (!target?.isRemote)
|
|
41
|
+
return err('this branch has no remote to push to');
|
|
42
|
+
return ok({ branch: head.name, remote: target.name });
|
|
43
|
+
}
|
|
44
|
+
/** Each check that would make the rewrite unsafe, or not use the pinned identity. */
|
|
45
|
+
async function firstRefusal(git, interactive) {
|
|
46
|
+
if (!await git.getConfig('repown.account', 'local'))
|
|
47
|
+
return 'this clone is not pinned: repown use <account> first';
|
|
48
|
+
const env = IDENTITY_ENV.find((name) => process.env[name]);
|
|
49
|
+
if (env)
|
|
50
|
+
return env + ' is set: the rewrite would not use the pinned address (unset it)';
|
|
51
|
+
for (const key of IDENTITY_CONFIG)
|
|
52
|
+
if (await git.getConfig(key))
|
|
53
|
+
return key + ' is set: the rewrite would not use the pinned address';
|
|
54
|
+
const busy = await git.operationInProgress();
|
|
55
|
+
if (busy)
|
|
56
|
+
return 'a ' + busy + ' is in progress: finish or abort it first';
|
|
57
|
+
const dirty = await git.hasTrackedChanges();
|
|
58
|
+
if (!dirty.ok || dirty.value)
|
|
59
|
+
return 'this clone has uncommitted changes (or files hidden with skip-worktree): commit or stash them first';
|
|
60
|
+
if (!interactive && await git.getBoolConfig('commit.gpgsign') === true)
|
|
61
|
+
return 'commit.gpgsign is on and there is no terminal to sign in: run repown reauthor in a terminal';
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
/** True only when a successful fetch left no tracking refs AND the remote lists no branches. */
|
|
65
|
+
async function destinationEmpty(git, remote) {
|
|
66
|
+
const tracked = await git.hasTrackingRefs(remote);
|
|
67
|
+
if (!tracked.ok)
|
|
68
|
+
return tracked;
|
|
69
|
+
if (tracked.value)
|
|
70
|
+
return ok(false);
|
|
71
|
+
const heads = await git.remoteHeadCount(remote);
|
|
72
|
+
if (!heads.ok)
|
|
73
|
+
return err('could not list ' + remote + '\'s branches (' + heads.error + '); nothing rewritten');
|
|
74
|
+
if (heads.value > 0)
|
|
75
|
+
return err('this clone does not track ' + remote + '\'s branches, so it can\'t tell what ' + remote + ' already has');
|
|
76
|
+
return ok(true);
|
|
77
|
+
}
|
|
78
|
+
async function foreignRange(git, scope) {
|
|
79
|
+
const listed = await git.identitiesIn(['--topo-order', 'HEAD', '--not', '--remotes']);
|
|
80
|
+
if (!listed.ok)
|
|
81
|
+
return listed;
|
|
82
|
+
const foreign = listed.value.filter((commit) => !isOwn(commit, scope.email));
|
|
83
|
+
const oldest = foreign.at(-1);
|
|
84
|
+
if (!oldest)
|
|
85
|
+
return ok(null);
|
|
86
|
+
const parent = await git.parentOf(oldest.sha);
|
|
87
|
+
if (!parent && !scope.empty)
|
|
88
|
+
return err('the oldest of these commits is a root, and ' + scope.remote + ' is not empty');
|
|
89
|
+
const base = parent ?? '--root';
|
|
90
|
+
const checked = await checkRange(git, base);
|
|
91
|
+
if (!checked.ok)
|
|
92
|
+
return checked;
|
|
93
|
+
return ok({ branch: scope.branch, remote: scope.remote, base, count: checked.value, addresses: otherAddresses(foreign, scope.email) });
|
|
94
|
+
}
|
|
95
|
+
/** The range must be linear and unpublished: a rebase flattens merges and rewrites all it covers. */
|
|
96
|
+
async function checkRange(git, base) {
|
|
97
|
+
const range = base === '--root' ? ['HEAD'] : [base + '..HEAD'];
|
|
98
|
+
const [all, merges, unpushed] = await Promise.all([
|
|
99
|
+
git.countIn(range), git.countIn(['--merges', ...range]), git.countIn([...range, '--not', '--remotes']),
|
|
100
|
+
]);
|
|
101
|
+
if (!all.ok)
|
|
102
|
+
return all;
|
|
103
|
+
if (!merges.ok)
|
|
104
|
+
return merges;
|
|
105
|
+
if (!unpushed.ok)
|
|
106
|
+
return unpushed;
|
|
107
|
+
if (merges.value > 0)
|
|
108
|
+
return err('the commits to rewrite include a merge, which a rebase would flatten: re-author them by hand');
|
|
109
|
+
if (unpushed.value !== all.value)
|
|
110
|
+
return err('a remote already has some commits in that range; nothing rewritten');
|
|
111
|
+
return ok(all.value);
|
|
112
|
+
}
|
|
113
|
+
/** Backup, rebase, check. On any failure HEAD is put back where it was, or the backup is named. */
|
|
114
|
+
export async function applyReauthor(git, plan, email) {
|
|
115
|
+
const head = await git.revParse('HEAD');
|
|
116
|
+
const backup = 'refs/repown/backup/' + plan.branch + '/' + Math.floor(Date.now() / 1000);
|
|
117
|
+
if (!head || !await git.createRef(backup, head))
|
|
118
|
+
return err('could not write a new backup ref (one from this second exists?); nothing rewritten');
|
|
119
|
+
const rebased = await git.rebaseExec(plan.base, AMEND_COMMAND);
|
|
120
|
+
if (!rebased.ok)
|
|
121
|
+
return err(await restored(git, { head, branch: plan.branch, backup }, rebased.error));
|
|
122
|
+
return checked(git, plan, email, backup);
|
|
123
|
+
}
|
|
124
|
+
/** Every planned commit is still there, and each is by the pin; otherwise the backup is named. */
|
|
125
|
+
async function checked(git, plan, email, backup) {
|
|
126
|
+
const range = plan.base === '--root' ? ['HEAD'] : [plan.base + '..HEAD'];
|
|
127
|
+
const after = await git.identitiesIn(range);
|
|
128
|
+
if (!after.ok)
|
|
129
|
+
return err('the rewritten commits could not be read (' + after.error + '); the original is at ' + backup);
|
|
130
|
+
if (after.value.length !== plan.count) {
|
|
131
|
+
return err(plan.count + ' commits were planned but ' + after.value.length + ' came out; the original is at ' + backup);
|
|
132
|
+
}
|
|
133
|
+
if (after.value.some((commit) => !isOwn(commit, email)))
|
|
134
|
+
return err('the rewritten commits do not all carry ' + email + '; the original is at ' + backup);
|
|
135
|
+
return ok({ count: after.value.length, backup });
|
|
136
|
+
}
|
|
137
|
+
/** "Nothing rewritten" only when the abort worked and the branch is back on its old commit. */
|
|
138
|
+
async function restored(git, before, why) {
|
|
139
|
+
const aborted = await git.abortRebase() || await git.operationInProgress() === null;
|
|
140
|
+
const [now, branch] = await Promise.all([git.revParse('HEAD'), git.currentBranch()]);
|
|
141
|
+
const back = aborted && now === before.head && branch?.kind === 'branch' && branch.name === before.branch;
|
|
142
|
+
return back
|
|
143
|
+
? 'the rebase failed (' + why + '); nothing rewritten'
|
|
144
|
+
: 'the rebase failed (' + why + ') and the branch did not return; finish with git rebase --abort, and the original is at ' + before.backup;
|
|
145
|
+
}
|
package/dist/core/registry.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { mkdir, readFile, writeFile, rename, rm } from 'node:fs/promises';
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
17
|
import { join, dirname } from 'node:path';
|
|
18
|
-
import { ok, err } from
|
|
18
|
+
import { ok, err } from './result.js';
|
|
19
19
|
const EMPTY = { accounts: {}, unreadable: [] };
|
|
20
20
|
export function configDirectory() {
|
|
21
21
|
const explicit = process.env['REPOWN_CONFIG_DIR'];
|
package/dist/core/unpushed.js
CHANGED
|
@@ -2,68 +2,133 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Pinning does not rewrite them (ADR-013). The guard refuses them at push
|
|
4
4
|
// (ADR-002, ADR-011), so `use` and setup's review say so first, with a copyable
|
|
5
|
-
// `git rebase` onto the parent of the oldest of those commits
|
|
6
|
-
// has none)
|
|
7
|
-
//
|
|
5
|
+
// `git rebase` onto the parent of the oldest of those commits by another address
|
|
6
|
+
// (`--root` when it has none), so the user's own commits before it are left alone.
|
|
7
|
+
// The identities come from `git log` through Git.identitiesIn (`--no-show-signature`),
|
|
8
|
+
// the parents from Git.firstParentsIn.
|
|
9
|
+
// Where the branch pushes may have no remote-tracking ref at all; then the range can
|
|
10
|
+
// hold published commits, and the rebase is offered only for when it has none of
|
|
11
|
+
// them (push-destination.ts, ADR-025).
|
|
8
12
|
// scan's address totals are a different question: every ref, counts only, and
|
|
9
13
|
// setup loads them only for the guard question.
|
|
10
|
-
import { ok } from
|
|
14
|
+
import { ok } from './result.js';
|
|
15
|
+
import { unknownDestination } from './push-destination.js';
|
|
16
|
+
import { copyableCommand, shellWord } from './guard/check.js';
|
|
11
17
|
const ADDRESS_CAP = 3;
|
|
12
|
-
|
|
18
|
+
/** The one re-author command: the advice prints it, and `repown reauthor` runs it. */
|
|
19
|
+
export const AMEND_COMMAND = 'git commit --amend --no-edit --reset-author --allow-empty';
|
|
20
|
+
const AMEND = '--exec "' + AMEND_COMMAND + '"';
|
|
13
21
|
export async function readUnpushed(git) {
|
|
14
22
|
const head = await git.currentBranch();
|
|
15
23
|
if (head?.kind !== 'branch')
|
|
16
24
|
return quiet(null);
|
|
17
25
|
const commits = await commitsOf(git);
|
|
18
26
|
if (!commits.ok || commits.value.length === 0)
|
|
19
|
-
return { branch: head.name, commits,
|
|
20
|
-
return { branch: head.name, commits,
|
|
27
|
+
return { branch: head.name, commits, unknown: null };
|
|
28
|
+
return { branch: head.name, commits, unknown: await unknownDestination(git, head.name) };
|
|
21
29
|
}
|
|
22
30
|
function quiet(branch) {
|
|
23
|
-
return { branch, commits: ok([]),
|
|
24
|
-
}
|
|
25
|
-
/** Parent of the oldest unpushed commit, or `--root` when that commit has none. */
|
|
26
|
-
async function rebaseBase(git) {
|
|
27
|
-
const oldest = await git.oldestIn(['HEAD', '--not', '--remotes']);
|
|
28
|
-
if (!oldest)
|
|
29
|
-
return null;
|
|
30
|
-
return (await git.parentShort(oldest)) ?? '--root';
|
|
31
|
+
return { branch, commits: ok([]), unknown: null };
|
|
31
32
|
}
|
|
32
33
|
/** No commit yet is an empty list. A log git could not print stays an error. */
|
|
33
34
|
async function commitsOf(git) {
|
|
34
35
|
if (!await git.hasCommit('HEAD'))
|
|
35
36
|
return ok([]);
|
|
36
|
-
const
|
|
37
|
+
const range = ['HEAD', '--not', '--remotes'];
|
|
38
|
+
const [found, parents] = await Promise.all([git.identitiesIn(range), git.firstParentsIn(range)]);
|
|
37
39
|
if (!found.ok)
|
|
38
40
|
return found;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
if (!parents.ok)
|
|
42
|
+
return parents;
|
|
43
|
+
return ok(found.value.map((commit) => brief(commit, parents.value.get(commit.sha) ?? null)));
|
|
44
|
+
}
|
|
45
|
+
function brief(commit, parent) {
|
|
46
|
+
return { authorEmail: commit.authorEmail, committerEmail: commit.committerEmail, parent };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Lines to show. Empty when there is nothing to say. The first is the fact; any other is how
|
|
50
|
+
* to fix it. `account` is what to pin again to count again. `guarded` false: the guard is off, so
|
|
51
|
+
* the first line says they push as they are rather than that the guard will refuse them.
|
|
52
|
+
*/
|
|
53
|
+
export function unpushedLines(fact, email, account, guarded = true) {
|
|
46
54
|
if (fact.branch === null)
|
|
47
55
|
return [];
|
|
48
56
|
if (!fact.commits.ok)
|
|
49
57
|
return [unread(fact.branch, fact.commits.error)];
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
function foreignLines(branch, commits, email, base) {
|
|
53
|
-
const found = collect(commits, fold(email));
|
|
58
|
+
const found = collect(fact.commits.value, fold(email));
|
|
54
59
|
if (found.count === 0)
|
|
55
60
|
return [];
|
|
56
|
-
return [sentence(branch, found), ...
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
return [sentence(fact.branch, found, guarded), ...advice(fact, found, account)];
|
|
62
|
+
}
|
|
63
|
+
/** How many unpushed commits carry an address other than `email`. Zero when they could not be read. */
|
|
64
|
+
export function foreignCount(fact, email) {
|
|
65
|
+
return fact.commits.ok ? collect(fact.commits.value, fold(email)).count : 0;
|
|
66
|
+
}
|
|
67
|
+
/** The addresses other than `email` on those commits, as they appear. Empty when they could not be read. */
|
|
68
|
+
export function foreignAddresses(fact, email) {
|
|
69
|
+
return fact.commits.ok ? collect(fact.commits.value, fold(email)).addresses : [];
|
|
70
|
+
}
|
|
71
|
+
/** Behind an unknown destination the rebase is right only when it has none of these commits. */
|
|
72
|
+
function advice(fact, found, account) {
|
|
73
|
+
const rebase = reauthorLine(found);
|
|
74
|
+
if (!fact.unknown)
|
|
75
|
+
return rebase;
|
|
76
|
+
const holder = holderOf(fact.unknown);
|
|
77
|
+
return [unknownLine(fact.unknown, account), ...rebase.map((line) => 'if ' + holder + ' has none of them, ' + line)];
|
|
78
|
+
}
|
|
79
|
+
function holderOf(unknown) {
|
|
80
|
+
return unknown.kind === 'remote' || unknown.kind === 'pushurl' ? show(unknown.name) : 'it';
|
|
81
|
+
}
|
|
82
|
+
/** The guard excludes what the pushed branch's remote tip has, not everything the remote holds. */
|
|
83
|
+
const GUARD = ' (the guard skips any already on the branch you push to)';
|
|
84
|
+
const THERE = ', so some of these may already be there' + GUARD;
|
|
85
|
+
function unknownLine(unknown, account) {
|
|
86
|
+
switch (unknown.kind) {
|
|
87
|
+
case 'remote': return trackingLine(unknown.name, account);
|
|
88
|
+
case 'pushurl': return show(unknown.name) + ' pushes to another URL than it fetches from' + THERE;
|
|
89
|
+
case 'url': return urlLine(unknown.key, unknown.remote, account);
|
|
90
|
+
case 'unnamed': return 'this branch pushes to "' + show(unknown.name) + '", which is not a remote here' + THERE;
|
|
91
|
+
case 'unread': return 'the remotes could not be read, so some of these may already be on one' + GUARD;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function trackingLine(name, account) {
|
|
95
|
+
const lead = show(name) + ' has no remote-tracking refs, so some of these may already be on it' + GUARD;
|
|
96
|
+
const fetch = copyable(name) ? copyableCommand(['git', 'fetch', show(name)]) : null;
|
|
97
|
+
return fetch ? lead + ': ' + fetch + ', ' + recount(account) : lead;
|
|
98
|
+
}
|
|
99
|
+
function urlLine(key, remote, account) {
|
|
100
|
+
const lead = 'this branch pushes to a URL, not a remote' + THERE;
|
|
101
|
+
if (!remote || !copyable(remote))
|
|
102
|
+
return lead;
|
|
103
|
+
const repoint = copyableCommand(['git', 'config', '--local', show(key), show(remote)]);
|
|
104
|
+
const fetch = copyableCommand(['git', 'fetch', show(remote)]);
|
|
105
|
+
return repoint && fetch ? lead + ': ' + repoint + ', ' + fetch + ', ' + recount(account) : lead;
|
|
106
|
+
}
|
|
107
|
+
function recount(account) {
|
|
108
|
+
const word = shellWord(show(account));
|
|
109
|
+
return word ? 'then repown use ' + word + ' to count again' : 'then run repown use again to count again';
|
|
110
|
+
}
|
|
111
|
+
/** Quoting keeps a shell from splitting a word, not git from reading `-x` as an option. */
|
|
112
|
+
function copyable(word) {
|
|
113
|
+
return !word.startsWith('-');
|
|
114
|
+
}
|
|
115
|
+
/** Pinning is an alternative only when one address made them all. */
|
|
116
|
+
function reauthorLine(found) {
|
|
117
|
+
const them = found.count === 1 ? 'it' : 'them';
|
|
118
|
+
const pin = found.addresses.length === 1 ? ', or pin that address' : '';
|
|
119
|
+
return ['re-author ' + them + ': git rebase ' + found.base + ' ' + AMEND + pin];
|
|
63
120
|
}
|
|
64
121
|
function collect(commits, wanted) {
|
|
65
122
|
const foreign = commits.filter((commit) => !own(commit, wanted));
|
|
66
|
-
return { count: foreign.length, addresses: distinct(foreign, wanted) };
|
|
123
|
+
return { count: foreign.length, addresses: distinct(foreign, wanted), base: foreign.at(-1)?.parent ?? '--root' };
|
|
124
|
+
}
|
|
125
|
+
/** Author and committer are both `email`, in any case. */
|
|
126
|
+
export function isOwn(commit, email) {
|
|
127
|
+
return own(commit, fold(email));
|
|
128
|
+
}
|
|
129
|
+
/** The addresses other than `email` on these commits, each once, as first spelled. */
|
|
130
|
+
export function otherAddresses(commits, email) {
|
|
131
|
+
return distinct(commits, fold(email));
|
|
67
132
|
}
|
|
68
133
|
function own(commit, wanted) {
|
|
69
134
|
return fold(commit.authorEmail) === wanted && fold(commit.committerEmail) === wanted;
|
|
@@ -86,12 +151,13 @@ function remember(seen, address, wanted) {
|
|
|
86
151
|
function fold(address) {
|
|
87
152
|
return address.toLowerCase();
|
|
88
153
|
}
|
|
89
|
-
function sentence(branch, found) {
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
154
|
+
function sentence(branch, found, guarded) {
|
|
155
|
+
const one = found.count === 1;
|
|
156
|
+
const noun = one ? '1 commit' : found.count + ' commits';
|
|
157
|
+
const guard = guarded ? 'the guard will refuse ' + (one ? 'it' : 'them')
|
|
158
|
+
: 'the guard is off, so ' + (one ? 'it pushes as it is' : 'they push as they are');
|
|
159
|
+
return noun + ' on ' + show(branch) + ' not on any remote ' + (one ? 'is' : 'are') + ' by ' +
|
|
160
|
+
list(found.addresses) + '; ' + guard;
|
|
95
161
|
}
|
|
96
162
|
function list(addresses) {
|
|
97
163
|
const shown = addresses.slice(0, ADDRESS_CAP).map(show);
|
|
@@ -103,8 +169,11 @@ function unread(branch, error) {
|
|
|
103
169
|
return 'commits on ' + show(branch) + ' not on any remote could not be read (' +
|
|
104
170
|
show(error) + '), so repown can\'t say whether the guard will refuse them';
|
|
105
171
|
}
|
|
106
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* Control characters could redraw the terminal around a line taken from a commit, and
|
|
174
|
+
* bidi or zero-width ones make a copyable command read differently from what it pastes.
|
|
175
|
+
*/
|
|
107
176
|
function show(text) {
|
|
108
|
-
const cleaned = text.replace(/[\x00-\x1f\x7f-\x9f]/g, '?');
|
|
177
|
+
const cleaned = text.replace(/[\x00-\x1f\x7f-\x9f\u200b-\u200f\u202a-\u202e\u2066-\u2069\u2028\u2029\ufeff]/g, '?');
|
|
109
178
|
return cleaned.length > 0 ? cleaned : '(none)';
|
|
110
179
|
}
|
package/dist/program.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// The command table. cli.ts starts the program; the start screen's Show help
|
|
2
2
|
// loads this same table. Importing this file does not run repown.
|
|
3
3
|
export const COMMANDS = {
|
|
4
|
-
status: async () => (await import(
|
|
5
|
-
use: async () => (await import(
|
|
6
|
-
off: async () => (await import(
|
|
7
|
-
doctor: async () => (await import(
|
|
8
|
-
fix: async () => (await import(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
status: async () => (await import('./commands/status.js')).default,
|
|
5
|
+
use: async () => (await import('./commands/use.js')).default,
|
|
6
|
+
off: async () => (await import('./commands/off.js')).default,
|
|
7
|
+
doctor: async () => (await import('./commands/doctor.js')).default,
|
|
8
|
+
fix: async () => (await import('./commands/fix.js')).default,
|
|
9
|
+
reauthor: async () => (await import('./commands/reauthor.js')).default,
|
|
10
|
+
guard: async () => (await import('./commands/guard.js')).default,
|
|
11
|
+
accounts: async () => (await import('./commands/accounts.js')).default,
|
|
12
|
+
scan: async () => (await import('./commands/scan.js')).default,
|
|
13
|
+
setup: async () => (await import('./commands/setup.js')).default,
|
|
13
14
|
};
|
package/dist/ui/args.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
// earlier bug: `repown use --gh octocat` read "octocat" as --gh's value and left
|
|
10
10
|
// no account), an unknown option is refused rather than silently dropped, and
|
|
11
11
|
// so is an extra positional.
|
|
12
|
-
import { Git } from
|
|
13
|
-
import { ok, err } from
|
|
14
|
-
import { suggest } from
|
|
12
|
+
import { Git } from '../core/git.js';
|
|
13
|
+
import { ok, err } from '../core/result.js';
|
|
14
|
+
import { suggest } from './suggest.js';
|
|
15
15
|
export const NO_POSITIONALS = { min: 0, max: 0 };
|
|
16
16
|
/** For commands whose payload a script may read. Only `json` is a stable contract (ADR-014). */
|
|
17
17
|
export const FORMAT_OPTION = {
|
package/dist/ui/command.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// the same way, and one renderer (ui/help.ts) generate help for all of them
|
|
6
6
|
// from the same declarations, so help can never drift from what the parser
|
|
7
7
|
// actually accepts.
|
|
8
|
-
import { NO_POSITIONALS } from
|
|
8
|
+
import { NO_POSITIONALS } from './args.js';
|
|
9
9
|
export function isGroup(entry) {
|
|
10
10
|
return 'actions' in entry;
|
|
11
11
|
}
|
package/dist/ui/dispatch.js
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
//
|
|
6
6
|
// Kept apart from src/cli.ts so a second program (the release tool in scripts/)
|
|
7
7
|
// gets the same grammar without importing cli.ts, which runs repown.
|
|
8
|
-
import { parseArgs, hasHelpFlag } from
|
|
9
|
-
import { isGroup, resolveAlias, specFor } from
|
|
10
|
-
import { renderHelpFor } from
|
|
11
|
-
import { suggest } from
|
|
12
|
-
import { ok, err } from
|
|
13
|
-
import * as out from
|
|
8
|
+
import { parseArgs, hasHelpFlag } from './args.js';
|
|
9
|
+
import { isGroup, resolveAlias, specFor } from './command.js';
|
|
10
|
+
import { renderHelpFor } from './help.js';
|
|
11
|
+
import { suggest } from './suggest.js';
|
|
12
|
+
import { ok, err } from '../core/result.js';
|
|
13
|
+
import * as out from './format.js';
|
|
14
14
|
/** Every command the program declares, in declaration order. Help uses this, and so can a runner. */
|
|
15
15
|
export async function loadEntries(commands) {
|
|
16
16
|
const names = Object.keys(commands);
|
package/dist/ui/format.js
CHANGED
|
@@ -8,6 +8,7 @@ const COLOURS = {
|
|
|
8
8
|
green: '\x1b[32m',
|
|
9
9
|
yellow: '\x1b[33m',
|
|
10
10
|
red: '\x1b[31m',
|
|
11
|
+
cyan: '\x1b[36m',
|
|
11
12
|
dim: '\x1b[2m',
|
|
12
13
|
reset: '\x1b[0m',
|
|
13
14
|
};
|
|
@@ -33,6 +34,36 @@ export function useColour(stream) {
|
|
|
33
34
|
function paint(stream, colour, text) {
|
|
34
35
|
return useColour(stream) ? COLOURS[colour] + text + COLOURS.reset : text;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Whether the terminal draws symbols beyond ASCII: the signals @clack/prompts draws its own
|
|
39
|
+
* frame by, so a mark and the frame around it never disagree. Windows' legacy console does
|
|
40
|
+
* not; Windows Terminal, VS Code and mintty (TERM=xterm-256color) do (ADR-027).
|
|
41
|
+
*/
|
|
42
|
+
export function unicodeTerminal(env = process.env, platform = process.platform) {
|
|
43
|
+
if (platform !== 'win32')
|
|
44
|
+
return env['TERM'] !== 'linux';
|
|
45
|
+
return Boolean(env['CI'] || env['WT_SESSION'] || env['TERMINUS_SUBLIME'])
|
|
46
|
+
|| env['ConEmuTask'] === '{cmd::Cmder}'
|
|
47
|
+
|| ['Terminus-Sublime', 'vscode'].includes(env['TERM_PROGRAM'] ?? '')
|
|
48
|
+
|| ['xterm-256color', 'alacritty'].includes(env['TERM'] ?? '')
|
|
49
|
+
|| env['TERMINAL_EMULATOR'] === 'JetBrains-JediTerm';
|
|
50
|
+
}
|
|
51
|
+
/** Each mark's colour, its symbol, and the ASCII stand-in where Unicode can't be drawn. */
|
|
52
|
+
const MARKS = {
|
|
53
|
+
ok: { colour: 'green', unicode: '✔', ascii: '+' },
|
|
54
|
+
warn: { colour: 'yellow', unicode: '▲', ascii: '!' },
|
|
55
|
+
};
|
|
56
|
+
/** `text` led by a coloured mark where `stream` has colour; exactly `text` where it has none. */
|
|
57
|
+
export function marked(kind, stream, text) {
|
|
58
|
+
if (!useColour(stream))
|
|
59
|
+
return text;
|
|
60
|
+
const mark = MARKS[kind];
|
|
61
|
+
return paint(stream, mark.colour, unicodeTerminal() ? mark.unicode : mark.ascii) + ' ' + text;
|
|
62
|
+
}
|
|
63
|
+
/** A command, cyan where `stream` has colour. */
|
|
64
|
+
export function accent(stream, text) {
|
|
65
|
+
return paint(stream, 'cyan', text);
|
|
66
|
+
}
|
|
36
67
|
function status(level, tag, message) {
|
|
37
68
|
const word = paint(level.stream, level.colour, level.word.padEnd(5));
|
|
38
69
|
level.stream.write(word + ' ' + tag.padEnd(10) + ' ' + message + '\n');
|
|
@@ -75,6 +106,14 @@ export function heading(text) {
|
|
|
75
106
|
export function dim(text) {
|
|
76
107
|
return paint(process.stdout, 'dim', text);
|
|
77
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Control characters, and the invisible, line-breaking or direction-changing ones, as visible
|
|
111
|
+
* escapes: text read from git, a remote URL or a commit must neither redraw the screen nor
|
|
112
|
+
* read as another name.
|
|
113
|
+
*/
|
|
114
|
+
export function printable(text) {
|
|
115
|
+
return text.replace(/[\x00-\x1f\x7f-\x9f\xad\u061c\u180e\u200b-\u200f\u202a-\u202e\u2028\u2029\u2060-\u2064\u2066-\u2069\ufeff\ufff9-\ufffb\u{e0000}-\u{e007f}]/gu, (char) => '\\u' + char.codePointAt(0).toString(16).padStart(4, '0'));
|
|
116
|
+
}
|
|
78
117
|
/** Shown to a person. Windows uses native separators; any other platform is unchanged. */
|
|
79
118
|
export function displayPath(path) {
|
|
80
119
|
if (process.platform !== 'win32')
|
package/dist/ui/help.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// `out.line` calls, and nothing here is reachable except by an explicit
|
|
6
6
|
// `--help`/`-h`/`help` request. A command's `run()` never sees a help request --
|
|
7
7
|
// cli.ts intercepts it before parsing the command's own arguments.
|
|
8
|
-
import { GLOBAL_OPTIONS } from
|
|
9
|
-
import { isGroup, optionsOf } from
|
|
8
|
+
import { GLOBAL_OPTIONS } from './args.js';
|
|
9
|
+
import { isGroup, optionsOf } from './command.js';
|
|
10
10
|
export function renderTopHelp(entries) {
|
|
11
11
|
return [
|
|
12
12
|
...topHeader(entries),
|
package/dist/ui/prompt.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// whatever a command actually produces, so `repown accounts add x | tee log` does
|
|
11
11
|
// not interleave a prompt into the log.
|
|
12
12
|
import { createInterface } from 'node:readline/promises';
|
|
13
|
-
import { ok, err } from
|
|
13
|
+
import { ok, err } from '../core/result.js';
|
|
14
14
|
export function interactive() {
|
|
15
15
|
return process.stdin.isTTY === true && process.stderr.isTTY === true;
|
|
16
16
|
}
|