@catamorphic/git 0.0.0-stage → 0.1.0-alpha.30
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.txt +202 -0
- package/NOTICE.txt +32 -0
- package/dist/checkout-remote-backend.d.ts +12 -0
- package/dist/checkout-remote-backend.d.ts.map +1 -0
- package/dist/file-reads.d.ts +15 -0
- package/dist/file-reads.d.ts.map +1 -0
- package/dist/fs-backend.d.ts +30 -0
- package/dist/fs-backend.d.ts.map +1 -0
- package/dist/fs-remote-backend.d.ts +47 -0
- package/dist/fs-remote-backend.d.ts.map +1 -0
- package/dist/git-object-codec.d.ts +31 -0
- package/dist/git-object-codec.d.ts.map +1 -0
- package/dist/git-sync.d.ts +61 -0
- package/dist/git-sync.d.ts.map +1 -0
- package/dist/in-memory-object-store.d.ts +23 -0
- package/dist/in-memory-object-store.d.ts.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4746 -0
- package/dist/index.js.map +32 -0
- package/dist/migrate-workflow.d.ts +12 -0
- package/dist/migrate-workflow.d.ts.map +1 -0
- package/dist/native-git.d.ts +25 -0
- package/dist/native-git.d.ts.map +1 -0
- package/dist/native-project-repo.d.ts +57 -0
- package/dist/native-project-repo.d.ts.map +1 -0
- package/dist/network-sync.d.ts +58 -0
- package/dist/network-sync.d.ts.map +1 -0
- package/dist/network.d.ts +81 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/object-remote-backend.d.ts +95 -0
- package/dist/object-remote-backend.d.ts.map +1 -0
- package/dist/object-store.d.ts +42 -0
- package/dist/object-store.d.ts.map +1 -0
- package/dist/origin-draft.d.ts +264 -0
- package/dist/origin-draft.d.ts.map +1 -0
- package/dist/origin-objects.d.ts +201 -0
- package/dist/origin-objects.d.ts.map +1 -0
- package/dist/personal-files.d.ts +6 -0
- package/dist/personal-files.d.ts.map +1 -0
- package/dist/project-manager.d.ts +214 -0
- package/dist/project-manager.d.ts.map +1 -0
- package/dist/project-repo.d.ts +79 -0
- package/dist/project-repo.d.ts.map +1 -0
- package/dist/ref-moved-error.d.ts +13 -0
- package/dist/ref-moved-error.d.ts.map +1 -0
- package/dist/ref-names.d.ts +18 -0
- package/dist/ref-names.d.ts.map +1 -0
- package/dist/types.d.ts +276 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workspace-mirror.d.ts +110 -0
- package/dist/workspace-mirror.d.ts.map +1 -0
- package/package.json +53 -4
- package/src/checkout-remote-backend.ts +154 -0
- package/src/diff3.d.ts +16 -0
- package/src/file-reads.ts +53 -0
- package/src/fs-backend.ts +206 -0
- package/src/fs-remote-backend.ts +252 -0
- package/src/git-object-codec.ts +87 -0
- package/src/git-sync.ts +539 -0
- package/src/in-memory-object-store.ts +60 -0
- package/src/index.ts +110 -0
- package/src/migrate-workflow.ts +30 -0
- package/src/native-git.ts +177 -0
- package/src/native-project-repo.ts +515 -0
- package/src/network-sync.ts +239 -0
- package/src/network.ts +269 -0
- package/src/object-remote-backend.ts +366 -0
- package/src/object-store.ts +41 -0
- package/src/origin-draft.ts +1033 -0
- package/src/origin-objects.ts +906 -0
- package/src/personal-files.ts +57 -0
- package/src/project-manager.ts +743 -0
- package/src/project-repo.ts +800 -0
- package/src/ref-moved-error.ts +18 -0
- package/src/ref-names.ts +47 -0
- package/src/types.ts +289 -0
- package/src/workspace-mirror.ts +400 -0
- package/README.md +0 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ProjectManager } from "./project-manager.js";
|
|
2
|
+
|
|
3
|
+
export async function migrateWorkflowToProject({
|
|
4
|
+
projectManager,
|
|
5
|
+
tenantId,
|
|
6
|
+
projectId,
|
|
7
|
+
workflowName,
|
|
8
|
+
workflowCode,
|
|
9
|
+
}: {
|
|
10
|
+
projectManager: ProjectManager;
|
|
11
|
+
tenantId: string;
|
|
12
|
+
projectId: string;
|
|
13
|
+
workflowName: string;
|
|
14
|
+
workflowCode: string;
|
|
15
|
+
}) {
|
|
16
|
+
const sanitizedName = workflowName
|
|
17
|
+
.replace(/[^a-zA-Z0-9-]/g, "-")
|
|
18
|
+
.toLowerCase();
|
|
19
|
+
|
|
20
|
+
const repo = await projectManager.create(tenantId, projectId, {
|
|
21
|
+
name: sanitizedName,
|
|
22
|
+
initialFiles: {
|
|
23
|
+
[`src/${sanitizedName}.ts`]: workflowCode,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const sha = await repo.resolveRef("HEAD");
|
|
28
|
+
await repo.dispose();
|
|
29
|
+
return { projectId, commitSha: sha };
|
|
30
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
|
|
6
|
+
const execute = promisify(execFile);
|
|
7
|
+
|
|
8
|
+
export interface NativeGitAuth {
|
|
9
|
+
url: string;
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Native Git runs outside the host event loop and never refreshes the index on reads. */
|
|
15
|
+
export async function nativeGit(
|
|
16
|
+
cwd: string,
|
|
17
|
+
args: readonly string[],
|
|
18
|
+
auth?: NativeGitAuth,
|
|
19
|
+
): Promise<string> {
|
|
20
|
+
// Large repository transfers need a different budget from local reads.
|
|
21
|
+
const networkOperation = ["fetch", "push", "clone", "ls-remote"].includes(
|
|
22
|
+
args[0] ?? "",
|
|
23
|
+
);
|
|
24
|
+
return (
|
|
25
|
+
await execute("git", ["-C", cwd, ...args], {
|
|
26
|
+
env: {
|
|
27
|
+
...process.env,
|
|
28
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
29
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
30
|
+
...(auth
|
|
31
|
+
? {
|
|
32
|
+
GIT_CONFIG_COUNT: "1",
|
|
33
|
+
GIT_CONFIG_KEY_0: `http.${auth.url}.extraHeader`,
|
|
34
|
+
GIT_CONFIG_VALUE_0: `Authorization: Basic ${Buffer.from(`${auth.username}:${auth.password}`).toString("base64")}`,
|
|
35
|
+
}
|
|
36
|
+
: {}),
|
|
37
|
+
},
|
|
38
|
+
timeout: networkOperation ? 15 * 60_000 : 60_000,
|
|
39
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
40
|
+
})
|
|
41
|
+
).stdout;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function nativeGitBytes(
|
|
45
|
+
cwd: string,
|
|
46
|
+
args: readonly string[],
|
|
47
|
+
input?: Uint8Array,
|
|
48
|
+
): Promise<Uint8Array> {
|
|
49
|
+
const command = execute("git", ["-C", cwd, ...args], {
|
|
50
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
51
|
+
timeout: 60_000,
|
|
52
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
53
|
+
encoding: "buffer",
|
|
54
|
+
});
|
|
55
|
+
if (input) command.child.stdin?.end(input);
|
|
56
|
+
return new Uint8Array((await command).stdout);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface LocalFolder {
|
|
60
|
+
path: string;
|
|
61
|
+
commonDirectory: string | null;
|
|
62
|
+
branch: string | null;
|
|
63
|
+
defaultBranch: string | null;
|
|
64
|
+
remoteUrl: string | null;
|
|
65
|
+
remoteBranch: string | null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A .git directory or worktree pointer belongs to this folder, not an ancestor. */
|
|
69
|
+
export async function hasLocalGit({
|
|
70
|
+
path: root,
|
|
71
|
+
}: {
|
|
72
|
+
path: string;
|
|
73
|
+
}): Promise<boolean> {
|
|
74
|
+
return fs.lstat(path.join(root, ".git")).then(
|
|
75
|
+
() => true,
|
|
76
|
+
(error: unknown) => {
|
|
77
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
78
|
+
return false;
|
|
79
|
+
throw error;
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Resolve subfolders, symlink aliases and linked worktrees without modifying the checkout. */
|
|
85
|
+
export async function discoverLocalFolder(input: {
|
|
86
|
+
path: string;
|
|
87
|
+
}): Promise<LocalFolder> {
|
|
88
|
+
const requested = await fs.realpath(input.path);
|
|
89
|
+
if (!(await fs.stat(requested)).isDirectory())
|
|
90
|
+
throw new Error("Choose a folder to open as a project");
|
|
91
|
+
// Check ancestors too: a subfolder of a damaged checkout must not be
|
|
92
|
+
// accepted as a new plain folder, nor later initialized as a nested repo.
|
|
93
|
+
let ancestor = requested;
|
|
94
|
+
while (!(await hasLocalGit({ path: ancestor }))) {
|
|
95
|
+
if (
|
|
96
|
+
await fs.stat(path.join(ancestor, "HEAD")).then(
|
|
97
|
+
() => true,
|
|
98
|
+
() => false,
|
|
99
|
+
)
|
|
100
|
+
) {
|
|
101
|
+
if (
|
|
102
|
+
(
|
|
103
|
+
await nativeGit(ancestor, [
|
|
104
|
+
"rev-parse",
|
|
105
|
+
"--is-bare-repository",
|
|
106
|
+
]).catch(() => "")
|
|
107
|
+
).trim() === "true"
|
|
108
|
+
)
|
|
109
|
+
throw new Error("Choose a working folder, not a bare Git repository");
|
|
110
|
+
}
|
|
111
|
+
const parent = path.dirname(ancestor);
|
|
112
|
+
if (parent === ancestor)
|
|
113
|
+
return {
|
|
114
|
+
path: requested,
|
|
115
|
+
commonDirectory: null,
|
|
116
|
+
branch: null,
|
|
117
|
+
defaultBranch: null,
|
|
118
|
+
remoteUrl: null,
|
|
119
|
+
remoteBranch: null,
|
|
120
|
+
};
|
|
121
|
+
ancestor = parent;
|
|
122
|
+
}
|
|
123
|
+
const root = await fs.realpath(
|
|
124
|
+
(await nativeGit(requested, ["rev-parse", "--show-toplevel"])).trim(),
|
|
125
|
+
);
|
|
126
|
+
const common = (
|
|
127
|
+
await nativeGit(root, ["rev-parse", "--git-common-dir"])
|
|
128
|
+
).trim();
|
|
129
|
+
const branch =
|
|
130
|
+
(await nativeGit(root, ["branch", "--show-current"])).trim() || null;
|
|
131
|
+
const remoteName = branch
|
|
132
|
+
? (
|
|
133
|
+
await nativeGit(root, [
|
|
134
|
+
"config",
|
|
135
|
+
"--get",
|
|
136
|
+
`branch.${branch}.remote`,
|
|
137
|
+
]).catch(() => "")
|
|
138
|
+
).trim() || "origin"
|
|
139
|
+
: "origin";
|
|
140
|
+
const remoteUrl =
|
|
141
|
+
remoteName === "."
|
|
142
|
+
? null
|
|
143
|
+
: (
|
|
144
|
+
await nativeGit(root, ["remote", "get-url", remoteName]).catch(
|
|
145
|
+
() => "",
|
|
146
|
+
)
|
|
147
|
+
).trim() || null;
|
|
148
|
+
const remoteBranch = branch
|
|
149
|
+
? (
|
|
150
|
+
await nativeGit(root, [
|
|
151
|
+
"config",
|
|
152
|
+
"--get",
|
|
153
|
+
`branch.${branch}.merge`,
|
|
154
|
+
]).catch(() => "")
|
|
155
|
+
)
|
|
156
|
+
.trim()
|
|
157
|
+
.replace(/^refs\/heads\//, "") || null
|
|
158
|
+
: null;
|
|
159
|
+
const defaultBranch =
|
|
160
|
+
(
|
|
161
|
+
await nativeGit(root, [
|
|
162
|
+
"symbolic-ref",
|
|
163
|
+
"--short",
|
|
164
|
+
`refs/remotes/${remoteName}/HEAD`,
|
|
165
|
+
]).catch(() => "")
|
|
166
|
+
)
|
|
167
|
+
.trim()
|
|
168
|
+
.replace(`${remoteName}/`, "") || null;
|
|
169
|
+
return {
|
|
170
|
+
path: root,
|
|
171
|
+
commonDirectory: await fs.realpath(path.resolve(root, common)),
|
|
172
|
+
branch,
|
|
173
|
+
defaultBranch,
|
|
174
|
+
remoteUrl,
|
|
175
|
+
remoteBranch,
|
|
176
|
+
};
|
|
177
|
+
}
|