@lbdudc/linea-git 0.0.0-stage → 0.1.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.
- package/README.md +47 -2
- package/dist/access.d.ts +18 -0
- package/dist/access.js +18 -0
- package/dist/access.js.map +1 -0
- package/dist/auth.d.ts +11 -0
- package/dist/auth.js +16 -0
- package/dist/auth.js.map +1 -0
- package/dist/changelog/generate.d.ts +18 -0
- package/dist/changelog/generate.js +166 -0
- package/dist/changelog/generate.js.map +1 -0
- package/dist/changelog/index.d.ts +5 -0
- package/dist/changelog/index.js +3 -0
- package/dist/changelog/index.js.map +1 -0
- package/dist/changelog/parse.d.ts +43 -0
- package/dist/changelog/parse.js +91 -0
- package/dist/changelog/parse.js.map +1 -0
- package/dist/changelog/types.d.ts +85 -0
- package/dist/changelog/types.js +2 -0
- package/dist/changelog/types.js.map +1 -0
- package/dist/checkout/credential.d.ts +14 -0
- package/dist/checkout/credential.js +29 -0
- package/dist/checkout/credential.js.map +1 -0
- package/dist/checkout/git.d.ts +78 -0
- package/dist/checkout/git.js +191 -0
- package/dist/checkout/git.js.map +1 -0
- package/dist/checkout/index.d.ts +3 -0
- package/dist/checkout/index.js +4 -0
- package/dist/checkout/index.js.map +1 -0
- package/dist/checkout/sync.d.ts +156 -0
- package/dist/checkout/sync.js +211 -0
- package/dist/checkout/sync.js.map +1 -0
- package/dist/closing.d.ts +1 -0
- package/dist/closing.js +14 -0
- package/dist/closing.js.map +1 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.js +40 -0
- package/dist/config.js.map +1 -0
- package/dist/deletion.d.ts +19 -0
- package/dist/deletion.js +27 -0
- package/dist/deletion.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/factory.d.ts +20 -0
- package/dist/factory.js +46 -0
- package/dist/factory.js.map +1 -0
- package/dist/github/client.d.ts +44 -0
- package/dist/github/client.js +145 -0
- package/dist/github/client.js.map +1 -0
- package/dist/github/config.d.ts +24 -0
- package/dist/github/config.js +11 -0
- package/dist/github/config.js.map +1 -0
- package/dist/github/provider.d.ts +510 -0
- package/dist/github/provider.js +1009 -0
- package/dist/github/provider.js.map +1 -0
- package/dist/gitlab/client.d.ts +50 -0
- package/dist/gitlab/client.js +228 -0
- package/dist/gitlab/client.js.map +1 -0
- package/dist/gitlab/provider.d.ts +487 -0
- package/dist/gitlab/provider.js +719 -0
- package/dist/gitlab/provider.js.map +1 -0
- package/dist/host.d.ts +27 -0
- package/dist/host.js +45 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/local/diff.d.ts +3 -0
- package/dist/local/diff.js +43 -0
- package/dist/local/diff.js.map +1 -0
- package/dist/local/git.d.ts +24 -0
- package/dist/local/git.js +51 -0
- package/dist/local/git.js.map +1 -0
- package/dist/local/health.d.ts +36 -0
- package/dist/local/health.js +57 -0
- package/dist/local/health.js.map +1 -0
- package/dist/local/hooks.d.ts +2 -0
- package/dist/local/hooks.js +44 -0
- package/dist/local/hooks.js.map +1 -0
- package/dist/local/http.d.ts +35 -0
- package/dist/local/http.js +160 -0
- package/dist/local/http.js.map +1 -0
- package/dist/local/provider.d.ts +571 -0
- package/dist/local/provider.js +1237 -0
- package/dist/local/provider.js.map +1 -0
- package/dist/local/store.d.ts +136 -0
- package/dist/local/store.js +171 -0
- package/dist/local/store.js.map +1 -0
- package/dist/packages/github-source.d.ts +69 -0
- package/dist/packages/github-source.js +133 -0
- package/dist/packages/github-source.js.map +1 -0
- package/dist/packages/gitlab-source.d.ts +59 -0
- package/dist/packages/gitlab-source.js +214 -0
- package/dist/packages/gitlab-source.js.map +1 -0
- package/dist/packages/index.d.ts +30 -0
- package/dist/packages/index.js +45 -0
- package/dist/packages/index.js.map +1 -0
- package/dist/packages/provider-source.d.ts +34 -0
- package/dist/packages/provider-source.js +57 -0
- package/dist/packages/provider-source.js.map +1 -0
- package/dist/packages/repository-files.d.ts +12 -0
- package/dist/packages/repository-files.js +16 -0
- package/dist/packages/repository-files.js.map +1 -0
- package/dist/provider.d.ts +888 -0
- package/dist/provider.js +29 -0
- package/dist/provider.js.map +1 -0
- package/dist/read-cache.d.ts +5 -0
- package/dist/read-cache.js +101 -0
- package/dist/read-cache.js.map +1 -0
- package/dist/registry/catalog.d.ts +55 -0
- package/dist/registry/catalog.js +143 -0
- package/dist/registry/catalog.js.map +1 -0
- package/dist/registry/kinds.d.ts +21 -0
- package/dist/registry/kinds.js +43 -0
- package/dist/registry/kinds.js.map +1 -0
- package/dist/registry/packages.d.ts +165 -0
- package/dist/registry/packages.js +290 -0
- package/dist/registry/packages.js.map +1 -0
- package/dist/registry/publish.d.ts +35 -0
- package/dist/registry/publish.js +155 -0
- package/dist/registry/publish.js.map +1 -0
- package/dist/registry/release.d.ts +63 -0
- package/dist/registry/release.js +79 -0
- package/dist/registry/release.js.map +1 -0
- package/dist/restoration.d.ts +14 -0
- package/dist/restoration.js +33 -0
- package/dist/restoration.js.map +1 -0
- package/dist/templates.d.ts +8 -0
- package/dist/templates.js +39 -0
- package/dist/templates.js.map +1 -0
- package/dist/testing/contract.d.ts +43 -0
- package/dist/testing/contract.js +713 -0
- package/dist/testing/contract.js.map +1 -0
- package/dist/testing/diff.d.ts +1 -0
- package/dist/testing/diff.js +65 -0
- package/dist/testing/diff.js.map +1 -0
- package/dist/testing/git-http.d.ts +12 -0
- package/dist/testing/git-http.js +308 -0
- package/dist/testing/git-http.js.map +1 -0
- package/dist/testing/github-double.d.ts +151 -0
- package/dist/testing/github-double.js +1129 -0
- package/dist/testing/github-double.js.map +1 -0
- package/dist/testing/gitlab-double.d.ts +161 -0
- package/dist/testing/gitlab-double.js +1554 -0
- package/dist/testing/gitlab-double.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +12 -0
- package/dist/version.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { CommitSummary, GitProvider, Id } from '../provider.js';
|
|
2
|
+
/** The kinds of change a Conventional Commit can name that LINEA knows about; anything else lands in `other`. */
|
|
3
|
+
export type CommitType = 'feat' | 'fix' | 'perf' | 'refactor' | 'docs' | 'chore' | 'ci' | 'test';
|
|
4
|
+
export type SectionId = 'breaking' | 'features' | 'fixes' | 'performance' | 'other';
|
|
5
|
+
/** A `#N` (issue) or `!N` (merge request) found in a commit, with what the host says about it when it could be resolved. */
|
|
6
|
+
export interface ChangelogReference {
|
|
7
|
+
kind: 'issue' | 'mergeRequest';
|
|
8
|
+
number: number;
|
|
9
|
+
/** Empty when the host has no such item (or it could not be read). */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Empty when it was not resolved. */
|
|
12
|
+
webUrl: string;
|
|
13
|
+
resolved: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** One commit of the range, read as a Conventional Commit. */
|
|
16
|
+
export interface ChangelogCommit {
|
|
17
|
+
shortId: string;
|
|
18
|
+
title: string;
|
|
19
|
+
webUrl: string;
|
|
20
|
+
authorName: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
/** The type it declares (lower case), or `null` when it does not follow the convention. */
|
|
23
|
+
type: string | null;
|
|
24
|
+
scope: string | null;
|
|
25
|
+
/** What the change is, without the `type(scope):` prefix. */
|
|
26
|
+
description: string;
|
|
27
|
+
breaking: boolean;
|
|
28
|
+
/** The text of `BREAKING CHANGE:`, when the commit has one. */
|
|
29
|
+
breakingNote: string | null;
|
|
30
|
+
references: {
|
|
31
|
+
kind: 'issue' | 'mergeRequest';
|
|
32
|
+
number: number;
|
|
33
|
+
}[];
|
|
34
|
+
section: SectionId | null;
|
|
35
|
+
}
|
|
36
|
+
export interface ChangelogEntry {
|
|
37
|
+
shortId: string;
|
|
38
|
+
webUrl: string;
|
|
39
|
+
type: string | null;
|
|
40
|
+
scope: string | null;
|
|
41
|
+
description: string;
|
|
42
|
+
breaking: boolean;
|
|
43
|
+
breakingNote: string | null;
|
|
44
|
+
references: ChangelogReference[];
|
|
45
|
+
}
|
|
46
|
+
export interface ChangelogSection {
|
|
47
|
+
id: SectionId;
|
|
48
|
+
title: string;
|
|
49
|
+
entries: ChangelogEntry[];
|
|
50
|
+
}
|
|
51
|
+
export interface Changelog {
|
|
52
|
+
from: string | null;
|
|
53
|
+
to: string;
|
|
54
|
+
/** The range was cut: the history has more commits than a host gives (or than the generator reads). */
|
|
55
|
+
truncated: boolean;
|
|
56
|
+
markdown: string;
|
|
57
|
+
/** Only the sections that have entries, in a fixed order. */
|
|
58
|
+
sections: ChangelogSection[];
|
|
59
|
+
/** Every commit of the range that was kept (hidden types and ignored commits are not here). */
|
|
60
|
+
commits: ChangelogCommit[];
|
|
61
|
+
/** Every merge request mentioned by the kept commits and by the merges that were dropped, sorted by number. */
|
|
62
|
+
mergeRequests: ChangelogReference[];
|
|
63
|
+
/** Every issue mentioned, sorted by number. */
|
|
64
|
+
issues: ChangelogReference[];
|
|
65
|
+
}
|
|
66
|
+
export interface ChangelogOptions {
|
|
67
|
+
provider: GitProvider;
|
|
68
|
+
token: string;
|
|
69
|
+
id: Id;
|
|
70
|
+
/** Where the range starts (exclusive). Default: the greatest `vX.Y.Z` tag lower than `to`; with none, the first commit. */
|
|
71
|
+
from?: string | null | undefined;
|
|
72
|
+
/** A tag or a ref. */
|
|
73
|
+
to: string;
|
|
74
|
+
/** Types that are hidden by default (`chore`, `ci`, `test`, `docs`) and that should be shown, under «Otros». */
|
|
75
|
+
include?: string[];
|
|
76
|
+
/** More commits to leave out, on top of the defaults: tested against the title of each commit. */
|
|
77
|
+
ignore?: RegExp[];
|
|
78
|
+
/** Leave out version bumps and the commits LINEA itself makes (generations, syncs). Default `true`. */
|
|
79
|
+
ignoreDefaults?: boolean;
|
|
80
|
+
/** Heading of the markdown. Default: `to`. */
|
|
81
|
+
title?: string;
|
|
82
|
+
/** The language of the notes (their headings and fixed phrases). Default `en`. */
|
|
83
|
+
locale?: 'en' | 'es' | 'gl';
|
|
84
|
+
}
|
|
85
|
+
export type { CommitSummary };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/changelog/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CommitSummary, GitProvider, Id } from '../provider.js'\n\n/** The kinds of change a Conventional Commit can name that LINEA knows about; anything else lands in `other`. */\nexport type CommitType = 'feat' | 'fix' | 'perf' | 'refactor' | 'docs' | 'chore' | 'ci' | 'test'\n\nexport type SectionId = 'breaking' | 'features' | 'fixes' | 'performance' | 'other'\n\n/** A `#N` (issue) or `!N` (merge request) found in a commit, with what the host says about it when it could be resolved. */\nexport interface ChangelogReference {\n kind: 'issue' | 'mergeRequest'\n number: number\n /** Empty when the host has no such item (or it could not be read). */\n title: string\n /** Empty when it was not resolved. */\n webUrl: string\n resolved: boolean\n}\n\n/** One commit of the range, read as a Conventional Commit. */\nexport interface ChangelogCommit {\n shortId: string\n title: string\n webUrl: string\n authorName: string\n createdAt: string\n /** The type it declares (lower case), or `null` when it does not follow the convention. */\n type: string | null\n scope: string | null\n /** What the change is, without the `type(scope):` prefix. */\n description: string\n breaking: boolean\n /** The text of `BREAKING CHANGE:`, when the commit has one. */\n breakingNote: string | null\n references: { kind: 'issue' | 'mergeRequest', number: number }[]\n section: SectionId | null\n}\n\nexport interface ChangelogEntry {\n shortId: string\n webUrl: string\n type: string | null\n scope: string | null\n description: string\n breaking: boolean\n breakingNote: string | null\n references: ChangelogReference[]\n}\n\nexport interface ChangelogSection {\n id: SectionId\n title: string\n entries: ChangelogEntry[]\n}\n\nexport interface Changelog {\n from: string | null\n to: string\n /** The range was cut: the history has more commits than a host gives (or than the generator reads). */\n truncated: boolean\n markdown: string\n /** Only the sections that have entries, in a fixed order. */\n sections: ChangelogSection[]\n /** Every commit of the range that was kept (hidden types and ignored commits are not here). */\n commits: ChangelogCommit[]\n /** Every merge request mentioned by the kept commits and by the merges that were dropped, sorted by number. */\n mergeRequests: ChangelogReference[]\n /** Every issue mentioned, sorted by number. */\n issues: ChangelogReference[]\n}\n\nexport interface ChangelogOptions {\n provider: GitProvider\n token: string\n id: Id\n /** Where the range starts (exclusive). Default: the greatest `vX.Y.Z` tag lower than `to`; with none, the first commit. */\n from?: string | null | undefined\n /** A tag or a ref. */\n to: string\n /** Types that are hidden by default (`chore`, `ci`, `test`, `docs`) and that should be shown, under «Otros». */\n include?: string[]\n /** More commits to leave out, on top of the defaults: tested against the title of each commit. */\n ignore?: RegExp[]\n /** Leave out version bumps and the commits LINEA itself makes (generations, syncs). Default `true`. */\n ignoreDefaults?: boolean\n /** Heading of the markdown. Default: `to`. */\n title?: string\n /** The language of the notes (their headings and fixed phrases). Default `en`. */\n locale?: 'en' | 'es' | 'gl'\n}\n\nexport type { CommitSummary }\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The side of a git credential helper that does not depend on who runs it: git asks with `key=value` lines and takes the same as the
|
|
3
|
+
* answer (https://git-scm.com/docs/git-credential). A helper answers only for the host it has access for, and never prompts.
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseCredentialRequest(input: string): Record<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* What a helper says to a request: the username and password when the request is for `host` (same protocol, same host), nothing
|
|
8
|
+
* otherwise (git goes on to the next helper).
|
|
9
|
+
*/
|
|
10
|
+
export declare function answerCredentialRequest(input: string, access: {
|
|
11
|
+
host: URL | undefined;
|
|
12
|
+
username: string;
|
|
13
|
+
token: string;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The side of a git credential helper that does not depend on who runs it: git asks with `key=value` lines and takes the same as the
|
|
3
|
+
* answer (https://git-scm.com/docs/git-credential). A helper answers only for the host it has access for, and never prompts.
|
|
4
|
+
*/
|
|
5
|
+
export function parseCredentialRequest(input) {
|
|
6
|
+
const fields = {};
|
|
7
|
+
for (const line of input.split(/\r?\n/)) {
|
|
8
|
+
const i = line.indexOf('=');
|
|
9
|
+
if (i > 0)
|
|
10
|
+
fields[line.slice(0, i)] = line.slice(i + 1);
|
|
11
|
+
}
|
|
12
|
+
return fields;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What a helper says to a request: the username and password when the request is for `host` (same protocol, same host), nothing
|
|
16
|
+
* otherwise (git goes on to the next helper).
|
|
17
|
+
*/
|
|
18
|
+
export function answerCredentialRequest(input, access) {
|
|
19
|
+
const request = parseCredentialRequest(input);
|
|
20
|
+
const { host } = access;
|
|
21
|
+
if (!host || !request['host'])
|
|
22
|
+
return '';
|
|
23
|
+
if (request['protocol'] && `${request['protocol']}:` !== host.protocol)
|
|
24
|
+
return '';
|
|
25
|
+
if (request['host'].toLowerCase() !== host.host.toLowerCase())
|
|
26
|
+
return '';
|
|
27
|
+
return `username=${access.username}\npassword=${access.token}\n`;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../../src/checkout/credential.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,sBAAsB,CAAE,KAAa;IACnD,MAAM,MAAM,GAA2B,EAAE,CAAA;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,CAAC,GAAG,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACzD,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAE,KAAa,EAAE,MAAkE;IACxH,MAAM,OAAO,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAA;IAC7C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IACvB,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAA;IACxC,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,KAAK,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,CAAA;IACjF,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;QAAE,OAAO,EAAE,CAAA;IACxE,OAAO,YAAY,MAAM,CAAC,QAAQ,cAAc,MAAM,CAAC,KAAK,IAAI,CAAA;AAClE,CAAC","sourcesContent":["/**\n * The side of a git credential helper that does not depend on who runs it: git asks with `key=value` lines and takes the same as the\n * answer (https://git-scm.com/docs/git-credential). A helper answers only for the host it has access for, and never prompts.\n */\n\nexport function parseCredentialRequest (input: string): Record<string, string> {\n const fields: Record<string, string> = {}\n for (const line of input.split(/\\r?\\n/)) {\n const i = line.indexOf('=')\n if (i > 0) fields[line.slice(0, i)] = line.slice(i + 1)\n }\n return fields\n}\n\n/**\n * What a helper says to a request: the username and password when the request is for `host` (same protocol, same host), nothing\n * otherwise (git goes on to the next helper).\n */\nexport function answerCredentialRequest (input: string, access: { host: URL | undefined, username: string, token: string }): string {\n const request = parseCredentialRequest(input)\n const { host } = access\n if (!host || !request['host']) return ''\n if (request['protocol'] && `${request['protocol']}:` !== host.protocol) return ''\n if (request['host'].toLowerCase() !== host.host.toLowerCase()) return ''\n return `username=${access.username}\\npassword=${access.token}\\n`\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The git of your machine, run as `git` does. Arguments only (never a shell line), and no prompts: a command that cannot go on says
|
|
3
|
+
* why instead of waiting for a person.
|
|
4
|
+
*/
|
|
5
|
+
export interface GitResult {
|
|
6
|
+
status: number;
|
|
7
|
+
stdout: string;
|
|
8
|
+
stderr: string;
|
|
9
|
+
}
|
|
10
|
+
/** git, and wait for it (for what is quick and local: status, add, commit). Anything that goes over the network uses `gitAsync`. */
|
|
11
|
+
export declare function git(cwd: string | undefined, args: string[], opts?: {
|
|
12
|
+
input?: string;
|
|
13
|
+
}): GitResult;
|
|
14
|
+
/**
|
|
15
|
+
* git, without holding everything up (a window keeps drawing while a clone or a push runs). `onProgress` gets what git says as it
|
|
16
|
+
* goes ("Receiving objects: 45%"), one line at a time: ask for it with `--progress`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function gitAsync(cwd: string | undefined, args: string[], opts?: {
|
|
19
|
+
onProgress?: (line: string) => void;
|
|
20
|
+
env?: Record<string, string>;
|
|
21
|
+
input?: string;
|
|
22
|
+
}): Promise<GitResult>;
|
|
23
|
+
/** Whether what git said is an authentication failure. */
|
|
24
|
+
export declare const isAuthFailure: (said: string) => boolean;
|
|
25
|
+
/** What git said, without the credentials of an address in it. */
|
|
26
|
+
export declare const withoutCredentials: (said: string) => string;
|
|
27
|
+
/** A failed git command: what git said, and whether that was the host refusing access (`denied`). */
|
|
28
|
+
export declare class GitCommandError extends Error {
|
|
29
|
+
readonly command: string;
|
|
30
|
+
readonly said: string;
|
|
31
|
+
constructor(command: string, said: string);
|
|
32
|
+
get denied(): boolean;
|
|
33
|
+
}
|
|
34
|
+
/** `git`, and the output; a failure throws a `GitCommandError`. */
|
|
35
|
+
export declare function gitOk(cwd: string | undefined, args: string[]): string;
|
|
36
|
+
/** `gitAsync`, and the output; a failure throws a `GitCommandError`. */
|
|
37
|
+
export declare function gitOkAsync(cwd: string | undefined, args: string[], opts?: {
|
|
38
|
+
onProgress?: (line: string) => void;
|
|
39
|
+
}): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether git can read a repository with this username and token, as it will when it uses them: the answer to "is this token good for
|
|
42
|
+
* git?", which is not the same as "is it good for the host's API?" (a GitLab token needs `read_repository`, or `api`, for git). The
|
|
43
|
+
* token goes to git in its environment, not on a command line others can read, and nothing is kept.
|
|
44
|
+
*/
|
|
45
|
+
export declare function checkGitAccess(url: string, username: string, token: string): Promise<{
|
|
46
|
+
ok: true;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
said: string;
|
|
50
|
+
}>;
|
|
51
|
+
export declare function isRepo(dir: string): boolean;
|
|
52
|
+
/** The address `git` clones from for a repository the host shows at `webUrl`: the same, plus `.git` (GitLab and GitHub both). */
|
|
53
|
+
export declare const cloneUrlOf: (webUrl: string) => string;
|
|
54
|
+
/**
|
|
55
|
+
* `-c` options that make git use a credential helper (`helper`: what git runs, as `credential.helper` says: `!program args`) for a
|
|
56
|
+
* command that has no repository yet (clone). For the whole command, not for the host in it: an empty `credential.helper` forgets every
|
|
57
|
+
* helper there is (the system's Git Credential Manager included, which may hold an old password for this host and answer before ours is
|
|
58
|
+
* asked), and the helper given is the only one left.
|
|
59
|
+
*/
|
|
60
|
+
export declare function credentialOptions(url: string, helper: string): string[];
|
|
61
|
+
/** The same, kept in the repository's own config, so `git pull/push` there find the token as well. */
|
|
62
|
+
export declare function configureCredentials(dir: string, url: string, helper: string): void;
|
|
63
|
+
export interface RepoState {
|
|
64
|
+
dir: string;
|
|
65
|
+
branch: string;
|
|
66
|
+
upstream?: string;
|
|
67
|
+
ahead: number;
|
|
68
|
+
behind: number;
|
|
69
|
+
staged: number;
|
|
70
|
+
unstaged: number;
|
|
71
|
+
untracked: number;
|
|
72
|
+
clean: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** Where a checkout stands: branch, how far from its upstream, and what is changed. */
|
|
75
|
+
export declare function repoState(dir: string): RepoState;
|
|
76
|
+
export declare const changedCount: (s: RepoState) => number;
|
|
77
|
+
/** A word for a branch name out of a sentence. */
|
|
78
|
+
export declare function slug(text: string, max?: number): string;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
/**
|
|
5
|
+
* How git is run: it never asks a person. `GIT_TERMINAL_PROMPT=0` is not enough: an editor's terminal (VS Code) sets `GIT_ASKPASS` for
|
|
6
|
+
* every git it starts, and git reaches that program even with prompts off, which shows as a login box at the top of the editor, once
|
|
7
|
+
* per repository. An empty `GIT_ASKPASS` takes it away (and with it `SSH_ASKPASS`), so what git cannot get from the credential helper
|
|
8
|
+
* is a failure with a message, not a question.
|
|
9
|
+
*/
|
|
10
|
+
const GIT_ENV = { GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never', GIT_ASKPASS: '', SSH_ASKPASS: '', LC_ALL: 'C' };
|
|
11
|
+
const notFound = (e) => new Error(e.code === 'ENOENT' ? 'git is not installed or not on your PATH (https://git-scm.com).' : e.message);
|
|
12
|
+
/** git, and wait for it (for what is quick and local: status, add, commit). Anything that goes over the network uses `gitAsync`. */
|
|
13
|
+
export function git(cwd, args, opts = {}) {
|
|
14
|
+
const res = spawnSync('git', args, {
|
|
15
|
+
...(cwd ? { cwd } : {}),
|
|
16
|
+
encoding: 'utf8',
|
|
17
|
+
input: opts.input,
|
|
18
|
+
env: { ...process.env, ...GIT_ENV },
|
|
19
|
+
windowsHide: true
|
|
20
|
+
});
|
|
21
|
+
if (res.error)
|
|
22
|
+
throw notFound(res.error);
|
|
23
|
+
return { status: res.status ?? 1, stdout: res.stdout ?? '', stderr: res.stderr ?? '' };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* git, without holding everything up (a window keeps drawing while a clone or a push runs). `onProgress` gets what git says as it
|
|
27
|
+
* goes ("Receiving objects: 45%"), one line at a time: ask for it with `--progress`.
|
|
28
|
+
*/
|
|
29
|
+
export function gitAsync(cwd, args, opts = {}) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const child = spawn('git', args, { ...(cwd ? { cwd } : {}), env: { ...process.env, ...GIT_ENV, ...opts.env }, windowsHide: true });
|
|
32
|
+
let stdout = '';
|
|
33
|
+
let stderr = '';
|
|
34
|
+
let partial = '';
|
|
35
|
+
child.stdout.on('data', (d) => {
|
|
36
|
+
stdout += d.toString('utf8');
|
|
37
|
+
});
|
|
38
|
+
child.stderr.on('data', (d) => {
|
|
39
|
+
const chunk = d.toString('utf8');
|
|
40
|
+
stderr += chunk;
|
|
41
|
+
if (!opts.onProgress)
|
|
42
|
+
return;
|
|
43
|
+
// progress is redrawn in place with carriage returns: the last whole line is what is happening now
|
|
44
|
+
const lines = (partial + chunk).split(/[\r\n]+/);
|
|
45
|
+
partial = lines.pop() ?? '';
|
|
46
|
+
const last = lines.filter((l) => l.trim()).pop();
|
|
47
|
+
if (last)
|
|
48
|
+
opts.onProgress(last.trim());
|
|
49
|
+
});
|
|
50
|
+
child.on('error', (e) => reject(notFound(e)));
|
|
51
|
+
child.on('close', (code) => resolve({ status: code ?? 1, stdout, stderr }));
|
|
52
|
+
child.stdin.on('error', () => { });
|
|
53
|
+
child.stdin.end(opts.input);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** What git says when the host did not accept who it is talking to (or nobody told it). */
|
|
57
|
+
const AUTH_FAILURE = /could not read (Username|Password)|Authentication failed|Access denied|terminal prompts disabled|HTTP 40[13]|returned error: 40[13]/i;
|
|
58
|
+
/** Whether what git said is an authentication failure. */
|
|
59
|
+
export const isAuthFailure = (said) => AUTH_FAILURE.test(said);
|
|
60
|
+
/** What git said, without the credentials of an address in it. */
|
|
61
|
+
export const withoutCredentials = (said) => said.replace(/https?:\/\/[^@\s/]+@/g, 'https://');
|
|
62
|
+
/** A failed git command: what git said, and whether that was the host refusing access (`denied`). */
|
|
63
|
+
export class GitCommandError extends Error {
|
|
64
|
+
command;
|
|
65
|
+
said;
|
|
66
|
+
constructor(command, said) {
|
|
67
|
+
super(`git ${command} failed: ${said}`);
|
|
68
|
+
this.command = command;
|
|
69
|
+
this.said = said;
|
|
70
|
+
this.name = 'GitCommandError';
|
|
71
|
+
}
|
|
72
|
+
get denied() {
|
|
73
|
+
return isAuthFailure(this.said);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The git command that was run, not the options before it: `clone` for `-c credential…=… clone …`. */
|
|
77
|
+
const subcommand = (args) => {
|
|
78
|
+
let i = 0;
|
|
79
|
+
while (args[i] === '-c')
|
|
80
|
+
i += 2;
|
|
81
|
+
return args[i] ?? 'command';
|
|
82
|
+
};
|
|
83
|
+
const failure = (args, res) => {
|
|
84
|
+
// what git says first ("Cloning into …") is not what went wrong
|
|
85
|
+
const said = withoutCredentials((res.stderr || res.stdout).trim())
|
|
86
|
+
.split(/\r?\n/)
|
|
87
|
+
.filter((line) => !/^Cloning into /.test(line))
|
|
88
|
+
.join('\n');
|
|
89
|
+
return new GitCommandError(subcommand(args), said || `exit ${res.status}`);
|
|
90
|
+
};
|
|
91
|
+
/** `git`, and the output; a failure throws a `GitCommandError`. */
|
|
92
|
+
export function gitOk(cwd, args) {
|
|
93
|
+
const res = git(cwd, args);
|
|
94
|
+
if (res.status !== 0)
|
|
95
|
+
throw failure(args, res);
|
|
96
|
+
return res.stdout;
|
|
97
|
+
}
|
|
98
|
+
/** `gitAsync`, and the output; a failure throws a `GitCommandError`. */
|
|
99
|
+
export async function gitOkAsync(cwd, args, opts = {}) {
|
|
100
|
+
const res = await gitAsync(cwd, args, opts);
|
|
101
|
+
if (res.status !== 0)
|
|
102
|
+
throw failure(args, res);
|
|
103
|
+
return res.stdout;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Whether git can read a repository with this username and token, as it will when it uses them: the answer to "is this token good for
|
|
107
|
+
* git?", which is not the same as "is it good for the host's API?" (a GitLab token needs `read_repository`, or `api`, for git). The
|
|
108
|
+
* token goes to git in its environment, not on a command line others can read, and nothing is kept.
|
|
109
|
+
*/
|
|
110
|
+
export async function checkGitAccess(url, username, token) {
|
|
111
|
+
const basic = Buffer.from(`${username}:${token}`).toString('base64');
|
|
112
|
+
const res = await gitAsync(undefined, ['-c', 'credential.helper=', 'ls-remote', '--heads', url], {
|
|
113
|
+
env: { GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'http.extraHeader', GIT_CONFIG_VALUE_0: `Authorization: Basic ${basic}` }
|
|
114
|
+
});
|
|
115
|
+
return res.status === 0 ? { ok: true } : { ok: false, said: withoutCredentials((res.stderr || res.stdout).trim()) };
|
|
116
|
+
}
|
|
117
|
+
export function isRepo(dir) {
|
|
118
|
+
try {
|
|
119
|
+
return fs.existsSync(path.join(dir, '.git'));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** The address `git` clones from for a repository the host shows at `webUrl`: the same, plus `.git` (GitLab and GitHub both). */
|
|
126
|
+
export const cloneUrlOf = (webUrl) => `${webUrl.replace(/\/+$/, '').replace(/\.git$/, '')}.git`;
|
|
127
|
+
// ---------------------------------------------------------------- credentials for git
|
|
128
|
+
const originOf = (url) => {
|
|
129
|
+
try {
|
|
130
|
+
const u = new URL(url);
|
|
131
|
+
return /^https?:$/.test(u.protocol) ? u.origin : undefined;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* `-c` options that make git use a credential helper (`helper`: what git runs, as `credential.helper` says: `!program args`) for a
|
|
139
|
+
* command that has no repository yet (clone). For the whole command, not for the host in it: an empty `credential.helper` forgets every
|
|
140
|
+
* helper there is (the system's Git Credential Manager included, which may hold an old password for this host and answer before ours is
|
|
141
|
+
* asked), and the helper given is the only one left.
|
|
142
|
+
*/
|
|
143
|
+
export function credentialOptions(url, helper) {
|
|
144
|
+
return originOf(url) ? ['-c', 'credential.helper=', '-c', `credential.helper=${helper}`] : [];
|
|
145
|
+
}
|
|
146
|
+
/** The same, kept in the repository's own config, so `git pull/push` there find the token as well. */
|
|
147
|
+
export function configureCredentials(dir, url, helper) {
|
|
148
|
+
const origin = originOf(url);
|
|
149
|
+
if (!origin)
|
|
150
|
+
return;
|
|
151
|
+
const key = `credential.${origin}.helper`;
|
|
152
|
+
git(dir, ['config', '--local', '--unset-all', key]);
|
|
153
|
+
gitOk(dir, ['config', '--local', '--add', key, '']); // an empty one forgets the helpers of the system
|
|
154
|
+
gitOk(dir, ['config', '--local', '--add', key, helper]);
|
|
155
|
+
}
|
|
156
|
+
/** Where a checkout stands: branch, how far from its upstream, and what is changed. */
|
|
157
|
+
export function repoState(dir) {
|
|
158
|
+
const out = gitOk(dir, ['status', '--porcelain=v2', '--branch', '--untracked-files=all']);
|
|
159
|
+
const state = { dir, branch: '(detached)', ahead: 0, behind: 0, staged: 0, unstaged: 0, untracked: 0, clean: true };
|
|
160
|
+
for (const line of out.split(/\r?\n/)) {
|
|
161
|
+
if (line.startsWith('# branch.head '))
|
|
162
|
+
state.branch = line.slice('# branch.head '.length);
|
|
163
|
+
else if (line.startsWith('# branch.upstream '))
|
|
164
|
+
state.upstream = line.slice('# branch.upstream '.length);
|
|
165
|
+
else if (line.startsWith('# branch.ab ')) {
|
|
166
|
+
const m = /\+(\d+) -(\d+)/.exec(line);
|
|
167
|
+
if (m) {
|
|
168
|
+
state.ahead = Number(m[1]);
|
|
169
|
+
state.behind = Number(m[2]);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (line.startsWith('1 ') || line.startsWith('2 ') || line.startsWith('u ')) {
|
|
173
|
+
const xy = line.split(' ')[1] ?? '..';
|
|
174
|
+
if (xy[0] !== '.')
|
|
175
|
+
state.staged++;
|
|
176
|
+
if (xy[1] !== '.')
|
|
177
|
+
state.unstaged++;
|
|
178
|
+
}
|
|
179
|
+
else if (line.startsWith('? '))
|
|
180
|
+
state.untracked++;
|
|
181
|
+
}
|
|
182
|
+
state.clean = !(state.staged + state.unstaged + state.untracked);
|
|
183
|
+
return state;
|
|
184
|
+
}
|
|
185
|
+
export const changedCount = (s) => s.staged + s.unstaged + s.untracked;
|
|
186
|
+
/** A word for a branch name out of a sentence. */
|
|
187
|
+
export function slug(text, max = 40) {
|
|
188
|
+
const s = text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
189
|
+
return s.slice(0, max).replace(/-+$/, '') || 'changes';
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/checkout/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAa5B;;;;;GAKG;AACH,MAAM,OAAO,GAAG,EAAE,mBAAmB,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAA;AAErH,MAAM,QAAQ,GAAG,CAAC,CAAQ,EAAS,EAAE,CACnC,IAAI,KAAK,CAAE,CAA2B,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;AAE3I,oIAAoI;AACpI,MAAM,UAAU,GAAG,CAAE,GAAuB,EAAE,IAAc,EAAE,OAA2B,EAAE;IACzF,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE;QACjC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,EAAE,EAAE,GAA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AC,UAAU,EAAE,EAAE,CAAC,CAAA;IAChF,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,SAAS,CAAA;AACxD,CAAC","sourcesContent":["import { spawn, spawnSync } from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\n/**\n * The git of your machine, run as `git` does. Arguments only (never a shell line), and no prompts: a command that cannot go on says\n * why instead of waiting for a person.\n */\n\nexport interface GitResult {\n status: number\n stdout: string\n stderr: string\n}\n\n/**\n * How git is run: it never asks a person. `GIT_TERMINAL_PROMPT=0` is not enough: an editor's terminal (VS Code) sets `GIT_ASKPASS` for\n * every git it starts, and git reaches that program even with prompts off, which shows as a login box at the top of the editor, once\n * per repository. An empty `GIT_ASKPASS` takes it away (and with it `SSH_ASKPASS`), so what git cannot get from the credential helper\n * is a failure with a message, not a question.\n */\nconst GIT_ENV = { GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never', GIT_ASKPASS: '', SSH_ASKPASS: '', LC_ALL: 'C' }\n\nconst notFound = (e: Error): Error =>\n new Error((e as NodeJS.ErrnoException).code === 'ENOENT' ? 'git is not installed or not on your PATH (https://git-scm.com).' : e.message)\n\n/** git, and wait for it (for what is quick and local: status, add, commit). Anything that goes over the network uses `gitAsync`. */\nexport function git (cwd: string | undefined, args: string[], opts: { input?: string } = {}): GitResult {\n const res = spawnSync('git', args, {\n ...(cwd ? { cwd } : {}),\n encoding: 'utf8',\n input: opts.input,\n env: { ...process.env, ...GIT_ENV },\n windowsHide: true\n })\n if (res.error) throw notFound(res.error)\n return { status: res.status ?? 1, stdout: res.stdout ?? '', stderr: res.stderr ?? '' }\n}\n\n/**\n * git, without holding everything up (a window keeps drawing while a clone or a push runs). `onProgress` gets what git says as it\n * goes (\"Receiving objects: 45%\"), one line at a time: ask for it with `--progress`.\n */\nexport function gitAsync (cwd: string | undefined, args: string[], opts: { onProgress?: (line: string) => void, env?: Record<string, string>, input?: string } = {}): Promise<GitResult> {\n return new Promise((resolve, reject) => {\n const child = spawn('git', args, { ...(cwd ? { cwd } : {}), env: { ...process.env, ...GIT_ENV, ...opts.env }, windowsHide: true })\n let stdout = ''\n let stderr = ''\n let partial = ''\n child.stdout.on('data', (d: Buffer) => {\n stdout += d.toString('utf8')\n })\n child.stderr.on('data', (d: Buffer) => {\n const chunk = d.toString('utf8')\n stderr += chunk\n if (!opts.onProgress) return\n // progress is redrawn in place with carriage returns: the last whole line is what is happening now\n const lines = (partial + chunk).split(/[\\r\\n]+/)\n partial = lines.pop() ?? ''\n const last = lines.filter((l) => l.trim()).pop()\n if (last) opts.onProgress(last.trim())\n })\n child.on('error', (e) => reject(notFound(e)))\n child.on('close', (code) => resolve({ status: code ?? 1, stdout, stderr }))\n child.stdin.on('error', () => { /* git did not read what it was sent */ })\n child.stdin.end(opts.input)\n })\n}\n\n/** What git says when the host did not accept who it is talking to (or nobody told it). */\nconst AUTH_FAILURE = /could not read (Username|Password)|Authentication failed|Access denied|terminal prompts disabled|HTTP 40[13]|returned error: 40[13]/i\n\n/** Whether what git said is an authentication failure. */\nexport const isAuthFailure = (said: string): boolean => AUTH_FAILURE.test(said)\n\n/** What git said, without the credentials of an address in it. */\nexport const withoutCredentials = (said: string): string => said.replace(/https?:\\/\\/[^@\\s/]+@/g, 'https://')\n\n/** A failed git command: what git said, and whether that was the host refusing access (`denied`). */\nexport class GitCommandError extends Error {\n constructor (readonly command: string, readonly said: string) {\n super(`git ${command} failed: ${said}`)\n this.name = 'GitCommandError'\n }\n\n get denied (): boolean {\n return isAuthFailure(this.said)\n }\n}\n\n/** The git command that was run, not the options before it: `clone` for `-c credential…=… clone …`. */\nconst subcommand = (args: string[]): string => {\n let i = 0\n while (args[i] === '-c') i += 2\n return args[i] ?? 'command'\n}\n\nconst failure = (args: string[], res: GitResult): GitCommandError => {\n // what git says first (\"Cloning into …\") is not what went wrong\n const said = withoutCredentials((res.stderr || res.stdout).trim())\n .split(/\\r?\\n/)\n .filter((line) => !/^Cloning into /.test(line))\n .join('\\n')\n return new GitCommandError(subcommand(args), said || `exit ${res.status}`)\n}\n\n/** `git`, and the output; a failure throws a `GitCommandError`. */\nexport function gitOk (cwd: string | undefined, args: string[]): string {\n const res = git(cwd, args)\n if (res.status !== 0) throw failure(args, res)\n return res.stdout\n}\n\n/** `gitAsync`, and the output; a failure throws a `GitCommandError`. */\nexport async function gitOkAsync (cwd: string | undefined, args: string[], opts: { onProgress?: (line: string) => void } = {}): Promise<string> {\n const res = await gitAsync(cwd, args, opts)\n if (res.status !== 0) throw failure(args, res)\n return res.stdout\n}\n\n/**\n * Whether git can read a repository with this username and token, as it will when it uses them: the answer to \"is this token good for\n * git?\", which is not the same as \"is it good for the host's API?\" (a GitLab token needs `read_repository`, or `api`, for git). The\n * token goes to git in its environment, not on a command line others can read, and nothing is kept.\n */\nexport async function checkGitAccess (url: string, username: string, token: string): Promise<{ ok: true } | { ok: false, said: string }> {\n const basic = Buffer.from(`${username}:${token}`).toString('base64')\n const res = await gitAsync(undefined, ['-c', 'credential.helper=', 'ls-remote', '--heads', url], {\n env: { GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'http.extraHeader', GIT_CONFIG_VALUE_0: `Authorization: Basic ${basic}` }\n })\n return res.status === 0 ? { ok: true } : { ok: false, said: withoutCredentials((res.stderr || res.stdout).trim()) }\n}\n\nexport function isRepo (dir: string): boolean {\n try {\n return fs.existsSync(path.join(dir, '.git'))\n } catch {\n return false\n }\n}\n\n/** The address `git` clones from for a repository the host shows at `webUrl`: the same, plus `.git` (GitLab and GitHub both). */\nexport const cloneUrlOf = (webUrl: string): string => `${webUrl.replace(/\\/+$/, '').replace(/\\.git$/, '')}.git`\n\n// ---------------------------------------------------------------- credentials for git\n\nconst originOf = (url: string): string | undefined => {\n try {\n const u = new URL(url)\n return /^https?:$/.test(u.protocol) ? u.origin : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * `-c` options that make git use a credential helper (`helper`: what git runs, as `credential.helper` says: `!program args`) for a\n * command that has no repository yet (clone). For the whole command, not for the host in it: an empty `credential.helper` forgets every\n * helper there is (the system's Git Credential Manager included, which may hold an old password for this host and answer before ours is\n * asked), and the helper given is the only one left.\n */\nexport function credentialOptions (url: string, helper: string): string[] {\n return originOf(url) ? ['-c', 'credential.helper=', '-c', `credential.helper=${helper}`] : []\n}\n\n/** The same, kept in the repository's own config, so `git pull/push` there find the token as well. */\nexport function configureCredentials (dir: string, url: string, helper: string): void {\n const origin = originOf(url)\n if (!origin) return\n const key = `credential.${origin}.helper`\n git(dir, ['config', '--local', '--unset-all', key])\n gitOk(dir, ['config', '--local', '--add', key, '']) // an empty one forgets the helpers of the system\n gitOk(dir, ['config', '--local', '--add', key, helper])\n}\n\n// ---------------------------------------------------------------- state\n\nexport interface RepoState {\n dir: string\n branch: string\n upstream?: string\n ahead: number\n behind: number\n staged: number\n unstaged: number\n untracked: number\n clean: boolean\n}\n\n/** Where a checkout stands: branch, how far from its upstream, and what is changed. */\nexport function repoState (dir: string): RepoState {\n const out = gitOk(dir, ['status', '--porcelain=v2', '--branch', '--untracked-files=all'])\n const state: RepoState = { dir, branch: '(detached)', ahead: 0, behind: 0, staged: 0, unstaged: 0, untracked: 0, clean: true }\n for (const line of out.split(/\\r?\\n/)) {\n if (line.startsWith('# branch.head ')) state.branch = line.slice('# branch.head '.length)\n else if (line.startsWith('# branch.upstream ')) state.upstream = line.slice('# branch.upstream '.length)\n else if (line.startsWith('# branch.ab ')) {\n const m = /\\+(\\d+) -(\\d+)/.exec(line)\n if (m) {\n state.ahead = Number(m[1])\n state.behind = Number(m[2])\n }\n } else if (line.startsWith('1 ') || line.startsWith('2 ') || line.startsWith('u ')) {\n const xy = line.split(' ')[1] ?? '..'\n if (xy[0] !== '.') state.staged++\n if (xy[1] !== '.') state.unstaged++\n } else if (line.startsWith('? ')) state.untracked++\n }\n state.clean = !(state.staged + state.unstaged + state.untracked)\n return state\n}\n\nexport const changedCount = (s: RepoState): number => s.staged + s.unstaged + s.untracked\n\n/** A word for a branch name out of a sentence. */\nexport function slug (text: string, max = 40): string {\n const s = text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '')\n return s.slice(0, max).replace(/-+$/, '') || 'changes'\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/checkout/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA","sourcesContent":["export * from './git.js'\nexport * from './sync.js'\nexport * from './credential.js'\n"]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { type Origin } from '@lbdudc/linea-core/workspace';
|
|
2
|
+
import type { GitProvider } from '../provider.js';
|
|
3
|
+
import { type PackageKind } from '../registry/kinds.js';
|
|
4
|
+
import { type RepoState } from './git.js';
|
|
5
|
+
/**
|
|
6
|
+
* Checkouts: an SPL cloned from the host, and the products cloned inside it, as the repositories they are. What `get`, `status` and
|
|
7
|
+
* `push` of a program are made of; the program says it in words. Every call takes `helper`, what git runs as its credential helper
|
|
8
|
+
* (see `credentialOptions`), because what that is depends on the program.
|
|
9
|
+
*/
|
|
10
|
+
type Progress = (line: string) => void;
|
|
11
|
+
export interface Checkout {
|
|
12
|
+
name: string;
|
|
13
|
+
kind: 'spl' | 'product';
|
|
14
|
+
dir: string;
|
|
15
|
+
/** for a product: the SPL it sits in */
|
|
16
|
+
lineDir?: string;
|
|
17
|
+
}
|
|
18
|
+
/** The git checkouts of an SPL: itself, and the products cloned into it. */
|
|
19
|
+
export declare function checkoutsOfLine(lineDir: string): Checkout[];
|
|
20
|
+
/** The SPLs of a workspace that are git checkouts. */
|
|
21
|
+
export declare function splCheckouts(root: string): Checkout[];
|
|
22
|
+
/**
|
|
23
|
+
* What a command acts on, from where you stand: the product you are in; else the SPL and its products; else the SPLs of the
|
|
24
|
+
* workspace (`fallbackRoot` when the folder is in none).
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkoutsAt(cwd: string, fallbackRoot: string): Checkout[];
|
|
27
|
+
/** Clones a repository and leaves it ready for `git pull/push` with the helper; says which branch it started on (the default one). */
|
|
28
|
+
export declare function cloneRepository({ url, dest, helper, onProgress }: {
|
|
29
|
+
url: string;
|
|
30
|
+
dest: string;
|
|
31
|
+
helper: string;
|
|
32
|
+
onProgress?: Progress;
|
|
33
|
+
}): Promise<string>;
|
|
34
|
+
/** What a clone remembers about where it came from, besides the repository itself. */
|
|
35
|
+
export type OriginBase = Pick<Origin, 'server' | 'provider' | 'lineId' | 'webUi'>;
|
|
36
|
+
/** Clones a repository of the host as the SPL it is, and writes where it came from. */
|
|
37
|
+
export declare function cloneLine({ dir, base, line, helper, onProgress }: {
|
|
38
|
+
dir: string;
|
|
39
|
+
base: OriginBase;
|
|
40
|
+
line: {
|
|
41
|
+
name: string;
|
|
42
|
+
webUrl: string;
|
|
43
|
+
repoId: number | string;
|
|
44
|
+
};
|
|
45
|
+
helper: string;
|
|
46
|
+
onProgress?: Progress;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
/** Clones a product of an SPL into the SPL's folder, as a repository of its own that the SPL's git leaves alone. */
|
|
49
|
+
export declare function cloneProduct({ lineDir, base, product, helper, onProgress }: {
|
|
50
|
+
lineDir: string;
|
|
51
|
+
base: OriginBase;
|
|
52
|
+
product: {
|
|
53
|
+
_id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
repo: {
|
|
56
|
+
id: number | string;
|
|
57
|
+
webUrl: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
helper: string;
|
|
61
|
+
onProgress?: Progress;
|
|
62
|
+
}): Promise<string>;
|
|
63
|
+
export interface PullResult {
|
|
64
|
+
/** `updated`: new commits came; `current`: nothing new; `failed`: see `said` */
|
|
65
|
+
outcome: 'updated' | 'current' | 'failed';
|
|
66
|
+
/** how many commits came */
|
|
67
|
+
commits: number;
|
|
68
|
+
/** it has changes of its own and the host moved: they have to be committed before they can be joined */
|
|
69
|
+
changesAndBehind: boolean;
|
|
70
|
+
/** what git said when it failed, without credentials */
|
|
71
|
+
said?: string;
|
|
72
|
+
/** the failure was the host refusing access */
|
|
73
|
+
denied?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** `git pull --ff-only` in a checkout. A failure is a result, not an error: the next checkout is still worth updating. */
|
|
76
|
+
export declare function pullCheckout({ dir, helper, onProgress }: {
|
|
77
|
+
dir: string;
|
|
78
|
+
helper: string;
|
|
79
|
+
onProgress?: Progress;
|
|
80
|
+
}): Promise<PullResult>;
|
|
81
|
+
/** Asks the host what is new, without changing anything here (`git fetch`). */
|
|
82
|
+
export declare function fetchCheckout({ dir, helper }: {
|
|
83
|
+
dir: string;
|
|
84
|
+
helper: string;
|
|
85
|
+
}): Promise<void>;
|
|
86
|
+
export interface PushResult {
|
|
87
|
+
/** the branch that was sent */
|
|
88
|
+
branch: string;
|
|
89
|
+
/** it went to the default branch itself: there is nothing to merge */
|
|
90
|
+
toDefault: boolean;
|
|
91
|
+
/** the merge/pull request opened for it, or why it could not be */
|
|
92
|
+
changeRequest?: {
|
|
93
|
+
url: string;
|
|
94
|
+
} | {
|
|
95
|
+
error: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** The branch name of changes sent for review: who, what, and when. */
|
|
99
|
+
export declare const reviewBranch: (user: string, message: string, now?: Date) => string;
|
|
100
|
+
/**
|
|
101
|
+
* Commits what changed in a checkout and sends it: to a branch of its own with a merge/pull request (the default), or to the branch
|
|
102
|
+
* it is on (`direct`). Without `changeRequest` (a copy made without the host's help) the branch is sent and nothing is opened.
|
|
103
|
+
* Throws a `GitCommandError` when git could not do something; a request that could not be opened is in the result.
|
|
104
|
+
*/
|
|
105
|
+
export declare function pushCheckout({ dir, message, direct, user, helper, onProgress, changeRequest }: {
|
|
106
|
+
dir: string;
|
|
107
|
+
message: string;
|
|
108
|
+
direct?: boolean;
|
|
109
|
+
user: string;
|
|
110
|
+
helper: string;
|
|
111
|
+
onProgress?: Progress;
|
|
112
|
+
/** the host's API, to open the request with */
|
|
113
|
+
changeRequest?: {
|
|
114
|
+
provider: GitProvider;
|
|
115
|
+
token: string;
|
|
116
|
+
};
|
|
117
|
+
}): Promise<PushResult>;
|
|
118
|
+
/** Whether a checkout has something to send: changes, or commits the host does not have. */
|
|
119
|
+
export declare const hasUnsent: (state: RepoState) => boolean;
|
|
120
|
+
/**
|
|
121
|
+
* A folder made here becomes the checkout of a repository the host just made for it (with the scaffold of an SPL): what is here goes
|
|
122
|
+
* on top of the scaffold, is committed and sent to the default branch, and the folder takes the repository over. Returns how many files
|
|
123
|
+
* were sent and the default branch.
|
|
124
|
+
*/
|
|
125
|
+
export declare function adoptFolder({ dir, url, name, helper, onProgress }: {
|
|
126
|
+
dir: string;
|
|
127
|
+
url: string;
|
|
128
|
+
name: string;
|
|
129
|
+
helper: string;
|
|
130
|
+
onProgress?: (what: 'getting' | 'uploading', line: string) => void;
|
|
131
|
+
}): Promise<{
|
|
132
|
+
copied: number;
|
|
133
|
+
defaultBranch: string;
|
|
134
|
+
}>;
|
|
135
|
+
/**
|
|
136
|
+
* Gets a module or metamodel of the git host into a workspace to change it: a clone that remembers where it came from, and where
|
|
137
|
+
* `publish` puts it back (the group on GitLab, the owner on GitHub). `repoPath` is `group/project` as the host knows it. Throws when
|
|
138
|
+
* the host does not know it, or it is not a package of that kind.
|
|
139
|
+
*/
|
|
140
|
+
export declare function clonePackage({ provider, token, kind, repoPath, workdir, dest, helper, onProgress }: {
|
|
141
|
+
provider: GitProvider;
|
|
142
|
+
token: string;
|
|
143
|
+
kind: PackageKind;
|
|
144
|
+
repoPath: string;
|
|
145
|
+
/** the workspace: the package goes to `<workdir>/modules/<name>` or `<workdir>/metamodels/<name>` unless `dest` says */
|
|
146
|
+
workdir: string;
|
|
147
|
+
dest?: string;
|
|
148
|
+
helper: string;
|
|
149
|
+
onProgress?: Progress;
|
|
150
|
+
}): Promise<{
|
|
151
|
+
status: 'cloned' | 'present';
|
|
152
|
+
name: string;
|
|
153
|
+
dir: string;
|
|
154
|
+
publishRoot?: string;
|
|
155
|
+
}>;
|
|
156
|
+
export {};
|