@huozi-ai/git-kit 0.1.0-alpha.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/LICENSE +202 -0
- package/NOTICE +6 -0
- package/dist/commands.d.ts +17 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +62 -0
- package/dist/commands.js.map +1 -0
- package/dist/configure.d.ts +43 -0
- package/dist/configure.d.ts.map +1 -0
- package/dist/configure.js +146 -0
- package/dist/configure.js.map +1 -0
- package/dist/credential.d.ts +40 -0
- package/dist/credential.d.ts.map +1 -0
- package/dist/credential.js +61 -0
- package/dist/credential.js.map +1 -0
- package/dist/git.d.ts +50 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +71 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/lfs/client.d.ts +47 -0
- package/dist/lfs/client.d.ts.map +1 -0
- package/dist/lfs/client.js +216 -0
- package/dist/lfs/client.js.map +1 -0
- package/dist/lfs/filter.d.ts +39 -0
- package/dist/lfs/filter.d.ts.map +1 -0
- package/dist/lfs/filter.js +148 -0
- package/dist/lfs/filter.js.map +1 -0
- package/dist/lfs/pktline.d.ts +33 -0
- package/dist/lfs/pktline.d.ts.map +1 -0
- package/dist/lfs/pktline.js +127 -0
- package/dist/lfs/pktline.js.map +1 -0
- package/dist/lfs/pointer.d.ts +20 -0
- package/dist/lfs/pointer.d.ts.map +1 -0
- package/dist/lfs/pointer.js +56 -0
- package/dist/lfs/pointer.js.map +1 -0
- package/dist/lfs/push.d.ts +20 -0
- package/dist/lfs/push.d.ts.map +1 -0
- package/dist/lfs/push.js +94 -0
- package/dist/lfs/push.js.map +1 -0
- package/dist/lfs/store.d.ts +28 -0
- package/dist/lfs/store.d.ts.map +1 -0
- package/dist/lfs/store.js +98 -0
- package/dist/lfs/store.js.map +1 -0
- package/dist/ops.d.ts +39 -0
- package/dist/ops.d.ts.map +1 -0
- package/dist/ops.js +130 -0
- package/dist/ops.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
2
|
+
import { type CredentialProvider } from "./credential.js";
|
|
3
|
+
export interface CommandIO {
|
|
4
|
+
cwd: string;
|
|
5
|
+
stdin: AsyncIterable<Buffer | Uint8Array>;
|
|
6
|
+
stdout: Writable;
|
|
7
|
+
stderr: Writable;
|
|
8
|
+
}
|
|
9
|
+
export declare function processIO(): CommandIO;
|
|
10
|
+
/**
|
|
11
|
+
* `<binary> lfs <command>` as git calls it (see `configureRepo`): `filter-process`,
|
|
12
|
+
* `clean -- <path>`, `smudge -- <path>` and `pre-push <remote> <url>`. Returns the exit code.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runLfsCommand(args: string[], io?: CommandIO): Promise<number>;
|
|
15
|
+
/** `<binary> git-credential <get|store|erase>`: answers git on stdout. Returns the exit code. */
|
|
16
|
+
export declare function runCredentialCommand(action: string, provider: CredentialProvider, io?: CommandIO): Promise<number>;
|
|
17
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAI5E,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC;IAC1C,MAAM,EAAE,QAAQ,CAAC;IACjB,MAAM,EAAE,QAAQ,CAAC;CAClB;AAED,wBAAgB,SAAS,IAAI,SAAS,CAOrC;AAUD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,GAAE,SAAuB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAsCjB;AAED,iGAAiG;AACjG,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,kBAAkB,EAC5B,EAAE,GAAE,SAAuB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAYjB"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { credentialHelper } from "./credential.js";
|
|
2
|
+
import { cleanFile, filterProcess, smudgeFile } from "./lfs/filter.js";
|
|
3
|
+
import { prePush } from "./lfs/push.js";
|
|
4
|
+
export function processIO() {
|
|
5
|
+
return {
|
|
6
|
+
cwd: process.cwd(),
|
|
7
|
+
stdin: process.stdin,
|
|
8
|
+
stdout: process.stdout,
|
|
9
|
+
stderr: process.stderr,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
async function readAll(input) {
|
|
13
|
+
const parts = [];
|
|
14
|
+
for await (const chunk of input)
|
|
15
|
+
parts.push(Buffer.from(chunk));
|
|
16
|
+
return Buffer.concat(parts).toString("utf8");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `<binary> lfs <command>` as git calls it (see `configureRepo`): `filter-process`,
|
|
20
|
+
* `clean -- <path>`, `smudge -- <path>` and `pre-push <remote> <url>`. Returns the exit code.
|
|
21
|
+
*/
|
|
22
|
+
export async function runLfsCommand(args, io = processIO()) {
|
|
23
|
+
const [command, ...rest] = args;
|
|
24
|
+
try {
|
|
25
|
+
switch (command) {
|
|
26
|
+
case "filter-process":
|
|
27
|
+
await filterProcess(io.cwd, io.stdin, io.stdout, (m) => io.stderr.write(`${m}\n`));
|
|
28
|
+
return 0;
|
|
29
|
+
case "clean":
|
|
30
|
+
await cleanFile(io.cwd, io.stdin, io.stdout);
|
|
31
|
+
return 0;
|
|
32
|
+
case "smudge":
|
|
33
|
+
await smudgeFile(io.cwd, io.stdin, io.stdout);
|
|
34
|
+
return 0;
|
|
35
|
+
case "pre-push": {
|
|
36
|
+
const sent = await prePush(io.cwd, rest[0] ?? "origin", rest[1] ?? "", await readAll(io.stdin));
|
|
37
|
+
if (sent > 0)
|
|
38
|
+
io.stderr.write(`Uploaded ${String(sent)} media file${sent === 1 ? "" : "s"}.\n`);
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
default:
|
|
42
|
+
io.stderr.write(`Unknown lfs command: ${String(command)}\n`);
|
|
43
|
+
return 2;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
io.stderr.write(`huozi lfs ${String(command)}: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** `<binary> git-credential <get|store|erase>`: answers git on stdout. Returns the exit code. */
|
|
52
|
+
export async function runCredentialCommand(action, provider, io = processIO()) {
|
|
53
|
+
try {
|
|
54
|
+
io.stdout.write(await credentialHelper(action, await readAll(io.stdin), provider));
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
io.stderr.write(`huozi git-credential: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","source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,EAAE,CAAC,MAAM,CAAC,KAAK,CACb,MAAM,gBAAgB,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAClE,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,EAAE,CAAC,MAAM,CAAC,KAAK,CACb,yBAAyB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CACpF,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How git reaches our code. The CLI passes its own executable; git then runs, through the shell:
|
|
3
|
+
*
|
|
4
|
+
* - `<binary> lfs filter-process` (and `lfs clean -- %f`, `lfs smudge -- %f` as fallbacks);
|
|
5
|
+
* - `<binary> lfs pre-push <remote> <url>` from the pre-push hook;
|
|
6
|
+
* - `<binary> git-credential get|store|erase` as the credential helper.
|
|
7
|
+
*
|
|
8
|
+
* The CLI routes these to `runLfsCommand` and `credentialHelper`.
|
|
9
|
+
*/
|
|
10
|
+
export interface GitKitCommand {
|
|
11
|
+
/** Executable, for example `huozi` or an absolute path to node. */
|
|
12
|
+
binary: string;
|
|
13
|
+
/** Arguments before the subcommand, for example a script path. */
|
|
14
|
+
args?: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare function commandLine(command: GitKitCommand, ...rest: string[]): string;
|
|
17
|
+
/** File types that go to LFS: audio, video, images, fonts. SVG stays text. */
|
|
18
|
+
export declare const MEDIA_EXTENSIONS: readonly ["mp3", "wav", "m4a", "aac", "ogg", "oga", "opus", "flac", "aif", "aiff", "mp4", "m4v", "mov", "webm", "mkv", "avi", "png", "jpg", "jpeg", "gif", "webp", "avif", "heic", "tif", "tiff", "bmp", "psd", "ttf", "otf", "woff", "woff2"];
|
|
19
|
+
/** `.gitattributes` lines for media, lower and upper case (cameras write `.JPG`, `.MOV`). */
|
|
20
|
+
export declare function mediaAttributes(): string[];
|
|
21
|
+
/** Adds the media lines that are missing to `.gitattributes`. Returns true when the file changed. */
|
|
22
|
+
export declare function ensureGitattributes(dir: string): Promise<boolean>;
|
|
23
|
+
export interface ConfigureOptions extends GitKitCommand {
|
|
24
|
+
/** LFS endpoint. Default: derived from the `origin` remote, when there is one. */
|
|
25
|
+
lfsUrl?: string;
|
|
26
|
+
/** Configure the credential helper for the remote's host. Default true. */
|
|
27
|
+
credentials?: boolean;
|
|
28
|
+
/** Write the media patterns into `.gitattributes`. Default true. */
|
|
29
|
+
attributes?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ConfigureResult {
|
|
32
|
+
/** False when `core.hooksPath` points elsewhere or another pre-push hook exists. */
|
|
33
|
+
hookInstalled: boolean;
|
|
34
|
+
/** `.gitattributes` changed (the caller saves it with the next commit). */
|
|
35
|
+
attributesChanged: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sets up a repository so git handles media through our LFS client and asks us for credentials:
|
|
39
|
+
* filter config, `lfs.url`, the credential helper for the remote's host, the pre-push hook and
|
|
40
|
+
* `.gitattributes`. Safe to run again (the CLI runs it whenever its own path may have changed).
|
|
41
|
+
*/
|
|
42
|
+
export declare function configureRepo(dir: string, options: ConfigureOptions): Promise<ConfigureResult>;
|
|
43
|
+
//# sourceMappingURL=configure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAK7E;AAED,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,gPAoCnB,CAAC;AAIX,6FAA6F;AAC7F,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAK1C;AAED,qGAAqG;AACrG,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBvE;AAKD,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oEAAoE;IACpE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,oFAAoF;IACpF,aAAa,EAAE,OAAO,CAAC;IACvB,2EAA2E;IAC3E,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAWD;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CAiD1B"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { gitConfig, gitText, runGit, shellQuote } from "./git.js";
|
|
4
|
+
import { endpointFromRemote } from "./lfs/client.js";
|
|
5
|
+
export function commandLine(command, ...rest) {
|
|
6
|
+
return [command.binary, ...(command.args ?? [])]
|
|
7
|
+
.map(shellQuote)
|
|
8
|
+
.concat(rest)
|
|
9
|
+
.join(" ");
|
|
10
|
+
}
|
|
11
|
+
/** File types that go to LFS: audio, video, images, fonts. SVG stays text. */
|
|
12
|
+
export const MEDIA_EXTENSIONS = [
|
|
13
|
+
// audio
|
|
14
|
+
"mp3",
|
|
15
|
+
"wav",
|
|
16
|
+
"m4a",
|
|
17
|
+
"aac",
|
|
18
|
+
"ogg",
|
|
19
|
+
"oga",
|
|
20
|
+
"opus",
|
|
21
|
+
"flac",
|
|
22
|
+
"aif",
|
|
23
|
+
"aiff",
|
|
24
|
+
// video
|
|
25
|
+
"mp4",
|
|
26
|
+
"m4v",
|
|
27
|
+
"mov",
|
|
28
|
+
"webm",
|
|
29
|
+
"mkv",
|
|
30
|
+
"avi",
|
|
31
|
+
// images
|
|
32
|
+
"png",
|
|
33
|
+
"jpg",
|
|
34
|
+
"jpeg",
|
|
35
|
+
"gif",
|
|
36
|
+
"webp",
|
|
37
|
+
"avif",
|
|
38
|
+
"heic",
|
|
39
|
+
"tif",
|
|
40
|
+
"tiff",
|
|
41
|
+
"bmp",
|
|
42
|
+
"psd",
|
|
43
|
+
// fonts
|
|
44
|
+
"ttf",
|
|
45
|
+
"otf",
|
|
46
|
+
"woff",
|
|
47
|
+
"woff2",
|
|
48
|
+
];
|
|
49
|
+
const LFS_ATTRS = "filter=lfs diff=lfs merge=lfs -text";
|
|
50
|
+
/** `.gitattributes` lines for media, lower and upper case (cameras write `.JPG`, `.MOV`). */
|
|
51
|
+
export function mediaAttributes() {
|
|
52
|
+
return MEDIA_EXTENSIONS.flatMap((ext) => [
|
|
53
|
+
`*.${ext} ${LFS_ATTRS}`,
|
|
54
|
+
`*.${ext.toUpperCase()} ${LFS_ATTRS}`,
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
/** Adds the media lines that are missing to `.gitattributes`. Returns true when the file changed. */
|
|
58
|
+
export async function ensureGitattributes(dir) {
|
|
59
|
+
const path = join(dir, ".gitattributes");
|
|
60
|
+
let current = "";
|
|
61
|
+
try {
|
|
62
|
+
current = await readFile(path, "utf8");
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// No file yet.
|
|
66
|
+
}
|
|
67
|
+
const have = new Set(current.split("\n").map((line) => line.trim()));
|
|
68
|
+
const missing = mediaAttributes().filter((line) => !have.has(line));
|
|
69
|
+
if (missing.length === 0)
|
|
70
|
+
return false;
|
|
71
|
+
const prefix = current === ""
|
|
72
|
+
? "# Media goes to Git LFS (managed by Huozi)\n"
|
|
73
|
+
: current.endsWith("\n")
|
|
74
|
+
? ""
|
|
75
|
+
: "\n";
|
|
76
|
+
await writeFile(path, `${current}${prefix}${missing.join("\n")}\n`);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
const HOOK_MARK = "# Installed by Huozi: uploads media (Git LFS) before a push.";
|
|
80
|
+
/** `https://host:1234/a/b.git` → `https://host:1234`. */
|
|
81
|
+
function origin(url) {
|
|
82
|
+
try {
|
|
83
|
+
return new URL(url).origin;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Sets up a repository so git handles media through our LFS client and asks us for credentials:
|
|
91
|
+
* filter config, `lfs.url`, the credential helper for the remote's host, the pre-push hook and
|
|
92
|
+
* `.gitattributes`. Safe to run again (the CLI runs it whenever its own path may have changed).
|
|
93
|
+
*/
|
|
94
|
+
export async function configureRepo(dir, options) {
|
|
95
|
+
const set = (key, value) => runGit(["config", "--local", key, value], { cwd: dir });
|
|
96
|
+
await set("filter.lfs.process", commandLine(options, "lfs", "filter-process"));
|
|
97
|
+
await set("filter.lfs.clean", commandLine(options, "lfs", "clean", "--", "%f"));
|
|
98
|
+
await set("filter.lfs.smudge", commandLine(options, "lfs", "smudge", "--", "%f"));
|
|
99
|
+
await set("filter.lfs.required", "true");
|
|
100
|
+
const remoteUrl = await gitConfig(dir, "remote.origin.url");
|
|
101
|
+
const lfsUrl = options.lfsUrl ?? (remoteUrl ? endpointFromRemote(remoteUrl) : undefined);
|
|
102
|
+
if (lfsUrl)
|
|
103
|
+
await set("lfs.url", lfsUrl);
|
|
104
|
+
const host = origin(lfsUrl ?? remoteUrl ?? "");
|
|
105
|
+
if (host && options.credentials !== false) {
|
|
106
|
+
const key = `credential.${host}.helper`;
|
|
107
|
+
await runGit(["config", "--local", "--unset-all", key], {
|
|
108
|
+
cwd: dir,
|
|
109
|
+
okCodes: [5],
|
|
110
|
+
});
|
|
111
|
+
// An empty helper first resets helpers from global config (a keychain must not keep our
|
|
112
|
+
// short-lived tokens), then ours.
|
|
113
|
+
await runGit(["config", "--local", "--add", key, ""], { cwd: dir });
|
|
114
|
+
await runGit([
|
|
115
|
+
"config",
|
|
116
|
+
"--local",
|
|
117
|
+
"--add",
|
|
118
|
+
key,
|
|
119
|
+
`!${commandLine(options, "git-credential")}`,
|
|
120
|
+
], { cwd: dir });
|
|
121
|
+
await set(`credential.${host}.useHttpPath`, "true");
|
|
122
|
+
}
|
|
123
|
+
const hookInstalled = await installPrePush(dir, options);
|
|
124
|
+
const attributesChanged = options.attributes === false ? false : await ensureGitattributes(dir);
|
|
125
|
+
return { hookInstalled, attributesChanged };
|
|
126
|
+
}
|
|
127
|
+
async function installPrePush(dir, command) {
|
|
128
|
+
if (await gitConfig(dir, "core.hooksPath"))
|
|
129
|
+
return false;
|
|
130
|
+
const hooks = await gitText(["rev-parse", "--git-path", "hooks"], {
|
|
131
|
+
cwd: dir,
|
|
132
|
+
});
|
|
133
|
+
const path = join(isAbsolute(hooks) ? hooks : resolve(dir, hooks), "pre-push");
|
|
134
|
+
try {
|
|
135
|
+
if (!(await readFile(path, "utf8")).includes(HOOK_MARK))
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// No hook yet.
|
|
140
|
+
}
|
|
141
|
+
await mkdir(dirname(path), { recursive: true });
|
|
142
|
+
await writeFile(path, `#!/bin/sh\n${HOOK_MARK}\nexec ${commandLine(command, "lfs", "pre-push")} "$@"\n`);
|
|
143
|
+
await chmod(path, 0o755);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=configure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configure.js","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"m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,EAC/C,UAAU,CACX,CAAC;IACF,IAAI,CAAC;QACH,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,OAAO,KAAK,CAAC;IACxE,CAAC;IAAC,MAAM,CAAC;QACP,eAAe;IACjB,CAAC;IACD,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,SAAS,CACb,IAAI,EACJ,cAAc,SAAS,UAAU,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,SAAS,CAClF,CAAC;IACF,MAAM,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The git credential helper protocol (https://git-scm.com/docs/git-credential): git writes
|
|
3
|
+
* `key=value` lines and a blank line to the helper's stdin; for `get` the helper answers with
|
|
4
|
+
* `username`, `password` and optionally `password_expiry_utc` (git 2.41+ stops reusing it after
|
|
5
|
+
* that time). `store` and `erase` answer nothing.
|
|
6
|
+
*
|
|
7
|
+
* Our helper never stores anything: it asks a token provider (the CLI calls the platform API) for a
|
|
8
|
+
* short-lived token scoped to one repository. The token never lands in `.git/config` or a keychain.
|
|
9
|
+
*/
|
|
10
|
+
export interface CredentialRequest {
|
|
11
|
+
protocol: string;
|
|
12
|
+
host: string;
|
|
13
|
+
/** The URL path git passes when `credential.useHttpPath` is on, for example `ws_1.git/info/lfs`. */
|
|
14
|
+
path?: string;
|
|
15
|
+
/** The repository the path points at: `path` without `.git`, `/info/lfs` and slashes. */
|
|
16
|
+
repo?: string;
|
|
17
|
+
/** Every attribute git sent. */
|
|
18
|
+
attributes: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export interface Credential {
|
|
21
|
+
username: string;
|
|
22
|
+
password: string;
|
|
23
|
+
expiresAt?: Date;
|
|
24
|
+
}
|
|
25
|
+
export interface CredentialProvider {
|
|
26
|
+
/** A credential for this request, or `null` to let git try the next helper. */
|
|
27
|
+
get(request: CredentialRequest): Promise<Credential | null>;
|
|
28
|
+
/** Git got a 401/403 with the last credential: forget any cached token. */
|
|
29
|
+
erase?(request: CredentialRequest): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare function parseCredentialInput(text: string): CredentialRequest;
|
|
32
|
+
/** `ws_1.git/info/lfs` → `ws_1`; `team/ws_1.git` → `team/ws_1`. */
|
|
33
|
+
export declare function repoFromPath(path: string): string | undefined;
|
|
34
|
+
export declare function formatCredential(credential: Credential): string;
|
|
35
|
+
/**
|
|
36
|
+
* Runs one helper action (`get`, `store` or `erase`) on git's input and returns what to print.
|
|
37
|
+
* Unknown actions print nothing, as the protocol asks.
|
|
38
|
+
*/
|
|
39
|
+
export declare function credentialHelper(action: string, input: string, provider: CredentialProvider): Promise<string>;
|
|
40
|
+
//# sourceMappingURL=credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yFAAyF;IACzF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,GAAG,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAC5D,2EAA2E;IAC3E,KAAK,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAoBpE;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO7D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAc/D;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function parseCredentialInput(text) {
|
|
2
|
+
const attributes = {};
|
|
3
|
+
for (const line of text.split("\n")) {
|
|
4
|
+
if (line.trim() === "")
|
|
5
|
+
break;
|
|
6
|
+
const eq = line.indexOf("=");
|
|
7
|
+
if (eq <= 0)
|
|
8
|
+
continue;
|
|
9
|
+
attributes[line.slice(0, eq)] = line.slice(eq + 1).replace(/\r$/, "");
|
|
10
|
+
}
|
|
11
|
+
const path = attributes["path"];
|
|
12
|
+
const request = {
|
|
13
|
+
protocol: attributes["protocol"] ?? "",
|
|
14
|
+
host: attributes["host"] ?? "",
|
|
15
|
+
attributes,
|
|
16
|
+
};
|
|
17
|
+
if (path) {
|
|
18
|
+
request.path = path;
|
|
19
|
+
const repo = repoFromPath(path);
|
|
20
|
+
if (repo)
|
|
21
|
+
request.repo = repo;
|
|
22
|
+
}
|
|
23
|
+
return request;
|
|
24
|
+
}
|
|
25
|
+
/** `ws_1.git/info/lfs` → `ws_1`; `team/ws_1.git` → `team/ws_1`. */
|
|
26
|
+
export function repoFromPath(path) {
|
|
27
|
+
const trimmed = path
|
|
28
|
+
.replace(/^\/+/, "")
|
|
29
|
+
.replace(/\/info\/lfs(\/.*)?$/, "")
|
|
30
|
+
.replace(/\/+$/, "")
|
|
31
|
+
.replace(/\.git$/, "");
|
|
32
|
+
return trimmed === "" ? undefined : trimmed;
|
|
33
|
+
}
|
|
34
|
+
export function formatCredential(credential) {
|
|
35
|
+
for (const value of [credential.username, credential.password]) {
|
|
36
|
+
if (/[\n\0]/.test(value))
|
|
37
|
+
throw new Error("Credential values cannot contain newlines");
|
|
38
|
+
}
|
|
39
|
+
const lines = [
|
|
40
|
+
`username=${credential.username}`,
|
|
41
|
+
`password=${credential.password}`,
|
|
42
|
+
];
|
|
43
|
+
if (credential.expiresAt)
|
|
44
|
+
lines.push(`password_expiry_utc=${String(Math.floor(credential.expiresAt.getTime() / 1000))}`);
|
|
45
|
+
return `${lines.join("\n")}\n`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Runs one helper action (`get`, `store` or `erase`) on git's input and returns what to print.
|
|
49
|
+
* Unknown actions print nothing, as the protocol asks.
|
|
50
|
+
*/
|
|
51
|
+
export async function credentialHelper(action, input, provider) {
|
|
52
|
+
const request = parseCredentialInput(input);
|
|
53
|
+
if (action === "get") {
|
|
54
|
+
const credential = await provider.get(request);
|
|
55
|
+
return credential ? formatCredential(credential) : "";
|
|
56
|
+
}
|
|
57
|
+
if (action === "erase")
|
|
58
|
+
await provider.erase?.(request);
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAiCA,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,IAAI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