repown 0.5.1 → 0.5.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.
@@ -2,13 +2,14 @@
2
2
  //
3
3
  // The one place repown rewrites history, so it refuses rather than guesses. It fetches the
4
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
5
+ // topologically oldest one by another address, leaving out what the destination's branches
6
+ // and tags reach (ls-remote); a merge in that range, a commit a remote has inside it, or a
7
+ // destination with branches this clone has not fetched is a refusal. The
7
8
  // rebase runs with no hook at all, without autosquash and without moving other branches,
8
9
  // behind a backup ref that is never overwritten, and is checked afterwards: every commit
9
10
  // still there, each by the pin. Nothing here pushes.
10
11
  import { ok, err } from './result.js';
11
- import { pushTarget, unknownDestination } from './push-destination.js';
12
+ import { hasTrackingRefs, pushTarget, unknownDestination } from './push-destination.js';
12
13
  import { AMEND_COMMAND, isOwn, otherAddresses } from './unpushed.js';
13
14
  const IDENTITY_ENV = ['GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL'];
14
15
  const IDENTITY_CONFIG = ['author.email', 'committer.email', 'author.name', 'committer.name'];
@@ -24,7 +25,10 @@ export async function planReauthor(git, email, interactive) {
24
25
  const empty = await destinationEmpty(git, remote);
25
26
  if (!empty.ok)
26
27
  return empty;
27
- return foreignRange(git, { branch, remote, email, empty: empty.value });
28
+ const published = await publishedHere(git, remote);
29
+ if (!published.ok)
30
+ return published;
31
+ return foreignRange(git, { branch, remote, email, empty: empty.value, published: published.value });
28
32
  }
