@aigne/afs-git 1.11.0-beta → 1.11.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -84
- package/README.md +0 -4
- package/dist/index.cjs +145 -20
- package/dist/index.d.cts +159 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +159 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +145 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -4,8 +4,28 @@ import { AFSAccessMode, AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSLi
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
interface AFSGitOptions {
|
|
6
6
|
name?: string;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Local path to git repository.
|
|
9
|
+
* If remoteUrl is provided and repoPath doesn't exist, will clone to this path.
|
|
10
|
+
* If remoteUrl is provided and repoPath is not specified, clones to temp directory.
|
|
11
|
+
*/
|
|
12
|
+
repoPath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Remote repository URL (https or git protocol).
|
|
15
|
+
* If provided, will clone the repository if repoPath doesn't exist.
|
|
16
|
+
* Examples:
|
|
17
|
+
* - https://github.com/user/repo.git
|
|
18
|
+
* - git@github.com:user/repo.git
|
|
19
|
+
*/
|
|
20
|
+
remoteUrl?: string;
|
|
8
21
|
description?: string;
|
|
22
|
+
/**
|
|
23
|
+
* List of branches to expose/access.
|
|
24
|
+
* Also used for clone optimization when cloning from remoteUrl:
|
|
25
|
+
* - Single branch (e.g., ['main']): Uses --single-branch for faster clone
|
|
26
|
+
* - Multiple branches: Clones all branches, filters access to specified ones
|
|
27
|
+
* - Not specified: All branches are accessible
|
|
28
|
+
*/
|
|
9
29
|
branches?: string[];
|
|
10
30
|
/**
|
|
11
31
|
* Access mode for this module.
|
|
@@ -26,14 +46,38 @@ interface AFSGitOptions {
|
|
|
26
46
|
name: string;
|
|
27
47
|
email: string;
|
|
28
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Clone depth for shallow clone (only used when cloning from remoteUrl)
|
|
51
|
+
* @default 1
|
|
52
|
+
*/
|
|
53
|
+
depth?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Automatically clean up cloned repository on cleanup()
|
|
56
|
+
* Only applies when repository was auto-cloned to temp directory
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
autoCleanup?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Git clone options (only used when cloning from remoteUrl)
|
|
62
|
+
*/
|
|
63
|
+
cloneOptions?: {
|
|
64
|
+
/**
|
|
65
|
+
* Authentication credentials for private repositories
|
|
66
|
+
*/
|
|
67
|
+
auth?: {
|
|
68
|
+
username?: string;
|
|
69
|
+
password?: string;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
29
72
|
}
|
|
30
73
|
declare class AFSGit implements AFSModule {
|
|
31
74
|
options: AFSGitOptions & {
|
|
32
75
|
cwd?: string;
|
|
33
76
|
};
|
|
34
|
-
static schema(): z.ZodEffects<z.ZodObject<{
|
|
77
|
+
static schema(): z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
35
78
|
name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
36
|
-
repoPath: z.
|
|
79
|
+
repoPath: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
80
|
+
remoteUrl: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
37
81
|
description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
38
82
|
branches: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
39
83
|
accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
|
|
@@ -45,9 +89,23 @@ declare class AFSGit implements AFSModule {
|
|
|
45
89
|
name: string;
|
|
46
90
|
email: string;
|
|
47
91
|
} | undefined>;
|
|
92
|
+
depth: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
|
|
93
|
+
autoCleanup: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
|
|
94
|
+
cloneOptions: z.ZodType<{
|
|
95
|
+
auth?: {
|
|
96
|
+
username?: string | undefined;
|
|
97
|
+
password?: string | undefined;
|
|
98
|
+
} | undefined;
|
|
99
|
+
} | undefined, z.ZodTypeDef, {
|
|
100
|
+
auth?: {
|
|
101
|
+
username?: string | undefined;
|
|
102
|
+
password?: string | undefined;
|
|
103
|
+
} | undefined;
|
|
104
|
+
} | undefined>;
|
|
48
105
|
}, "strip", z.ZodTypeAny, {
|
|
49
|
-
repoPath: string;
|
|
50
106
|
name?: string | undefined;
|
|
107
|
+
repoPath?: string | undefined;
|
|
108
|
+
remoteUrl?: string | undefined;
|
|
51
109
|
description?: string | undefined;
|
|
52
110
|
branches?: string[] | undefined;
|
|
53
111
|
accessMode?: "readonly" | "readwrite" | undefined;
|
|
@@ -56,9 +114,18 @@ declare class AFSGit implements AFSModule {
|
|
|
56
114
|
name: string;
|
|
57
115
|
email: string;
|
|
58
116
|
} | undefined;
|
|
117
|
+
depth?: number | undefined;
|
|
118
|
+
autoCleanup?: boolean | undefined;
|
|
119
|
+
cloneOptions?: {
|
|
120
|
+
auth?: {
|
|
121
|
+
username?: string | undefined;
|
|
122
|
+
password?: string | undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
} | undefined;
|
|
59
125
|
}, {
|
|
60
|
-
repoPath: string;
|
|
61
126
|
name?: string | undefined;
|
|
127
|
+
repoPath?: string | undefined;
|
|
128
|
+
remoteUrl?: string | undefined;
|
|
62
129
|
description?: string | undefined;
|
|
63
130
|
branches?: string[] | undefined;
|
|
64
131
|
accessMode?: "readonly" | "readwrite" | undefined;
|
|
@@ -67,9 +134,18 @@ declare class AFSGit implements AFSModule {
|
|
|
67
134
|
name: string;
|
|
68
135
|
email: string;
|
|
69
136
|
} | undefined;
|
|
137
|
+
depth?: number | undefined;
|
|
138
|
+
autoCleanup?: boolean | undefined;
|
|
139
|
+
cloneOptions?: {
|
|
140
|
+
auth?: {
|
|
141
|
+
username?: string | undefined;
|
|
142
|
+
password?: string | undefined;
|
|
143
|
+
} | undefined;
|
|
144
|
+
} | undefined;
|
|
70
145
|
}>, {
|
|
71
|
-
repoPath: string;
|
|
72
146
|
name?: string | undefined;
|
|
147
|
+
repoPath?: string | undefined;
|
|
148
|
+
remoteUrl?: string | undefined;
|
|
73
149
|
description?: string | undefined;
|
|
74
150
|
branches?: string[] | undefined;
|
|
75
151
|
accessMode?: "readonly" | "readwrite" | undefined;
|
|
@@ -78,18 +154,83 @@ declare class AFSGit implements AFSModule {
|
|
|
78
154
|
name: string;
|
|
79
155
|
email: string;
|
|
80
156
|
} | undefined;
|
|
157
|
+
depth?: number | undefined;
|
|
158
|
+
autoCleanup?: boolean | undefined;
|
|
159
|
+
cloneOptions?: {
|
|
160
|
+
auth?: {
|
|
161
|
+
username?: string | undefined;
|
|
162
|
+
password?: string | undefined;
|
|
163
|
+
} | undefined;
|
|
164
|
+
} | undefined;
|
|
165
|
+
}, {
|
|
166
|
+
name?: string | undefined;
|
|
167
|
+
repoPath?: string | undefined;
|
|
168
|
+
remoteUrl?: string | undefined;
|
|
169
|
+
description?: string | undefined;
|
|
170
|
+
branches?: string[] | undefined;
|
|
171
|
+
accessMode?: "readonly" | "readwrite" | undefined;
|
|
172
|
+
autoCommit?: boolean | undefined;
|
|
173
|
+
commitAuthor?: {
|
|
174
|
+
name: string;
|
|
175
|
+
email: string;
|
|
176
|
+
} | undefined;
|
|
177
|
+
depth?: number | undefined;
|
|
178
|
+
autoCleanup?: boolean | undefined;
|
|
179
|
+
cloneOptions?: {
|
|
180
|
+
auth?: {
|
|
181
|
+
username?: string | undefined;
|
|
182
|
+
password?: string | undefined;
|
|
183
|
+
} | undefined;
|
|
184
|
+
} | undefined;
|
|
185
|
+
}>, {
|
|
186
|
+
name?: string | undefined;
|
|
187
|
+
repoPath?: string | undefined;
|
|
188
|
+
remoteUrl?: string | undefined;
|
|
189
|
+
description?: string | undefined;
|
|
190
|
+
branches?: string[] | undefined;
|
|
191
|
+
accessMode?: "readonly" | "readwrite" | undefined;
|
|
192
|
+
autoCommit?: boolean | undefined;
|
|
193
|
+
commitAuthor?: {
|
|
194
|
+
name: string;
|
|
195
|
+
email: string;
|
|
196
|
+
} | undefined;
|
|
197
|
+
depth?: number | undefined;
|
|
198
|
+
autoCleanup?: boolean | undefined;
|
|
199
|
+
cloneOptions?: {
|
|
200
|
+
auth?: {
|
|
201
|
+
username?: string | undefined;
|
|
202
|
+
password?: string | undefined;
|
|
203
|
+
} | undefined;
|
|
204
|
+
} | undefined;
|
|
81
205
|
}, any>;
|
|
82
206
|
static load({
|
|
83
207
|
filepath,
|
|
84
208
|
parsed
|
|
85
209
|
}: AFSModuleLoadParams): Promise<AFSGit>;
|
|
210
|
+
private initPromise;
|
|
86
211
|
private git;
|
|
87
212
|
private tempBase;
|
|
88
213
|
private worktrees;
|
|
89
214
|
private repoHash;
|
|
215
|
+
private isAutoCloned;
|
|
216
|
+
private clonedPath?;
|
|
217
|
+
private repoPath;
|
|
90
218
|
constructor(options: AFSGitOptions & {
|
|
91
219
|
cwd?: string;
|
|
92
220
|
});
|
|
221
|
+
/**
|
|
222
|
+
* Wait for async initialization to complete
|
|
223
|
+
*/
|
|
224
|
+
ready(): Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* Async initialization logic (runs in constructor)
|
|
227
|
+
* Handles cloning remote repositories if needed
|
|
228
|
+
*/
|
|
229
|
+
private initialize;
|
|
230
|
+
/**
|
|
231
|
+
* Clone a remote repository to local path
|
|
232
|
+
*/
|
|
233
|
+
private static cloneRepository;
|
|
93
234
|
name: string;
|
|
94
235
|
description?: string;
|
|
95
236
|
accessMode: AFSAccessMode;
|
|
@@ -138,6 +279,18 @@ declare class AFSGit implements AFSModule {
|
|
|
138
279
|
message?: string;
|
|
139
280
|
}>;
|
|
140
281
|
search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
|
|
282
|
+
/**
|
|
283
|
+
* Fetch latest changes from remote
|
|
284
|
+
*/
|
|
285
|
+
fetch(): Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* Pull latest changes from remote for current branch
|
|
288
|
+
*/
|
|
289
|
+
pull(): Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* Push local changes to remote
|
|
292
|
+
*/
|
|
293
|
+
push(branch?: string): Promise<void>;
|
|
141
294
|
/**
|
|
142
295
|
* Cleanup all worktrees (useful when unmounting)
|
|
143
296
|
*/
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UAiCiB,aAAA;EAAA,IAAA;EAAA;AA6GjB;;;;EA7GiB,QAAA;EAAA;AA6GjB;;;;;;EA7GiB,SAAA;EAAA,WAAA;EAAA;AA6GjB;;;;;;EA7GiB,QAAA;EAAA;AA6GjB;;;;;EA7GiB,UAAA,GA+BF,aAAA;EAAA;AA8Ef;;;EA9Ee,UAAA;EAAA;AA8Ef;;EA9Ee,YAAA;IAAA,IAAA;IAAA,KAAA;EAAA;EAAA;AA8Ef;;;EA9Ee,KAAA;EAAA;AA8Ef;;;;EA9Ee,WAAA;EAAA;AA8Ef;;EA9Ee,YAAA;IAAA;AA8Ef;;IA9Ee,IAAA;MAAA,QAAA;MAAA,QAAA;IAAA;EAAA;AAAA;AAAA,cA8EF,MAAA,YAAkB,SAAA;EAAA,OAAA,EAqBD,aAAA;IAAA,GAAA;EAAA;EAAA,OAAA,OAAA,GApBf,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;IAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAI2B,mBAAA,GAAmB,OAAA,CAAA,MAAA;EAAA,QAAA,WAAA;EAAA,QAAA,GAAA;EAAA,QAAA,QAAA;EAAA,QAAA,SAAA;EAAA,QAAA,QAAA;EAAA,QAAA,YAAA;EAAA,QAAA,UAAA;EAAA,QAAA,QAAA;EAAA,YAAA,OAAA,EAgB/B,aAAA;IAAA,GAAA;EAAA;EAAA;;;EAAA,MAAA,GAgDb,OAAA;EAAA;;;;EAAA,QAAA,UAAA;EAAA;;;EAAA,eAAA,eAAA;EAAA,IAAA;EAAA,WAAA;EAAA,UAAA,EAgGH,aAAA;EAAA;;;;;;;;;EAAA,QAAA,SAAA;EAAA;;;EAAA,QAAA,WAAA;EAAA;;;EAAA,QAAA,YAAA;EAAA;;;EAAA,QAAA,WAAA;EAAA;;;EAAA,QAAA,cAAA;EAAA;;;EAAA,QAAA,iBAAA;EAAA;;;;;;EAAA,QAAA,SAAA;EAAA,KAAA,IAAA,UAAA,OAAA,GA8PuB,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,KAAA,IAAA,UAAA,QAAA,GAyCxB,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,MAAA,IAAA,UAAA,KAAA,EAgGpD,oBAAA,EAAA,OAAA,GACG,eAAA,GACT,OAAA,CAAQ,cAAA;EAAA,OAAA,IAAA,UAAA,OAAA,GA2E0B,gBAAA,GAAmB,OAAA,CAAQ,eAAA;EAAA,OAAA,OAAA,UAAA,OAAA,UAAA,OAAA,GAoDpD,gBAAA,GACT,OAAA;IAAA,OAAA;EAAA;EAAA,OAAA,IAAA,UAAA,KAAA,UAAA,OAAA,GAyEiD,gBAAA,GAAmB,OAAA,CAAQ,eAAA;EAAA;;;EAAA,MAAA,GAuFhE,OAAA;EAAA;;;EAAA,KAAA,GAQD,OAAA;EAAA;;;EAAA,KAAA,MAAA,YAQe,OAAA;EAAA;;;EAAA,QAAA,GAYZ,OAAA;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -9,11 +9,12 @@ import { simpleGit } from "simple-git";
|
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
|
|
11
11
|
//#region src/index.ts
|
|
12
|
-
const execFileAsync = promisify(execFile);
|
|
13
12
|
const LIST_MAX_LIMIT = 1e3;
|
|
13
|
+
const execFileAsync = promisify(execFile);
|
|
14
14
|
const afsGitOptionsSchema = camelize(z.object({
|
|
15
15
|
name: optionalize(z.string()),
|
|
16
|
-
repoPath: z.string().describe("The path to the git repository"),
|
|
16
|
+
repoPath: optionalize(z.string().describe("The path to the git repository")),
|
|
17
|
+
remoteUrl: optionalize(z.string().describe("Remote repository URL (https or git protocol)")),
|
|
17
18
|
description: optionalize(z.string().describe("A description of the repository")),
|
|
18
19
|
branches: optionalize(z.array(z.string()).describe("List of branches to expose")),
|
|
19
20
|
accessMode: optionalize(z.enum(["readonly", "readwrite"]).describe("Access mode for this module")),
|
|
@@ -21,35 +22,107 @@ const afsGitOptionsSchema = camelize(z.object({
|
|
|
21
22
|
commitAuthor: optionalize(z.object({
|
|
22
23
|
name: z.string(),
|
|
23
24
|
email: z.string()
|
|
24
|
-
}))
|
|
25
|
-
|
|
25
|
+
})),
|
|
26
|
+
depth: optionalize(z.number().describe("Clone depth for shallow clone")),
|
|
27
|
+
autoCleanup: optionalize(z.boolean().describe("Automatically clean up cloned repository on cleanup()")),
|
|
28
|
+
cloneOptions: optionalize(z.object({ auth: optionalize(z.object({
|
|
29
|
+
username: optionalize(z.string()),
|
|
30
|
+
password: optionalize(z.string())
|
|
31
|
+
})) }))
|
|
32
|
+
}).refine((data) => data.repoPath || data.remoteUrl, { message: "Either repoPath or remoteUrl must be provided" }));
|
|
26
33
|
var AFSGit = class AFSGit {
|
|
27
34
|
static schema() {
|
|
28
35
|
return afsGitOptionsSchema;
|
|
29
36
|
}
|
|
30
37
|
static async load({ filepath, parsed }) {
|
|
31
|
-
|
|
38
|
+
const instance = new AFSGit({
|
|
32
39
|
...await AFSGit.schema().parseAsync(parsed),
|
|
33
40
|
cwd: dirname(filepath)
|
|
34
41
|
});
|
|
42
|
+
await instance.ready();
|
|
43
|
+
return instance;
|
|
35
44
|
}
|
|
45
|
+
initPromise;
|
|
36
46
|
git;
|
|
37
47
|
tempBase;
|
|
38
48
|
worktrees = /* @__PURE__ */ new Map();
|
|
39
49
|
repoHash;
|
|
50
|
+
isAutoCloned = false;
|
|
51
|
+
clonedPath;
|
|
52
|
+
repoPath;
|
|
40
53
|
constructor(options) {
|
|
41
54
|
this.options = options;
|
|
42
55
|
zodParse(afsGitOptionsSchema, options);
|
|
43
56
|
let repoPath;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
let repoName;
|
|
58
|
+
if (options.repoPath) {
|
|
59
|
+
repoPath = isAbsolute(options.repoPath) ? options.repoPath : join(options.cwd || process.cwd(), options.repoPath);
|
|
60
|
+
repoName = basename(repoPath);
|
|
61
|
+
} else if (options.remoteUrl) {
|
|
62
|
+
const urlParts = options.remoteUrl.split("/");
|
|
63
|
+
repoName = urlParts[urlParts.length - 1]?.replace(/\.git$/, "") || "git";
|
|
64
|
+
const repoHash = createHash("md5").update(options.remoteUrl).digest("hex").substring(0, 8);
|
|
65
|
+
repoPath = join(tmpdir(), `afs-git-remote-${repoHash}`);
|
|
66
|
+
} else throw new Error("Either repoPath or remoteUrl must be provided");
|
|
67
|
+
this.repoPath = repoPath;
|
|
68
|
+
this.name = options.name || repoName;
|
|
48
69
|
this.description = options.description;
|
|
49
70
|
this.accessMode = options.accessMode ?? "readonly";
|
|
50
|
-
this.git = simpleGit(repoPath);
|
|
51
71
|
this.repoHash = createHash("md5").update(repoPath).digest("hex").substring(0, 8);
|
|
52
72
|
this.tempBase = join(tmpdir(), `afs-git-${this.repoHash}`);
|
|
73
|
+
this.git = null;
|
|
74
|
+
this.initPromise = this.initialize();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Wait for async initialization to complete
|
|
78
|
+
*/
|
|
79
|
+
async ready() {
|
|
80
|
+
await this.initPromise;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Async initialization logic (runs in constructor)
|
|
84
|
+
* Handles cloning remote repositories if needed
|
|
85
|
+
*/
|
|
86
|
+
async initialize() {
|
|
87
|
+
const options = this.options;
|
|
88
|
+
if (options.remoteUrl) {
|
|
89
|
+
const targetPath = options.repoPath ? isAbsolute(options.repoPath) ? options.repoPath : join(options.cwd || process.cwd(), options.repoPath) : this.repoPath;
|
|
90
|
+
if (!options.repoPath) this.isAutoCloned = true;
|
|
91
|
+
if (!await stat(targetPath).then(() => true).catch(() => false)) {
|
|
92
|
+
const singleBranch = options.branches?.length === 1 ? options.branches[0] : void 0;
|
|
93
|
+
await AFSGit.cloneRepository(options.remoteUrl, targetPath, {
|
|
94
|
+
depth: options.depth ?? 1,
|
|
95
|
+
branch: singleBranch,
|
|
96
|
+
auth: options.cloneOptions?.auth
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (targetPath !== this.repoPath) {
|
|
100
|
+
this.repoPath = targetPath;
|
|
101
|
+
this.repoHash = createHash("md5").update(targetPath).digest("hex").substring(0, 8);
|
|
102
|
+
this.tempBase = join(tmpdir(), `afs-git-${this.repoHash}`);
|
|
103
|
+
}
|
|
104
|
+
this.clonedPath = this.isAutoCloned ? targetPath : void 0;
|
|
105
|
+
}
|
|
106
|
+
this.git = simpleGit(this.repoPath);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Clone a remote repository to local path
|
|
110
|
+
*/
|
|
111
|
+
static async cloneRepository(remoteUrl, targetPath, options = {}) {
|
|
112
|
+
const git = simpleGit();
|
|
113
|
+
const cloneArgs = [];
|
|
114
|
+
if (options.depth) cloneArgs.push("--depth", options.depth.toString());
|
|
115
|
+
if (options.branch) cloneArgs.push("--branch", options.branch, "--single-branch");
|
|
116
|
+
let cloneUrl = remoteUrl;
|
|
117
|
+
if (options.auth?.username && options.auth?.password) {
|
|
118
|
+
if (remoteUrl.startsWith("https://")) {
|
|
119
|
+
const url = new URL(remoteUrl);
|
|
120
|
+
url.username = encodeURIComponent(options.auth.username);
|
|
121
|
+
url.password = encodeURIComponent(options.auth.password);
|
|
122
|
+
cloneUrl = url.toString();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
await git.clone(cloneUrl, targetPath, cloneArgs);
|
|
53
126
|
}
|
|
54
127
|
name;
|
|
55
128
|
description;
|
|
@@ -136,8 +209,8 @@ var AFSGit = class AFSGit {
|
|
|
136
209
|
async ensureWorktree(branch) {
|
|
137
210
|
if (this.worktrees.has(branch)) return this.worktrees.get(branch);
|
|
138
211
|
if ((await this.git.revparse(["--abbrev-ref", "HEAD"])).trim() === branch) {
|
|
139
|
-
this.worktrees.set(branch, this.
|
|
140
|
-
return this.
|
|
212
|
+
this.worktrees.set(branch, this.repoPath);
|
|
213
|
+
return this.repoPath;
|
|
141
214
|
}
|
|
142
215
|
const worktreePath = join(this.tempBase, branch);
|
|
143
216
|
if (!await stat(worktreePath).then(() => true).catch(() => false)) {
|
|
@@ -242,18 +315,36 @@ var AFSGit = class AFSGit {
|
|
|
242
315
|
return `/${encodedBranch}/${filePath}`;
|
|
243
316
|
}
|
|
244
317
|
async list(path, options) {
|
|
318
|
+
await this.ready();
|
|
245
319
|
const { branch, filePath } = this.parsePath(path);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
320
|
+
const maxDepth = options?.maxDepth ?? 1;
|
|
321
|
+
const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);
|
|
322
|
+
if (!branch) {
|
|
323
|
+
const branches = await this.getBranches();
|
|
324
|
+
const entries = [];
|
|
325
|
+
for (const name of branches) {
|
|
326
|
+
if (entries.length >= limit) break;
|
|
327
|
+
const encodedPath = this.buildPath(name);
|
|
328
|
+
entries.push({
|
|
329
|
+
id: encodedPath,
|
|
330
|
+
path: encodedPath,
|
|
331
|
+
metadata: { type: "directory" }
|
|
332
|
+
});
|
|
333
|
+
if (maxDepth > 1) {
|
|
334
|
+
const branchResult = await this.listWithGitLsTree(name, "", {
|
|
335
|
+
...options,
|
|
336
|
+
maxDepth: maxDepth - 1,
|
|
337
|
+
limit: limit - entries.length
|
|
338
|
+
});
|
|
339
|
+
entries.push(...branchResult.data);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return { data: entries };
|
|
343
|
+
}
|
|
254
344
|
return this.listWithGitLsTree(branch, filePath, options);
|
|
255
345
|
}
|
|
256
346
|
async read(path, _options) {
|
|
347
|
+
await this.ready();
|
|
257
348
|
const { branch, filePath } = this.parsePath(path);
|
|
258
349
|
if (!branch) return { data: {
|
|
259
350
|
id: "/",
|
|
@@ -322,6 +413,7 @@ var AFSGit = class AFSGit {
|
|
|
322
413
|
}
|
|
323
414
|
}
|
|
324
415
|
async write(path, entry, options) {
|
|
416
|
+
await this.ready();
|
|
325
417
|
const { branch, filePath } = this.parsePath(path);
|
|
326
418
|
if (!branch || !filePath) throw new Error("Cannot write to root or branch root");
|
|
327
419
|
const worktreePath = await this.ensureWorktree(branch);
|
|
@@ -366,6 +458,7 @@ var AFSGit = class AFSGit {
|
|
|
366
458
|
} };
|
|
367
459
|
}
|
|
368
460
|
async delete(path, options) {
|
|
461
|
+
await this.ready();
|
|
369
462
|
const { branch, filePath } = this.parsePath(path);
|
|
370
463
|
if (!branch || !filePath) throw new Error("Cannot delete root or branch root");
|
|
371
464
|
const worktreePath = await this.ensureWorktree(branch);
|
|
@@ -388,6 +481,7 @@ var AFSGit = class AFSGit {
|
|
|
388
481
|
return { message: `Successfully deleted: ${path}` };
|
|
389
482
|
}
|
|
390
483
|
async rename(oldPath, newPath, options) {
|
|
484
|
+
await this.ready();
|
|
391
485
|
const { branch: oldBranch, filePath: oldFilePath } = this.parsePath(oldPath);
|
|
392
486
|
const { branch: newBranch, filePath: newFilePath } = this.parsePath(newPath);
|
|
393
487
|
if (!oldBranch || !oldFilePath) throw new Error("Cannot rename from root or branch root");
|
|
@@ -418,6 +512,7 @@ var AFSGit = class AFSGit {
|
|
|
418
512
|
return { message: `Successfully renamed '${oldPath}' to '${newPath}'` };
|
|
419
513
|
}
|
|
420
514
|
async search(path, query, options) {
|
|
515
|
+
await this.ready();
|
|
421
516
|
const { branch, filePath } = this.parsePath(path);
|
|
422
517
|
if (!branch) return {
|
|
423
518
|
data: [],
|
|
@@ -476,9 +571,32 @@ var AFSGit = class AFSGit {
|
|
|
476
571
|
}
|
|
477
572
|
}
|
|
478
573
|
/**
|
|
574
|
+
* Fetch latest changes from remote
|
|
575
|
+
*/
|
|
576
|
+
async fetch() {
|
|
577
|
+
await this.ready();
|
|
578
|
+
await this.git.fetch();
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Pull latest changes from remote for current branch
|
|
582
|
+
*/
|
|
583
|
+
async pull() {
|
|
584
|
+
await this.ready();
|
|
585
|
+
await this.git.pull();
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Push local changes to remote
|
|
589
|
+
*/
|
|
590
|
+
async push(branch) {
|
|
591
|
+
await this.ready();
|
|
592
|
+
if (branch) await this.git.push("origin", branch);
|
|
593
|
+
else await this.git.push();
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
479
596
|
* Cleanup all worktrees (useful when unmounting)
|
|
480
597
|
*/
|
|
481
598
|
async cleanup() {
|
|
599
|
+
await this.ready();
|
|
482
600
|
for (const [_branch, worktreePath] of this.worktrees) try {
|
|
483
601
|
await this.git.raw([
|
|
484
602
|
"worktree",
|
|
@@ -494,6 +612,13 @@ var AFSGit = class AFSGit {
|
|
|
494
612
|
force: true
|
|
495
613
|
});
|
|
496
614
|
} catch {}
|
|
615
|
+
const autoCleanup = this.options.autoCleanup ?? true;
|
|
616
|
+
if (this.isAutoCloned && autoCleanup && this.clonedPath) try {
|
|
617
|
+
await rm(this.clonedPath, {
|
|
618
|
+
recursive: true,
|
|
619
|
+
force: true
|
|
620
|
+
});
|
|
621
|
+
} catch {}
|
|
497
622
|
}
|
|
498
623
|
};
|
|
499
624
|
|