29
33
  async function preconditions(git, interactive) {
30
34
  const head = await git.currentBranch();
@@ -34,7 +38,7 @@ async function preconditions(git, interactive) {
34
38
  if (blocked)
35
39
  return err(blocked);
36
40
  const unknown = await unknownDestination(git, head.name);
37
- if (unknown && unknown.kind !== 'remote')
41
+ if (unknown && unknown.kind !== 'remote' && unknown.kind !== 'untracked')
38
42
  return err('this branch does not push to a remote repown can fetch: point the branch at a remote first');
39
43
  const target = await pushTarget(git, head.name);
40
44
  if (!target?.isRemote)
@@ -63,7 +67,7 @@ async function firstRefusal(git, interactive) {
63
67
  }
64
68
  /** True only when a successful fetch left no tracking refs AND the remote lists no branches. */
65
69
  async function destinationEmpty(git, remote) {
66
- const tracked = await git.hasTrackingRefs(remote);
70
+ const tracked = await hasTrackingRefs(git, remote);
67
71
  if (!tracked.ok)
68
72
  return tracked;
69
73
  if (tracked.value)
@@ -75,8 +79,31 @@ async function destinationEmpty(git, remote) {
75
79
  return err('this clone does not track ' + remote + '\'s branches, so it can\'t tell what ' + remote + ' already has');
76
80
  return ok(true);
77
81
  }
82
+ /**
83
+ * The commits the remote's branches and tags point at, as commits here: what a fetch
84
+ * refspec that leaves branches out, or a pushed tag, hides from `--not --remotes`.
85
+ * A branch tip this clone lacks may sit on top of these commits, so that is a refusal;
86
+ * a tag on a commit this clone lacks is skipped (tags are fetched only when they follow).
87
+ */
88
+ async function publishedHere(git, remote) {
89
+ const tips = await git.remoteTips(remote);
90
+ if (!tips.ok)
91
+ return err('could not list ' + remote + '\'s branches (' + tips.error + '); nothing rewritten');
92
+ const [heads, tags] = await Promise.all([git.localCommits(tips.value.heads), git.localCommits(tips.value.tags)]);
93
+ if (!heads.ok)
94
+ return heads;
95
+ if (!tags.ok)
96
+ return tags;
97
+ if (heads.value.includes(null))
98
+ return err(unfetched(remote));
99
+ return ok([...heads.value, ...tags.value].filter((sha) => sha !== null));
100
+ }
101
+ function unfetched(remote) {
102
+ return remote + ' has commits this clone has not fetched (remote.' + remote + '.fetch leaves some of its branches out, ' +
103
+ 'or something was pushed since the fetch), so repown can\'t tell which of these it already has; nothing rewritten';
104
+ }
78
105
  async function foreignRange(git, scope) {
79
- const listed = await git.identitiesIn(['--topo-order', 'HEAD', '--not', '--remotes']);
106
+ const listed = await git.identitiesIn(['--topo-order', 'HEAD', '--not', '--remotes'], scope.published);
80
107
  if (!listed.ok)
81
108
  return listed;
82
109
  const foreign = listed.value.filter((commit) => !isOwn(commit, scope.email));
@@ -87,16 +114,16 @@ async function foreignRange(git, scope) {
87
114
  if (!parent && !scope.empty)
88
115
  return err('the oldest of these commits is a root, and ' + scope.remote + ' is not empty');
89
116
  const base = parent ?? '--root';
90
- const checked = await checkRange(git, base);
117
+ const checked = await checkRange(git, base, scope.published);
91
118
  if (!checked.ok)
92
119
  return checked;
93
120
  return ok({ branch: scope.branch, remote: scope.remote, base, count: checked.value, addresses: otherAddresses(foreign, scope.email) });
94
121
  }
95
122
  /** The range must be linear and unpublished: a rebase flattens merges and rewrites all it covers. */
96
- async function checkRange(git, base) {
123
+ async function checkRange(git, base, published) {
97
124
  const range = base === '--root' ? ['HEAD'] : [base + '..HEAD'];
98
125
  const [all, merges, unpushed] = await Promise.all([
99
- git.countIn(range), git.countIn(['--merges', ...range]), git.countIn([...range, '--not', '--remotes']),
126
+ git.countIn(range), git.countIn(['--merges', ...range]), git.countIn([...range, '--not', '--remotes'], published),
100
127
  ]);
101
128
  if (!all.ok)
102
129
  return all;
@@ -0,0 +1,45 @@
1
+ // A remote's fetch refspecs (`remote.<name>.fetch`), read the way git reads them: which
2
+ // tracking ref a branch gets, and where the remote's tracking refs live (ADR-025).
3
+ //
4
+ // A clone made with --single-branch fetches only its one branch, and a negative refspec
5
+ // (`^refs/heads/x`) leaves a branch out. A push of such a branch updates no tracking ref,
6
+ // so `HEAD --not --remotes` cannot see what that push published.
7
+ /** `HEAD --not --remotes` counts only these: a tracking ref anywhere else proves nothing. */
8
+ const REMOTES = 'refs/remotes/';
9
+ /** The tracking ref the refspecs give `ref` (a full `refs/heads/...` name) under refs/remotes/, or null. */
10
+ export function trackingRefOf(specs, ref) {
11
+ const parsed = specs.map(parse);
12
+ if (parsed.some((spec) => spec.negative && matched(spec.src, ref) !== null))
13
+ return null;
14
+ for (const spec of parsed) {
15
+ const middle = spec.negative || !spec.dst ? null : matched(spec.src, ref);
16
+ const tracking = middle === null ? null : spec.dst.replace('*', middle);
17
+ if (tracking?.startsWith(REMOTES))
18
+ return tracking;
19
+ }
20
+ return null;
21
+ }
22
+ /** Where the refspecs write under refs/remotes/: the namespace before a glob's star, or the exact ref. */
23
+ export function trackingPrefixes(specs) {
24
+ const written = specs.map(parse).flatMap((spec) => spec.negative || !spec.dst ? [] : [spec.dst.split('*')[0]]);
25
+ return written.filter((prefix) => prefix.startsWith(REMOTES));
26
+ }
27
+ function parse(raw) {
28
+ const text = raw.trim().replace(/^\+/, '');
29
+ if (text.startsWith('^'))
30
+ return { src: text.slice(1), dst: null, negative: true };
31
+ const colon = text.indexOf(':');
32
+ if (colon < 0)
33
+ return { src: text, dst: null, negative: false };
34
+ return { src: text.slice(0, colon), dst: text.slice(colon + 1) || null, negative: false };
35
+ }
36
+ /** What the star stands for ('' for an exact match), or null when `ref` does not match. */
37
+ function matched(src, ref) {
38
+ const full = src.startsWith('refs/') ? src : 'refs/heads/' + src;
39
+ const star = full.indexOf('*');
40
+ if (star < 0)
41
+ return full === ref ? '' : null;
42
+ const [before, after] = [full.slice(0, star), full.slice(star + 1)];
43
+ const fits = ref.length >= before.length + after.length && ref.startsWith(before) && ref.endsWith(after);
44
+ return fits ? ref.slice(before.length, ref.length - after.length) : null;
45
+ }
@@ -0,0 +1,32 @@
1
+ // Commands printed for someone to copy and paste, quoted so every shell reads them the same
2
+ // (test/paste.test.ts runs each). Build any copyable word here, never by hand.
3
+ /**
4
+ * A word of a command printed to copy, as sh, bash, dash, zsh, fish, PowerShell and cmd all
5
+ * read it (test/paste.test.ts runs each). Bare when no shell treats any of it specially: a
6
+ * leading `@` is a PowerShell splat, and PowerShell splits a dashed word at `.` or `:`.
7
+ * `--` is quoted, since PowerShell drops a bare one from the `$args` of repown.ps1.
8
+ * Otherwise double quotes, unless they would expand or end early somewhere: `$` and a
9
+ * backtick (POSIX, PowerShell), `%` and `!` (cmd), a curly double quote (PowerShell), a
10
+ * backslash that escapes (`\\`, or one before the closing quote), a control character, or
11
+ * nothing at all (Windows PowerShell drops `""`). Then it is null and the caller prints no
12
+ * command: single quotes are no quotes in cmd, and PowerShell would run the rest of a
13
+ * POSIX `'\''` as code.
14
+ */
15
+ export function shellWord(value) {
16
+ if (value === '--')
17
+ return '"--"';
18
+ if (/^(?:-[\w-]*|[\w./][\w.@+/:-]*)$/.test(value))
19
+ return value;
20
+ if (value === '' || /["$`%!“”„\x00-\x1f\x7f-\x9f]|\\\\|\\$/.test(value))
21
+ return null;
22
+ return '"' + value + '"';
23
+ }
24
+ /** A whole command to copy, or null when one of its words can't be printed safely (shellWord). */
25
+ export function copyableCommand(words) {
26
+ const quoted = words.map(shellWord);
27
+ return quoted.every((word) => word !== null) ? quoted.join(' ') : null;
28
+ }
29
+ /** A git positional (a remote name) as argv words: after `--` when git would read it as an option. */
30
+ export function positional(word) {
31
+ return word.startsWith('-') ? ['--', word] : [word];
32
+ }
@@ -13,7 +13,7 @@
13
13
  // setup loads them only for the guard question.
14
14
  import { ok } from './result.js';
15
15
  import { unknownDestination } from './push-destination.js';
16
- import { copyableCommand, shellWord } from './guard/check.js';
16
+ import { copyableCommand, positional, shellWord } from './shell.js';
17
17
  const ADDRESS_CAP = 3;
18
18
  /** The one re-author command: the advice prints it, and `repown reauthor` runs it. */
19
19
  export const AMEND_COMMAND = 'git commit --amend --no-edit --reset-author --allow-empty';
@@ -77,7 +77,7 @@ function advice(fact, found, account) {
77
77
  return [unknownLine(fact.unknown, account), ...rebase.map((line) => 'if ' + holder + ' has none of them, ' + line)];
78
78
  }
79
79
  function holderOf(unknown) {
80
- return unknown.kind === 'remote' || unknown.kind === 'pushurl' ? show(unknown.name) : 'it';
80
+ return unknown.kind === 'remote' || unknown.kind === 'pushurl' || unknown.kind === 'untracked' ? show(unknown.name) : 'it';
81
81
  }
82
82
  /** The guard excludes what the pushed branch's remote tip has, not everything the remote holds. */
83
83
  const GUARD = ' (the guard skips any already on the branch you push to)';
@@ -86,6 +86,7 @@ function unknownLine(unknown, account) {
86
86
  switch (unknown.kind) {
87
87
  case 'remote': return trackingLine(unknown.name, account);
88
88
  case 'pushurl': return show(unknown.name) + ' pushes to another URL than it fetches from' + THERE;
89
+ case 'untracked': return untrackedLine(unknown.name, unknown.branch);
89
90
  case 'url': return urlLine(unknown.key, unknown.remote, account);
90
91
  case 'unnamed': return 'this branch pushes to "' + show(unknown.name) + '", which is not a remote here' + THERE;
91
92
  case 'unread': return 'the remotes could not be read, so some of these may already be on one' + GUARD;
@@ -93,25 +94,25 @@ function unknownLine(unknown, account) {
93
94
  }
94
95
  function trackingLine(name, account) {
95
96
  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
+ const fetch = copyableCommand(['git', 'fetch', ...positional(show(name))]);
97
98
  return fetch ? lead + ': ' + fetch + ', ' + recount(account) : lead;
98
99
  }
100
+ /** No fetch helps: the refspec itself leaves the branch out, so no tracking ref ever records it. */
101
+ function untrackedLine(remote, branch) {
102
+ return show(remote) + '\'s ' + show(branch) + ' is not fetched here (remote.' + show(remote) + '.fetch leaves it out)' + THERE;
103
+ }
99
104
  function urlLine(key, remote, account) {
100
105
  const lead = 'this branch pushes to a URL, not a remote' + THERE;
101
- if (!remote || !copyable(remote))
106
+ if (!remote)
102
107
  return lead;
103
108
  const repoint = copyableCommand(['git', 'config', '--local', show(key), show(remote)]);
104
- const fetch = copyableCommand(['git', 'fetch', show(remote)]);
109
+ const fetch = copyableCommand(['git', 'fetch', ...positional(show(remote))]);
105
110
  return repoint && fetch ? lead + ': ' + repoint + ', ' + fetch + ', ' + recount(account) : lead;
106
111
  }
107
112
  function recount(account) {
108
113
  const word = shellWord(show(account));
109
114
  return word ? 'then repown use ' + word + ' to count again' : 'then run repown use again to count again';
110
115
  }
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
116
  /** Pinning is an alternative only when one address made them all. */
116
117
  function reauthorLine(found) {
117
118
  const them = found.count === 1 ? 'it' : 'them';
package/dist/ui/format.js CHANGED
@@ -114,6 +114,17 @@ export function dim(text) {
114
114
  export function printable(text) {
115
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
116
  }
117
+ /** No column: combining marks, format characters (zero-width, bidi), variation selectors. */
118
+ const ZERO_WIDTH = /[\p{Mn}\p{Me}\p{Cf}\u{fe00}-\u{fe0f}]/u;
119
+ /** Two columns: East Asian Wide and Fullwidth, and the emoji blocks. */
120
+ const WIDE = /[\u{1100}-\u{115f}\u{2e80}-\u{303e}\u{3041}-\u{33ff}\u{3400}-\u{4dbf}\u{4e00}-\u{9fff}\u{a000}-\u{a4cf}\u{ac00}-\u{d7a3}\u{f900}-\u{faff}\u{fe30}-\u{fe4f}\u{ff00}-\u{ff60}\u{ffe0}-\u{ffe6}\u{1f004}\u{1f0cf}\u{1f300}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{1f900}-\u{1f9ff}\u{1fa70}-\u{1faff}\u{20000}-\u{3fffd}]/u;
121
+ /** The columns `text` takes in a terminal, for wrapping: not its length in UTF-16 units. */
122
+ export function displayWidth(text) {
123
+ let width = 0;
124
+ for (const char of text)
125
+ width += ZERO_WIDTH.test(char) ? 0 : WIDE.test(char) ? 2 : 1;
126
+ return width;
127
+ }
117
128
  /** Shown to a person. Windows uses native separators; any other platform is unchanged. */
118
129
  export function displayPath(path) {
119
130
  if (process.platform !== 'win32')
package/dist/ui/help.js CHANGED
@@ -12,7 +12,8 @@ export function renderTopHelp(entries) {
12
12
  ...topHeader(entries),
13
13
  ...globalOptionsHelp(),
14
14
  ...environmentHelp(),
15
- ' Exit codes: 0 success, 1 failure or refusal, 2 usage error.',
15
+ ' Exit codes: 0 success, 1 failure or refusal, 2 usage error,',
16
+ ' 130 cancelled (setup, the start screen).',
16
17
  '',
17
18
  ];
18
19
  }
@@ -14,13 +14,14 @@ import { signedInLogins } from './setup-flow.js';
14
14
  /** How many levels below this folder the start screen looks. `repown scan` looks further. */
15
15
  export const HOME_DEPTH = 2;
16
16
  export async function readHome(cwd, deps = {}) {
17
- const [registry, ghIsHelper, clones, identity] = await Promise.all([
18
- registryOf(deps), helperOf(cwd, deps), clonesOf(cwd, deps), (deps.identity ?? identityOf)(cwd),
19
- ]);
20
- return { cwd: resolve(cwd), registry, ghIsHelper, clones, identity };
17
+ const [registry, ghIsHelper, clones] = await Promise.all([registryOf(deps), helperOf(cwd, deps), clonesOf(cwd, deps)]);
18
+ return { cwd: resolve(cwd), registry, ghIsHelper, clones };
21
19
  }
22
- /** Outside a clone, git's own lookup is the global (or system) value. */
23
- async function identityOf(cwd) {
20
+ /**
21
+ * Global user.name and user.email, shown beside a new account's and never filled in: read only
22
+ * when Record an account is chosen. Outside a clone, git's own lookup is the global (or system) value.
23
+ */
24
+ export async function identityOf(cwd) {
24
25
  const git = new Git(cwd);
25
26
  const [name, email] = await Promise.all([git.getConfig('user.name'), git.getConfig('user.email')]);
26
27
  return { name, email };
@@ -6,7 +6,7 @@
6
6
  // Quit exits 0. Esc and Ctrl-C exit 130, the same cancel setup uses. Neither writes.
7
7
  import fixCommand from '../commands/fix.js';
8
8
  import doctorCommand from '../commands/doctor.js';
9
- import accountsGroup from '../commands/accounts.js';
9
+ import accountsGroup, { asked } from '../commands/accounts.js';
10
10
  import { COMMANDS } from '../program.js';
11
11
  import { parseArgs } from '../ui/args.js';
12
12
  import { specFor } from '../ui/command.js';
@@ -14,7 +14,7 @@ import { loadEntries } from '../ui/dispatch.js';
14
14
  import * as out from '../ui/format.js';
15
15
  import { renderTopHelp } from '../ui/help.js';
16
16
  import { CANCEL, runFlow } from './engine.js';
17
- import { readHome, readSignedIn } from './home-context.js';
17
+ import { identityOf, readHome, readSignedIn } from './home-context.js';
18
18
  import { BACK as HOME_BACK, MENU, accountChoices, accountOfChoice, commandFor, homeNote, listedClones, menuItems, summaryLines } from './home-flow.js';
19
19
  import { BACK_LABEL, BUSY, CANCELLED, QUIT, WHAT_NEXT, WHICH_ACCOUNT, WHICH_CLONE, homeTitle, recordBlocked, removeLabel, removeNote, removeQuestion } from './home-text.js';
20
20
  import { writeProblem } from '../core/registry.js';
@@ -110,7 +110,7 @@ async function recordAccount(prompter, home, deps) {
110
110
  prompter.note(recordBlocked(printable(blocked)));
111
111
  return null;
112
112
  }
113
- const ctx = accountContext(home, deps);
113
+ const ctx = accountContext(home, deps, await (deps.identity ?? identityOf)(home.cwd));
114
114
  const walk = await runFlow({ steps: [loginStep(ctx), ...profileSteps(ctx)] }, ctx, FIRST_PASS, prompter);
115
115
  if (walk.status === 'cancelled')
116
116
  return finish(prompter, CANCELLED, CANCELLED_CODE);
@@ -143,10 +143,10 @@ async function again(ran) {
143
143
  await ran;
144
144
  return AGAIN;
145
145
  }
146
- function accountContext(home, deps) {
146
+ function accountContext(home, deps, machineIdentity) {
147
147
  const recorded = home.registry.ok ? home.registry.value.accounts : {};
148
148
  return {
149
- recorded, host: 'github', machineIdentity: home.identity,
149
+ recorded, host: 'github', machineIdentity,
150
150
  suggest: deps.suggest ?? suggester(), signedIn: deps.signedIn ?? once(() => readSignedIn(home.cwd)),
151
151
  };
152
152
  }
@@ -162,7 +162,8 @@ async function runOwn(prompter, command, tokens, argv) {
162
162
  out.fail('repown', parsed.error);
163
163
  return 2;
164
164
  }
165
- return command.run(parsed.value);
165
+ // Record an account said while asking what accounts add would warn about a typed login.
166
+ return command.run(command === accountsGroup.actions['add'] ? asked(parsed.value) : parsed.value);
166
167
  }
167
168
  function setupArgs(cwd) {
168
169
  return { positional: [], flags: new Map([['cwd', cwd]]) };
@@ -2,6 +2,7 @@
2
2
  // screens say the same thing: the numbered steps, the closing lines, the question, its
3
3
  // choices and which one Enter takes, and "Change an answer". What goes IN the review
4
4
  // comes from the flow (setup-flow.ts).
5
+ import { displayWidth } from '../ui/format.js';
5
6
  /** "Change an answer": the question, and the choice that returns to the review. */
6
7
  export const PICK_QUESTION = 'Which answer do you want to change?';
7
8
  export const BACK_TO_REVIEW = 'Back to the review';
@@ -75,13 +76,13 @@ export function labelOf(text) {
75
76
  * past any indent, a "1. " step number, or a "label " column.
76
77
  */
77
78
  export function wrap(text, width) {
78
- if (text.length <= width)
79
+ if (displayWidth(text) <= width)
79
80
  return [text];
80
- const hang = ' '.repeat(HANG.exec(text)[0].length);
81
+ const hang = ' '.repeat(displayWidth(HANG.exec(text)[0]));
81
82
  const lines = [];
82
83
  let line = '';
83
84
  for (const word of text.split(/(?<=\S) (?=\S)/)) {
84
- if (line && line.length + 1 + word.length > width) {
85
+ if (line && displayWidth(line) + 1 + displayWidth(word) > width) {
85
86
  lines.push(line);
86
87
  line = hang + word.trimStart();
87
88
  }
@@ -3,7 +3,7 @@
3
3
  // and the machine (gh, the credential helper, the global identity, git's version).
4
4
  // Nothing here writes.
5
5
  import { gitSupportsAutoUpstream } from '../core/version.js';
6
- import { inspectRepo, inspectAuth } from '../core/inspect.js';
6
+ import { inspectRepo, inspectAuth, pinsCredential } from '../core/inspect.js';
7
7
  import { pinHolds } from '../core/identity.js';
8
8
  import { loadRegistry } from '../core/registry.js';
9
9
  import { planRepair } from '../core/credential/repair.js';
@@ -97,7 +97,7 @@ async function readFacts(git, repo, recorded, options) {
97
97
  return finishFacts(git, repo, recorded, loaded);
98
98
  }
99
99
  async function loadClone(git, repo, options) {
100
- const authPromise = options.auth ? Promise.resolve(options.auth) : inspectAuth(git, repo.originUrl ?? undefined);
100
+ const authPromise = options.auth ? Promise.resolve(options.auth) : inspectAuth(git, repo.credentialUrl ?? undefined);
101
101
  const [auth, pinned, allowed, planned, addresses, helpers, ownerIsUser, upstream, [unpushed, push]] = await Promise.all([
102
102
  authPromise,
103
103
  git.getConfig('repown.account', 'local'),
@@ -156,7 +156,7 @@ function assemble(cwd, recorded, repo, facts) {
156
156
  detected: facts.detected,
157
157
  ownerIsUser: facts.ownerIsUser,
158
158
  allowed: facts.allowed.map((owner) => owner.toLowerCase()),
159
- credentialPinned: repo.credentialKeys.length > 0, credentialKeys: repo.credentialKeys,
159
+ credentialPinned: pinsCredential(repo), credentialKeys: repo.credentialKeys,
160
160
  gh: facts.gh, ghIsHelper: facts.ghIsHelper,
161
161
  guard: repo.guard,
162
162
  redirected: repo.hook?.redirected ?? false, hookPath: repo.hook?.path ?? null,
@@ -245,11 +245,11 @@ async function pinIntact(git, pinned, entry, repo) {
245
245
  }
246
246
  /** The identity and push account git resolves for this clone, from every scope it reads. */
247
247
  async function gitUses(git, values, repo) {
248
- const pinsCredential = repo.credentialKeys.length > 0 && repo.originUrl !== null;
248
+ const pinned = pinsCredential(repo) && repo.credentialUrl !== null;
249
249
  const [name, email, user] = await Promise.all([
250
250
  git.getConfig('user.name'),
251
251
  git.getConfig('user.email'),
252
- pinsCredential ? git.getUrlMatch('credential.username', repo.originUrl) : Promise.resolve(values.account),
252
+ pinned ? git.getUrlMatch('credential.username', repo.credentialUrl) : Promise.resolve(values.account),
253
253
  ]);
254
254
  return name === values.name && email === values.email && user === values.account;
255
255
  }
@@ -9,7 +9,8 @@
9
9
  import { ghAdvice, upstreamText } from '../commands/status.js';
10
10
  import { providers } from '../core/hosts/index.js';
11
11
  import { isNoreplyAddress } from '../core/hosts/github.js';
12
- import { ALLOW_OWNER_BY_HAND, allowOwnerCommand, shellWord } from '../core/guard/check.js';
12
+ import { ALLOW_OWNER_BY_HAND, allowOwnerCommand } from '../core/guard/check.js';
13
+ import { positional, shellWord } from '../core/shell.js';
13
14
  import { printable } from '../ui/format.js';
14
15
  import { foreignAddresses, foreignCount } from '../core/unpushed.js';
15
16
  import { blockers } from '../core/blockers.js';
@@ -275,15 +276,18 @@ async function nameDetail(answers, ctx) {
275
276
  }
276
277
  /** On GitHub, when this machine is signed in as other logins only: perhaps not this person's account. */
277
278
  async function notSignedIn(answers, ctx) {
278
- if (hostOf(answers, ctx) !== 'github')
279
- return null;
280
- const logins = await ctx.signedIn();
281
- const login = accountOf(answers);
279
+ return hostOf(answers, ctx) === 'github' ? signedInNote(accountOf(answers), await ctx.signedIn(), 'go back') : null;
280
+ }
281
+ /**
282
+ * `signed in as A, not X: if X isn't your account, <undo>; ...`, or null when X is among the
283
+ * logins or none could be read. Typed `accounts add` says it too, with its own undo.
284
+ */
285
+ export function signedInNote(login, logins, undo) {
282
286
  if (!logins || logins.length === 0 || logins.some((other) => other.toLowerCase() === login.toLowerCase()))
283
287
  return null;
284
288
  const shown = printable(login);
285
289
  return 'signed in as ' + logins.map(printable).join(', ') + ', not ' + shown + ': if ' + shown +
286
- ' isn\'t your account, go back; otherwise the first push asks you to sign in as it';
290
+ ' isn\'t your account, ' + undo + '; otherwise the first push asks you to sign in as it';
287
291
  }
288
292
  /** Said when the name question starts as the login: no profile name was found. */
289
293
  function loginPrefill(answers, found, ctx) {
@@ -583,11 +587,11 @@ function repointArgv(answers, ctx) {
583
587
  }
584
588
  function fetchArgv(answers, ctx) {
585
589
  const remote = answers['fetch'] === true ? fetchTarget(answers, ctx) : null;
586
- return remote ? [...gitIn(ctx), 'fetch', remote] : null;
590
+ return remote ? [...gitIn(ctx), 'fetch', ...positional(remote)] : null;
587
591
  }
588
592
  export function gitStepOf(argv) {
589
593
  const sub = argv[1] === '-C' ? argv.slice(3) : argv.slice(1);
590
- if (sub[0] === 'fetch' && sub.length === 2)
594
+ if (sub[0] === 'fetch' && (sub.length === 2 || (sub.length === 3 && sub[1] === '--')))
591
595
  return 'fetch';
592
596
  if (sub[0] !== 'config' || sub[1] !== '--local')
593
597
  return null;
@@ -619,7 +623,7 @@ function gitWhat(argv, ctx) {
619
623
  if (step === 'repoint')
620
624
  return 'Push through ' + argv.at(-1) + ' instead of the URL in ' + argv.at(-2) + ' (this clone only)';
621
625
  if (step === 'fetch')
622
- return 'Fetch ' + argv.at(-1) + ', so repown can tell which commits it already has';
626
+ return 'Fetch ' + argv.at(-1) + ', so repown can tell which commits it already has (prompts off: a sign-in that would ask fails instead)';
623
627
  if (step === 'upstream')
624
628
  return 'Push branches without -u: the first push sets the upstream (this clone only)';
625
629
  return 'Let this clone push to ' + ctx.owner + '\'s repositories';
@@ -16,7 +16,7 @@ import useCommand, { NEXT_GUARD } from '../commands/use.js';
16
16
  import fixCommand from '../commands/fix.js';
17
17
  import reauthorCommand from '../commands/reauthor.js';
18
18
  import guardGroup from '../commands/guard.js';
19
- import accountsGroup from '../commands/accounts.js';
19
+ import accountsGroup, { asked } from '../commands/accounts.js';
20
20
  import { wizard, refusedGiven } from './engine.js';
21
21
  import { setupFlow, planCommands, formatCommand, gitStepOf, keptFlags, briefOf, missingFlags, printable, dropFixPrefix, NEW_ACCOUNT, accountOf, pinUnchanged, ghNoted } from './setup-flow.js';
22
22
  import { cloneChangeLines, machineChangeLines, readCloneSnapshot } from './setup-changes.js';
@@ -462,7 +462,8 @@ async function runOne(argv, git) {
462
462
  out.fail('setup', 'could not run ' + formatCommand(argv) + ': ' + parsed.error);
463
463
  return 2;
464
464
  }
465
- return command.run(parsed.value);
465
+ // Setup said while asking what accounts add would warn about a typed login.
466
+ return command.run(command === accountsGroup.actions['add'] ? asked(parsed.value) : parsed.value);
466
467
  }
467
468
  /** The Command a planned argv names, and the arguments after its name; null for anything else. */
468
469
  function commandFor(argv) {
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "repown",
9
- "version": "0.5.1",
9
+ "version": "0.5.2",
10
10
  "license": "MIT",
11
11
  "bin": {
12
12
  "repown": "dist/cli.js"
13
13
  },
14
14
  "devDependencies": {
15
- "@types/node": "^26.6.3",
15
+ "@types/node": "^26.6.4",
16
16
  "typescript": "^7.0.2"
17
17
  },
18
18
  "engines": {
@@ -53,9 +53,9 @@
53
53
  }
54
54
  },
55
55
  "node_modules/@types/node": {
56
- "version": "26.6.3",
57
- "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.3.tgz",
58
- "integrity": "sha512-dsqMQQoeTLqu9wynDD00q573mNzso3IdQOAfHRJqLCcmCFPoGo9A1bDpUcv/9tnKpErQWv9uKeGfl37EIS02Yg==",
56
+ "version": "26.6.4",
57
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.4.tgz",
58
+ "integrity": "sha512-ldVPDCzj7fsaGZrLB0NuHuTvJcsNasysBAqMolr/cgxrLd1xbqxIr3XJiPnHHJUCxj5sNF1vnRj9aWnrVh5Jcg==",
59
59
  "dev": true,
60
60
  "license": "MIT",
61
61
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repown",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Use several git accounts on one machine: each repo owns its identity, so you move between repos with no switch command and never push the wrong one.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,7 +54,7 @@
54
54
  "access": "public"
55
55
  },
56
56
  "devDependencies": {
57
- "@types/node": "^26.6.3",
57
+ "@types/node": "^26.6.4",
58
58
  "typescript": "^7.0.2"
59
59
  },
60
60
  "optionalDependencies": {