@trebired/git-host 0.1.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/CHANGELOG.md +22 -0
- package/LICENSE +21 -0
- package/README.md +451 -0
- package/dist/api/handler/action.d.ts +5 -0
- package/dist/api/handler/action.d.ts.map +1 -0
- package/dist/api/handler/action.js +47 -0
- package/dist/api/handler/action.js.map +1 -0
- package/dist/api/handler/response.d.ts +34 -0
- package/dist/api/handler/response.d.ts.map +1 -0
- package/dist/api/handler/response.js +87 -0
- package/dist/api/handler/response.js.map +1 -0
- package/dist/api/handler/route.d.ts +15 -0
- package/dist/api/handler/route.d.ts.map +1 -0
- package/dist/api/handler/route.js +51 -0
- package/dist/api/handler/route.js.map +1 -0
- package/dist/api/handler.d.ts +6 -0
- package/dist/api/handler.d.ts.map +1 -0
- package/dist/api/handler.js +117 -0
- package/dist/api/handler.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/create_git_host/branch_methods.d.ts +5 -0
- package/dist/core/create_git_host/branch_methods.d.ts.map +1 -0
- package/dist/core/create_git_host/branch_methods.js +137 -0
- package/dist/core/create_git_host/branch_methods.js.map +1 -0
- package/dist/core/create_git_host/content_methods.d.ts +5 -0
- package/dist/core/create_git_host/content_methods.d.ts.map +1 -0
- package/dist/core/create_git_host/content_methods.js +24 -0
- package/dist/core/create_git_host/content_methods.js.map +1 -0
- package/dist/core/create_git_host/remote_methods.d.ts +5 -0
- package/dist/core/create_git_host/remote_methods.d.ts.map +1 -0
- package/dist/core/create_git_host/remote_methods.js +48 -0
- package/dist/core/create_git_host/remote_methods.js.map +1 -0
- package/dist/core/create_git_host/shared.d.ts +21 -0
- package/dist/core/create_git_host/shared.d.ts.map +1 -0
- package/dist/core/create_git_host/shared.js +17 -0
- package/dist/core/create_git_host/shared.js.map +1 -0
- package/dist/core/create_git_host/working_tree_methods.d.ts +5 -0
- package/dist/core/create_git_host/working_tree_methods.d.ts.map +1 -0
- package/dist/core/create_git_host/working_tree_methods.js +63 -0
- package/dist/core/create_git_host/working_tree_methods.js.map +1 -0
- package/dist/core/create_git_host.d.ts +4 -0
- package/dist/core/create_git_host.d.ts.map +1 -0
- package/dist/core/create_git_host.js +167 -0
- package/dist/core/create_git_host.js.map +1 -0
- package/dist/core/inspect/helpers.d.ts +27 -0
- package/dist/core/inspect/helpers.d.ts.map +1 -0
- package/dist/core/inspect/helpers.js +86 -0
- package/dist/core/inspect/helpers.js.map +1 -0
- package/dist/core/inspect.d.ts +17 -0
- package/dist/core/inspect.d.ts.map +1 -0
- package/dist/core/inspect.js +174 -0
- package/dist/core/inspect.js.map +1 -0
- package/dist/core/locks.d.ts +5 -0
- package/dist/core/locks.d.ts.map +1 -0
- package/dist/core/locks.js +27 -0
- package/dist/core/locks.js.map +1 -0
- package/dist/core/operation_state.d.ts +4 -0
- package/dist/core/operation_state.d.ts.map +1 -0
- package/dist/core/operation_state.js +51 -0
- package/dist/core/operation_state.js.map +1 -0
- package/dist/core/remote.d.ts +13 -0
- package/dist/core/remote.d.ts.map +1 -0
- package/dist/core/remote.js +187 -0
- package/dist/core/remote.js.map +1 -0
- package/dist/core/repository/parsers.d.ts +12 -0
- package/dist/core/repository/parsers.d.ts.map +1 -0
- package/dist/core/repository/parsers.js +181 -0
- package/dist/core/repository/parsers.js.map +1 -0
- package/dist/core/repository.d.ts +11 -0
- package/dist/core/repository.d.ts.map +1 -0
- package/dist/core/repository.js +81 -0
- package/dist/core/repository.js.map +1 -0
- package/dist/core/run_git/env.d.ts +7 -0
- package/dist/core/run_git/env.d.ts.map +1 -0
- package/dist/core/run_git/env.js +18 -0
- package/dist/core/run_git/env.js.map +1 -0
- package/dist/core/run_git/process.d.ts +13 -0
- package/dist/core/run_git/process.d.ts.map +1 -0
- package/dist/core/run_git/process.js +96 -0
- package/dist/core/run_git/process.js.map +1 -0
- package/dist/core/run_git/repository_setup.d.ts +20 -0
- package/dist/core/run_git/repository_setup.d.ts.map +1 -0
- package/dist/core/run_git/repository_setup.js +116 -0
- package/dist/core/run_git/repository_setup.js.map +1 -0
- package/dist/core/run_git.d.ts +6 -0
- package/dist/core/run_git.d.ts.map +1 -0
- package/dist/core/run_git.js +6 -0
- package/dist/core/run_git.js.map +1 -0
- package/dist/core/working_tree/mutate.d.ts +9 -0
- package/dist/core/working_tree/mutate.d.ts.map +1 -0
- package/dist/core/working_tree/mutate.js +159 -0
- package/dist/core/working_tree/mutate.js.map +1 -0
- package/dist/core/working_tree/read.d.ts +6 -0
- package/dist/core/working_tree/read.d.ts.map +1 -0
- package/dist/core/working_tree/read.js +108 -0
- package/dist/core/working_tree/read.js.map +1 -0
- package/dist/core/working_tree/shared.d.ts +20 -0
- package/dist/core/working_tree/shared.d.ts.map +1 -0
- package/dist/core/working_tree/shared.js +87 -0
- package/dist/core/working_tree/shared.js.map +1 -0
- package/dist/core/working_tree.d.ts +3 -0
- package/dist/core/working_tree.d.ts.map +1 -0
- package/dist/core/working_tree.js +3 -0
- package/dist/core/working_tree.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/http/handler/helpers.d.ts +35 -0
- package/dist/http/handler/helpers.d.ts.map +1 -0
- package/dist/http/handler/helpers.js +146 -0
- package/dist/http/handler/helpers.js.map +1 -0
- package/dist/http/handler.d.ts +6 -0
- package/dist/http/handler.d.ts.map +1 -0
- package/dist/http/handler.js +208 -0
- package/dist/http/handler.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/logging.d.ts +4 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +134 -0
- package/dist/logging.js.map +1 -0
- package/dist/react/client/error.d.ts +14 -0
- package/dist/react/client/error.d.ts.map +1 -0
- package/dist/react/client/error.js +32 -0
- package/dist/react/client/error.js.map +1 -0
- package/dist/react/client/helpers.d.ts +12 -0
- package/dist/react/client/helpers.d.ts.map +1 -0
- package/dist/react/client/helpers.js +45 -0
- package/dist/react/client/helpers.js.map +1 -0
- package/dist/react/client/types.d.ts +61 -0
- package/dist/react/client/types.d.ts.map +1 -0
- package/dist/react/client/types.js +2 -0
- package/dist/react/client/types.js.map +1 -0
- package/dist/react/client.d.ts +6 -0
- package/dist/react/client.d.ts.map +1 -0
- package/dist/react/client.js +115 -0
- package/dist/react/client.js.map +1 -0
- package/dist/react/hooks/query.d.ts +10 -0
- package/dist/react/hooks/query.d.ts.map +1 -0
- package/dist/react/hooks/query.js +74 -0
- package/dist/react/hooks/query.js.map +1 -0
- package/dist/react/hooks/resources.d.ts +11 -0
- package/dist/react/hooks/resources.d.ts.map +1 -0
- package/dist/react/hooks/resources.js +113 -0
- package/dist/react/hooks/resources.js.map +1 -0
- package/dist/react/hooks/types.d.ts +40 -0
- package/dist/react/hooks/types.d.ts.map +1 -0
- package/dist/react/hooks/types.js +2 -0
- package/dist/react/hooks/types.js.map +1 -0
- package/dist/react/hooks.d.ts +4 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +3 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -0
- package/dist/ssh/keys.d.ts +18 -0
- package/dist/ssh/keys.d.ts.map +1 -0
- package/dist/ssh/keys.js +41 -0
- package/dist/ssh/keys.js.map +1 -0
- package/dist/ssh/server/audit.d.ts +5 -0
- package/dist/ssh/server/audit.d.ts.map +1 -0
- package/dist/ssh/server/audit.js +21 -0
- package/dist/ssh/server/audit.js.map +1 -0
- package/dist/ssh/server/shared.d.ts +30 -0
- package/dist/ssh/server/shared.d.ts.map +1 -0
- package/dist/ssh/server/shared.js +93 -0
- package/dist/ssh/server/shared.js.map +1 -0
- package/dist/ssh/server.d.ts +5 -0
- package/dist/ssh/server.d.ts.map +1 -0
- package/dist/ssh/server.js +265 -0
- package/dist/ssh/server.js.map +1 -0
- package/dist/types/common.d.ts +32 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +2 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/host.d.ts +142 -0
- package/dist/types/host.d.ts.map +1 -0
- package/dist/types/host.js +2 -0
- package/dist/types/host.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/repository.d.ts +163 -0
- package/dist/types/repository.d.ts.map +1 -0
- package/dist/types/repository.js +2 -0
- package/dist/types/repository.js.map +1 -0
- package/dist/types/transports.d.ts +156 -0
- package/dist/types/transports.d.ts.map +1 -0
- package/dist/types/transports.js +2 -0
- package/dist/types/transports.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/paths.d.ts +10 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +51 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/text.d.ts +4 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +10 -0
- package/dist/utils/text.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/core/run_git/env.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,iBAAS,WAAW,CAAC,OAAO,GAAE;IAC5B,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc9B;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DEFAULT_ACTOR_EMAIL, DEFAULT_ACTOR_NAME, } from "../../constants.js";
|
|
2
|
+
import { text } from "../../utils/text.js";
|
|
3
|
+
function buildGitEnv(options = {}) {
|
|
4
|
+
const actor = options.actor || null;
|
|
5
|
+
const extraEnv = options.extraEnv || {};
|
|
6
|
+
const name = text(actor && actor.name, DEFAULT_ACTOR_NAME);
|
|
7
|
+
const email = text(actor && actor.email, DEFAULT_ACTOR_EMAIL);
|
|
8
|
+
return {
|
|
9
|
+
...process.env,
|
|
10
|
+
...extraEnv,
|
|
11
|
+
GIT_AUTHOR_EMAIL: email,
|
|
12
|
+
GIT_AUTHOR_NAME: name,
|
|
13
|
+
GIT_COMMITTER_EMAIL: email,
|
|
14
|
+
GIT_COMMITTER_NAME: name,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export { buildGitEnv };
|
|
18
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/core/run_git/env.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,SAAS,WAAW,CAAC,UAGjB,EAAE;IACJ,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC;IACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;IAE9D,OAAO;QACL,GAAG,OAAO,CAAC,GAAG;QACd,GAAG,QAAQ;QACX,gBAAgB,EAAE,KAAK;QACvB,eAAe,EAAE,IAAI;QACrB,mBAAmB,EAAE,KAAK;QAC1B,kBAAkB,EAAE,IAAI;KACC,CAAC;AAC9B,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GitCommandBufferResult, GitCommandResult } from "../../types.js";
|
|
2
|
+
declare function runGit(args: string[], options: {
|
|
3
|
+
cwd: string;
|
|
4
|
+
env?: Record<string, string>;
|
|
5
|
+
stdinText?: string;
|
|
6
|
+
}): Promise<GitCommandResult>;
|
|
7
|
+
declare function runGitBuffer(args: string[], options: {
|
|
8
|
+
cwd: string;
|
|
9
|
+
env?: Record<string, string>;
|
|
10
|
+
stdin?: Buffer;
|
|
11
|
+
}): Promise<GitCommandBufferResult>;
|
|
12
|
+
export { runGit, runGitBuffer };
|
|
13
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../../src/core/run_git/process.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG/E,iBAAe,MAAM,CACnB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE;IACP,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GACA,OAAO,CAAC,gBAAgB,CAAC,CA+C3B;AAED,iBAAe,YAAY,CACzB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE;IACP,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GACA,OAAO,CAAC,sBAAsB,CAAC,CA+CjC;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { text } from "../../utils/text.js";
|
|
3
|
+
async function runGit(args, options) {
|
|
4
|
+
const cwd = text(options.cwd);
|
|
5
|
+
const env = options.env;
|
|
6
|
+
const stdinText = typeof options.stdinText === "string" ? options.stdinText : "";
|
|
7
|
+
return await new Promise((resolve) => {
|
|
8
|
+
let stdout = "";
|
|
9
|
+
let stderr = "";
|
|
10
|
+
let child;
|
|
11
|
+
try {
|
|
12
|
+
child = spawn("git", Array.isArray(args) ? args : [], {
|
|
13
|
+
cwd,
|
|
14
|
+
env,
|
|
15
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
resolve({
|
|
20
|
+
code: -1,
|
|
21
|
+
ok: false,
|
|
22
|
+
stderr: error && error.message ? String(error.message) : "Failed to start git.",
|
|
23
|
+
stdout: "",
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
child.stdout.on("data", (chunk) => {
|
|
28
|
+
stdout += String(chunk);
|
|
29
|
+
});
|
|
30
|
+
child.stderr.on("data", (chunk) => {
|
|
31
|
+
stderr += String(chunk);
|
|
32
|
+
});
|
|
33
|
+
child.on("error", (error) => {
|
|
34
|
+
stderr += error && error.message ? String(error.message) : "Git command failed.";
|
|
35
|
+
});
|
|
36
|
+
child.on("close", (code) => {
|
|
37
|
+
resolve({
|
|
38
|
+
code: Number(code) || 0,
|
|
39
|
+
ok: Number(code) === 0,
|
|
40
|
+
stderr,
|
|
41
|
+
stdout,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
if (stdinText)
|
|
45
|
+
child.stdin.write(stdinText);
|
|
46
|
+
child.stdin.end();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async function runGitBuffer(args, options) {
|
|
50
|
+
const cwd = text(options.cwd);
|
|
51
|
+
const env = options.env;
|
|
52
|
+
const stdin = Buffer.isBuffer(options.stdin) ? options.stdin : null;
|
|
53
|
+
return await new Promise((resolve) => {
|
|
54
|
+
const stdoutChunks = [];
|
|
55
|
+
let stderr = "";
|
|
56
|
+
let child;
|
|
57
|
+
try {
|
|
58
|
+
child = spawn("git", Array.isArray(args) ? args : [], {
|
|
59
|
+
cwd,
|
|
60
|
+
env,
|
|
61
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
resolve({
|
|
66
|
+
code: -1,
|
|
67
|
+
ok: false,
|
|
68
|
+
stderr: error && error.message ? String(error.message) : "Failed to start git.",
|
|
69
|
+
stdout: Buffer.alloc(0),
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
child.stdout.on("data", (chunk) => {
|
|
74
|
+
stdoutChunks.push(Buffer.from(chunk));
|
|
75
|
+
});
|
|
76
|
+
child.stderr.on("data", (chunk) => {
|
|
77
|
+
stderr += String(chunk);
|
|
78
|
+
});
|
|
79
|
+
child.on("error", (error) => {
|
|
80
|
+
stderr += error && error.message ? String(error.message) : "Git command failed.";
|
|
81
|
+
});
|
|
82
|
+
child.on("close", (code) => {
|
|
83
|
+
resolve({
|
|
84
|
+
code: Number(code) || 0,
|
|
85
|
+
ok: Number(code) === 0,
|
|
86
|
+
stderr,
|
|
87
|
+
stdout: Buffer.concat(stdoutChunks),
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
if (stdin)
|
|
91
|
+
child.stdin.write(stdin);
|
|
92
|
+
child.stdin.end();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export { runGit, runGitBuffer };
|
|
96
|
+
//# sourceMappingURL=process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AK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC;QACnF,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,OAAO,CAAC;gBACN,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;gBACvB,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;gBACtB,MAAM;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;aACpC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,KAAK;YAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GitActor, GitCommandResult } from "../../types.js";
|
|
2
|
+
declare function repositoryExists(workspaceRoot: string): Promise<boolean>;
|
|
3
|
+
declare function isDirectoryEmpty(dirPath: string): boolean;
|
|
4
|
+
declare function workspaceHasTrackableFiles(workspaceRoot: string): boolean;
|
|
5
|
+
declare function initRepository(workspaceRoot: string, initialBranch?: string): Promise<GitCommandResult>;
|
|
6
|
+
declare function ensureHostedRepositoryConfig(workspaceRoot: string): Promise<GitCommandResult>;
|
|
7
|
+
declare function ensureManagedExcludeFile(workspaceRoot: string, options?: {
|
|
8
|
+
header?: string;
|
|
9
|
+
patterns?: string[];
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
declare function createInitialCommit(workspaceRoot: string, actor: GitActor | null, message?: string): Promise<GitCommandResult>;
|
|
12
|
+
declare function cloneRepository(input: {
|
|
13
|
+
cloneUrl: string;
|
|
14
|
+
remoteUrl?: string;
|
|
15
|
+
workspaceRoot: string;
|
|
16
|
+
args?: string[];
|
|
17
|
+
env?: Record<string, string>;
|
|
18
|
+
}): Promise<GitCommandResult>;
|
|
19
|
+
export { cloneRepository, createInitialCommit, ensureHostedRepositoryConfig, ensureManagedExcludeFile, initRepository, isDirectoryEmpty, repositoryExists, workspaceHasTrackableFiles, };
|
|
20
|
+
//# sourceMappingURL=repository_setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository_setup.d.ts","sourceRoot":"","sources":["../../../src/core/run_git/repository_setup.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKjE,iBAAe,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAIvE;AAED,iBAAS,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAMlD;AAED,iBAAS,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAMlE;AAED,iBAAe,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,SAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAS9G;AAED,iBAAe,4BAA4B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAW5F;AAED,iBAAe,wBAAwB,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,iBA0BpH;AAED,iBAAe,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,OAAO,SAAyB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAiB7I;AAED,iBAAe,eAAe,CAAC,KAAK,EAAE;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgB5B;AAED,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,GAC3B,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DEFAULT_BRANCH, DEFAULT_COMMIT_MESSAGE, DEFAULT_MANAGED_EXCLUDE_HEADER, DEFAULT_MANAGED_EXCLUDE_PATTERNS, } from "../../constants.js";
|
|
4
|
+
import { text } from "../../utils/text.js";
|
|
5
|
+
import { buildGitEnv } from "./env.js";
|
|
6
|
+
import { runGit } from "./process.js";
|
|
7
|
+
async function repositoryExists(workspaceRoot) {
|
|
8
|
+
if (!fs.existsSync(workspaceRoot))
|
|
9
|
+
return false;
|
|
10
|
+
const probe = await runGit(["rev-parse", "--git-dir"], { cwd: workspaceRoot });
|
|
11
|
+
return probe.ok && Boolean(text(probe.stdout));
|
|
12
|
+
}
|
|
13
|
+
function isDirectoryEmpty(dirPath) {
|
|
14
|
+
try {
|
|
15
|
+
return fs.readdirSync(dirPath).length === 0;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function workspaceHasTrackableFiles(workspaceRoot) {
|
|
22
|
+
try {
|
|
23
|
+
return fs.readdirSync(workspaceRoot).some((entry) => entry && entry !== ".git");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function initRepository(workspaceRoot, initialBranch = DEFAULT_BRANCH) {
|
|
30
|
+
let initRes = await runGit(["init", "--initial-branch", text(initialBranch, DEFAULT_BRANCH)], { cwd: workspaceRoot });
|
|
31
|
+
if (!initRes.ok) {
|
|
32
|
+
initRes = await runGit(["init"], { cwd: workspaceRoot });
|
|
33
|
+
if (!initRes.ok)
|
|
34
|
+
return initRes;
|
|
35
|
+
const branchRes = await runGit(["symbolic-ref", "HEAD", `refs/heads/${text(initialBranch, DEFAULT_BRANCH)}`], { cwd: workspaceRoot });
|
|
36
|
+
if (!branchRes.ok)
|
|
37
|
+
return branchRes;
|
|
38
|
+
}
|
|
39
|
+
return initRes;
|
|
40
|
+
}
|
|
41
|
+
async function ensureHostedRepositoryConfig(workspaceRoot) {
|
|
42
|
+
for (const args of [
|
|
43
|
+
["config", "receive.denyCurrentBranch", "updateInstead"],
|
|
44
|
+
["config", "http.receivepack", "true"],
|
|
45
|
+
["config", "http.uploadpack", "true"],
|
|
46
|
+
]) {
|
|
47
|
+
const res = await runGit(args, { cwd: workspaceRoot });
|
|
48
|
+
if (!res.ok)
|
|
49
|
+
return res;
|
|
50
|
+
}
|
|
51
|
+
return { code: 0, ok: true, stderr: "", stdout: "" };
|
|
52
|
+
}
|
|
53
|
+
async function ensureManagedExcludeFile(workspaceRoot, options = {}) {
|
|
54
|
+
const header = text(options.header, DEFAULT_MANAGED_EXCLUDE_HEADER);
|
|
55
|
+
const patterns = Array.isArray(options.patterns) && options.patterns.length
|
|
56
|
+
? options.patterns.map((entry) => text(entry)).filter(Boolean)
|
|
57
|
+
: Array.from(DEFAULT_MANAGED_EXCLUDE_PATTERNS);
|
|
58
|
+
const infoDir = path.join(workspaceRoot, ".git", "info");
|
|
59
|
+
const excludePath = path.join(infoDir, "exclude");
|
|
60
|
+
fs.mkdirSync(infoDir, { recursive: true });
|
|
61
|
+
let current = "";
|
|
62
|
+
try {
|
|
63
|
+
current = fs.readFileSync(excludePath, "utf8");
|
|
64
|
+
}
|
|
65
|
+
catch { }
|
|
66
|
+
const lines = current ? current.split(/\r?\n/) : [];
|
|
67
|
+
const next = lines.slice();
|
|
68
|
+
if (!lines.some((line) => line.trim() === header)) {
|
|
69
|
+
if (next.length && next[next.length - 1].trim())
|
|
70
|
+
next.push("");
|
|
71
|
+
next.push(header);
|
|
72
|
+
}
|
|
73
|
+
for (const pattern of patterns) {
|
|
74
|
+
if (!next.some((line) => line.trim() === pattern))
|
|
75
|
+
next.push(pattern);
|
|
76
|
+
}
|
|
77
|
+
fs.writeFileSync(excludePath, `${next.join("\n").replace(/\n+$/g, "")}\n`, "utf8");
|
|
78
|
+
}
|
|
79
|
+
async function createInitialCommit(workspaceRoot, actor, message = DEFAULT_COMMIT_MESSAGE) {
|
|
80
|
+
const addRes = await runGit(["add", "-A"], {
|
|
81
|
+
cwd: workspaceRoot,
|
|
82
|
+
env: buildGitEnv({ actor }),
|
|
83
|
+
});
|
|
84
|
+
if (!addRes.ok)
|
|
85
|
+
return addRes;
|
|
86
|
+
const statusRes = await runGit(["status", "--porcelain=v1", "--branch"], { cwd: workspaceRoot });
|
|
87
|
+
if (!statusRes.ok)
|
|
88
|
+
return statusRes;
|
|
89
|
+
const clean = statusRes.stdout.split(/\r?\n/).slice(1).map((line) => line.trim()).filter(Boolean).length === 0;
|
|
90
|
+
if (clean)
|
|
91
|
+
return { code: 0, ok: true, stderr: "", stdout: "" };
|
|
92
|
+
return await runGit(["commit", "-m", text(message, DEFAULT_COMMIT_MESSAGE)], {
|
|
93
|
+
cwd: workspaceRoot,
|
|
94
|
+
env: buildGitEnv({ actor }),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async function cloneRepository(input) {
|
|
98
|
+
const cloneUrl = text(input.cloneUrl);
|
|
99
|
+
const remoteUrl = text(input.remoteUrl) || cloneUrl;
|
|
100
|
+
const workspaceRoot = text(input.workspaceRoot);
|
|
101
|
+
const args = Array.isArray(input.args) ? input.args : [];
|
|
102
|
+
const cloneRes = await runGit([...args, "clone", "--origin", "origin", cloneUrl, workspaceRoot], {
|
|
103
|
+
cwd: path.dirname(workspaceRoot),
|
|
104
|
+
env: input.env,
|
|
105
|
+
});
|
|
106
|
+
if (!cloneRes.ok)
|
|
107
|
+
return cloneRes;
|
|
108
|
+
if (remoteUrl && remoteUrl !== cloneUrl) {
|
|
109
|
+
const remoteRes = await runGit(["remote", "set-url", "origin", remoteUrl], { cwd: workspaceRoot });
|
|
110
|
+
if (!remoteRes.ok)
|
|
111
|
+
return remoteRes;
|
|
112
|
+
}
|
|
113
|
+
return cloneRes;
|
|
114
|
+
}
|
|
115
|
+
export { cloneRepository, createInitialCommit, ensureHostedRepositoryConfig, ensureManagedExcludeFile, initRepository, isDirectoryEmpty, repositoryExists, workspaceHasTrackableFiles, };
|
|
116
|
+
//# sourceMappingURL=repository_setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository_setup.js","sourceRoot":"","sources":["../../../src/core/run_git/repository_setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,8BAA8B,EAC9B,gCAAgC,GACjC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,KAAK,UAAU,gBAAgB,CAAC,aAAqB;IACnD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;IAC/E,OAAO,KAAK,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,gBA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AC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAEzD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE;QAC/F,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;QAChC,GAAG,EAAE,KAAK,CAAC,GAAG;KACf,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,OAAO,QAAQ,CAAC;IAClC,IAAI,SAAS,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;QACnG,IAAI,CAAC,SAAS,CAAC,EAAE;YAAE,OAAO,SAAS,CAAC;IACtC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,GAC3B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_BRANCH, DEFAULT_COMMIT_MESSAGE } from "../constants.js";
|
|
2
|
+
import { buildGitEnv } from "./run_git/env.js";
|
|
3
|
+
import { runGit, runGitBuffer } from "./run_git/process.js";
|
|
4
|
+
import { cloneRepository, createInitialCommit, ensureHostedRepositoryConfig, ensureManagedExcludeFile, initRepository, isDirectoryEmpty, repositoryExists, workspaceHasTrackableFiles } from "./run_git/repository_setup.js";
|
|
5
|
+
export { buildGitEnv, cloneRepository, createInitialCommit, DEFAULT_BRANCH, DEFAULT_COMMIT_MESSAGE, ensureHostedRepositoryConfig, ensureManagedExcludeFile, initRepository, isDirectoryEmpty, repositoryExists, runGit, runGitBuffer, workspaceHasTrackableFiles, };
|
|
6
|
+
//# sourceMappingURL=run_git.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run_git.d.ts","sourceRoot":"","sources":["../../src/core/run_git.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,0BAA0B,GAC3B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_BRANCH, DEFAULT_COMMIT_MESSAGE, } from "../constants.js";
|
|
2
|
+
import { buildGitEnv } from "./run_git/env.js";
|
|
3
|
+
import { runGit, runGitBuffer } from "./run_git/process.js";
|
|
4
|
+
import { cloneRepository, createInitialCommit, ensureHostedRepositoryConfig, ensureManagedExcludeFile, initRepository, isDirectoryEmpty, repositoryExists, workspaceHasTrackableFiles, } from "./run_git/repository_setup.js";
|
|
5
|
+
export { buildGitEnv, cloneRepository, createInitialCommit, DEFAULT_BRANCH, DEFAULT_COMMIT_MESSAGE, ensureHostedRepositoryConfig, ensureManagedExcludeFile, initRepository, isDirectoryEmpty, repositoryExists, runGit, runGitBuffer, workspaceHasTrackableFiles, };
|
|
6
|
+
//# sourceMappingURL=run_git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run_git.js","sourceRoot":"","sources":["../../src/core/run_git.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,0BAA0B,GAC3B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CommitInput, ContinueOperationInput, DiscardPathsInput, GitRepositoryHandle, StagePathsInput, UnstagePathsInput } from "../../types.js";
|
|
2
|
+
declare function stageRepositoryPaths(repository: GitRepositoryHandle, input?: StagePathsInput): Promise<void>;
|
|
3
|
+
declare function unstageRepositoryPaths(repository: GitRepositoryHandle, input?: UnstagePathsInput): Promise<void>;
|
|
4
|
+
declare function discardRepositoryPaths(repository: GitRepositoryHandle, input?: DiscardPathsInput): Promise<void>;
|
|
5
|
+
declare function commitRepository(repository: GitRepositoryHandle, input: CommitInput): Promise<void>;
|
|
6
|
+
declare function continueRepositoryOperation(repository: GitRepositoryHandle, input?: ContinueOperationInput): Promise<void>;
|
|
7
|
+
declare function abortRepositoryOperation(repository: GitRepositoryHandle): Promise<void>;
|
|
8
|
+
export { abortRepositoryOperation, commitRepository, continueRepositoryOperation, discardRepositoryPaths, stageRepositoryPaths, unstageRepositoryPaths, };
|
|
9
|
+
//# sourceMappingURL=mutate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutate.d.ts","sourceRoot":"","sources":["../../../src/core/working_tree/mutate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAOxB,iBAAe,oBAAoB,CAAC,UAAU,EAAE,mBAAmB,EAAE,KAAK,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAY/G;AAED,iBAAe,sBAAsB,CAAC,UAAU,EAAE,mBAAmB,EAAE,KAAK,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAcnH;AAED,iBAAe,sBAAsB,CAAC,UAAU,EAAE,mBAAmB,EAAE,KAAK,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BnH;AAED,iBAAe,gBAAgB,CAAC,UAAU,EAAE,mBAAmB,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BlG;AAED,iBAAe,2BAA2B,CAAC,UAAU,EAAE,mBAAmB,EAAE,KAAK,GAAE,sBAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAuC7H;AAED,iBAAe,wBAAwB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BtF;AAED,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,GACvB,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { GitHostError } from "../../errors.js";
|
|
2
|
+
import { isTruthy, text } from "../../utils/text.js";
|
|
3
|
+
import { readRepositoryOperationState } from "../operation_state.js";
|
|
4
|
+
import { readRepositoryStatus } from "../repository.js";
|
|
5
|
+
import { buildGitEnv, runGit } from "../run_git.js";
|
|
6
|
+
import { assertRepositoryReady, normalizePathList, repositoryHasHead } from "./shared.js";
|
|
7
|
+
async function stageRepositoryPaths(repository, input = {}) {
|
|
8
|
+
await assertRepositoryReady(repository);
|
|
9
|
+
const paths = normalizePathList(input && input.paths);
|
|
10
|
+
const addRes = await runGit(paths.length ? ["add", "--", ...paths] : ["add", "-A"], {
|
|
11
|
+
cwd: repository.path,
|
|
12
|
+
});
|
|
13
|
+
if (!addRes.ok) {
|
|
14
|
+
throw new GitHostError("git_command_failed", text(addRes.stderr, "Failed to stage repository changes."), {
|
|
15
|
+
repositoryId: repository.id,
|
|
16
|
+
paths,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function unstageRepositoryPaths(repository, input = {}) {
|
|
21
|
+
await assertRepositoryReady(repository);
|
|
22
|
+
const paths = normalizePathList(input && input.paths);
|
|
23
|
+
const hasHead = await repositoryHasHead(repository.path);
|
|
24
|
+
const args = hasHead
|
|
25
|
+
? (paths.length ? ["restore", "--staged", "--", ...paths] : ["restore", "--staged", "--", "."])
|
|
26
|
+
: (paths.length ? ["rm", "-r", "--cached", "--ignore-unmatch", "--", ...paths] : ["rm", "-r", "--cached", "--ignore-unmatch", "."]);
|
|
27
|
+
const unstageRes = await runGit(args, { cwd: repository.path });
|
|
28
|
+
if (!unstageRes.ok) {
|
|
29
|
+
throw new GitHostError("git_command_failed", text(unstageRes.stderr, "Failed to unstage repository changes."), {
|
|
30
|
+
repositoryId: repository.id,
|
|
31
|
+
paths,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function discardRepositoryPaths(repository, input = {}) {
|
|
36
|
+
await assertRepositoryReady(repository);
|
|
37
|
+
const paths = normalizePathList(input && input.paths);
|
|
38
|
+
const hasHead = await repositoryHasHead(repository.path);
|
|
39
|
+
const removeUntracked = isTruthy(input && input.removeUntracked);
|
|
40
|
+
if (hasHead) {
|
|
41
|
+
const restoreArgs = paths.length
|
|
42
|
+
? ["restore", "--staged", "--worktree", "--source=HEAD", "--", ...paths]
|
|
43
|
+
: ["restore", "--staged", "--worktree", "--source=HEAD", "--", "."];
|
|
44
|
+
const restoreRes = await runGit(restoreArgs, { cwd: repository.path });
|
|
45
|
+
if (!restoreRes.ok) {
|
|
46
|
+
throw new GitHostError("git_command_failed", text(restoreRes.stderr, "Failed to discard repository changes."), {
|
|
47
|
+
repositoryId: repository.id,
|
|
48
|
+
paths,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (removeUntracked || !hasHead) {
|
|
53
|
+
const cleanArgs = paths.length ? ["clean", "-fd", "--", ...paths] : ["clean", "-fd"];
|
|
54
|
+
const cleanRes = await runGit(cleanArgs, { cwd: repository.path });
|
|
55
|
+
if (!cleanRes.ok) {
|
|
56
|
+
throw new GitHostError("git_command_failed", text(cleanRes.stderr, "Failed to remove untracked files."), {
|
|
57
|
+
repositoryId: repository.id,
|
|
58
|
+
paths,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function commitRepository(repository, input) {
|
|
64
|
+
await assertRepositoryReady(repository);
|
|
65
|
+
const message = text(input && input.message);
|
|
66
|
+
if (!message) {
|
|
67
|
+
throw new GitHostError("git_command_failed", "Commit message is required.", {
|
|
68
|
+
repositoryId: repository.id,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const status = await readRepositoryStatus(repository.path);
|
|
72
|
+
if (status.clean) {
|
|
73
|
+
throw new GitHostError("git_command_failed", "No repository changes to commit.", {
|
|
74
|
+
repositoryId: repository.id,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (!Number(status.staged)) {
|
|
78
|
+
throw new GitHostError("git_command_failed", "Stage changes before creating a commit.", {
|
|
79
|
+
repositoryId: repository.id,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const commitRes = await runGit(["commit", "-m", message], {
|
|
83
|
+
cwd: repository.path,
|
|
84
|
+
env: buildGitEnv({ actor: input && input.actor ? input.actor : null }),
|
|
85
|
+
});
|
|
86
|
+
if (!commitRes.ok) {
|
|
87
|
+
throw new GitHostError("git_command_failed", text(commitRes.stderr, "Failed to create repository commit."), {
|
|
88
|
+
repositoryId: repository.id,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function continueRepositoryOperation(repository, input = {}) {
|
|
93
|
+
await assertRepositoryReady(repository);
|
|
94
|
+
const operation = readRepositoryOperationState(repository.path);
|
|
95
|
+
if (!operation.in_progress) {
|
|
96
|
+
throw new GitHostError("git_command_failed", "No repository operation is in progress.", {
|
|
97
|
+
repositoryId: repository.id,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const commands = {
|
|
101
|
+
merge: ["commit", "--no-edit"],
|
|
102
|
+
rebase: ["rebase", "--continue"],
|
|
103
|
+
"cherry-pick": ["cherry-pick", "--continue"],
|
|
104
|
+
revert: ["revert", "--continue"],
|
|
105
|
+
};
|
|
106
|
+
const args = commands[operation.kind] || [];
|
|
107
|
+
if (!args.length) {
|
|
108
|
+
throw new GitHostError("git_command_failed", "That repository operation cannot be continued.", {
|
|
109
|
+
repositoryId: repository.id,
|
|
110
|
+
operation: operation.kind,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const continueRes = await runGit(args, {
|
|
114
|
+
cwd: repository.path,
|
|
115
|
+
env: buildGitEnv({
|
|
116
|
+
actor: input && input.actor ? input.actor : null,
|
|
117
|
+
extraEnv: {
|
|
118
|
+
GIT_EDITOR: "true",
|
|
119
|
+
},
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
if (!continueRes.ok) {
|
|
123
|
+
throw new GitHostError("git_command_failed", text(continueRes.stderr, "Failed to continue repository operation."), {
|
|
124
|
+
repositoryId: repository.id,
|
|
125
|
+
operation: operation.kind,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function abortRepositoryOperation(repository) {
|
|
130
|
+
await assertRepositoryReady(repository);
|
|
131
|
+
const operation = readRepositoryOperationState(repository.path);
|
|
132
|
+
if (!operation.in_progress) {
|
|
133
|
+
throw new GitHostError("git_command_failed", "No repository operation is in progress.", {
|
|
134
|
+
repositoryId: repository.id,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const commands = {
|
|
138
|
+
merge: ["merge", "--abort"],
|
|
139
|
+
rebase: ["rebase", "--abort"],
|
|
140
|
+
"cherry-pick": ["cherry-pick", "--abort"],
|
|
141
|
+
revert: ["revert", "--abort"],
|
|
142
|
+
};
|
|
143
|
+
const args = commands[operation.kind] || [];
|
|
144
|
+
if (!args.length) {
|
|
145
|
+
throw new GitHostError("git_command_failed", "That repository operation cannot be aborted.", {
|
|
146
|
+
repositoryId: repository.id,
|
|
147
|
+
operation: operation.kind,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const abortRes = await runGit(args, { cwd: repository.path });
|
|
151
|
+
if (!abortRes.ok) {
|
|
152
|
+
throw new GitHostError("git_command_failed", text(abortRes.stderr, "Failed to abort repository operation."), {
|
|
153
|
+
repositoryId: repository.id,
|
|
154
|
+
operation: operation.kind,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export { abortRepositoryOperation, commitRepository, continueRepositoryOperation, discardRepositoryPaths, stageRepositoryPaths, unstageRepositoryPaths, };
|
|
159
|
+
//# sourceMappingURL=mutate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutate.js","sourceRoot":"","sources":["../../../src/core/working_tree/mutate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS/C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,o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AC;IACL,CAAC;AACH,CAAC;AAED,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,GACvB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GitFileContent, GitRepositoryHandle, GitWorkingTree, ReadWorkingTreeFileOptions } from "../../types.js";
|
|
2
|
+
declare function readRepositoryWorkingTree(repository: GitRepositoryHandle): Promise<GitWorkingTree>;
|
|
3
|
+
declare function readRepositoryStagedFile(repository: GitRepositoryHandle, options: ReadWorkingTreeFileOptions): Promise<GitFileContent>;
|
|
4
|
+
declare function readRepositoryUnstagedFile(repository: GitRepositoryHandle, options: ReadWorkingTreeFileOptions): Promise<GitFileContent>;
|
|
5
|
+
export { readRepositoryStagedFile, readRepositoryUnstagedFile, readRepositoryWorkingTree };
|
|
6
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/working_tree/read.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAatH,iBAAe,yBAAyB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC,CA0DjG;AAED,iBAAe,wBAAwB,CACrC,UAAU,EAAE,mBAAmB,EAC/B,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,CAwCzB;AAED,iBAAe,0BAA0B,CACvC,UAAU,EAAE,mBAAmB,EAC/B,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,CAYzB;AAED,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { GitHostError } from "../../errors.js";
|
|
2
|
+
import { text } from "../../utils/text.js";
|
|
3
|
+
import { readRepositoryStatus, parseNumstatOutput } from "../repository.js";
|
|
4
|
+
import { runGit, runGitBuffer } from "../run_git.js";
|
|
5
|
+
import { assertRepositoryReady, decodeFileContent, normalizeFilePath, readWorkingTreeFileBuffer, sumLines, withEntryStats, } from "./shared.js";
|
|
6
|
+
async function readRepositoryWorkingTree(repository) {
|
|
7
|
+
await assertRepositoryReady(repository);
|
|
8
|
+
const [status, stagedNumstatRes, unstagedNumstatRes, stagedDiffRes, unstagedDiffRes] = await Promise.all([
|
|
9
|
+
readRepositoryStatus(repository.path),
|
|
10
|
+
runGit(["diff", "--cached", "--find-renames", "--numstat"], { cwd: repository.path }),
|
|
11
|
+
runGit(["diff", "--find-renames", "--numstat"], { cwd: repository.path }),
|
|
12
|
+
runGit(["diff", "--cached", "--find-renames"], { cwd: repository.path }),
|
|
13
|
+
runGit(["diff", "--find-renames"], { cwd: repository.path }),
|
|
14
|
+
]);
|
|
15
|
+
if (!stagedNumstatRes.ok) {
|
|
16
|
+
throw new GitHostError("git_command_failed", text(stagedNumstatRes.stderr, "Failed to read staged repository changes."), {
|
|
17
|
+
repositoryId: repository.id,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (!unstagedNumstatRes.ok) {
|
|
21
|
+
throw new GitHostError("git_command_failed", text(unstagedNumstatRes.stderr, "Failed to read unstaged repository changes."), {
|
|
22
|
+
repositoryId: repository.id,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (!stagedDiffRes.ok) {
|
|
26
|
+
throw new GitHostError("git_command_failed", text(stagedDiffRes.stderr, "Failed to read staged repository diff."), {
|
|
27
|
+
repositoryId: repository.id,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!unstagedDiffRes.ok) {
|
|
31
|
+
throw new GitHostError("git_command_failed", text(unstagedDiffRes.stderr, "Failed to read unstaged repository diff."), {
|
|
32
|
+
repositoryId: repository.id,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const entries = withEntryStats(status.entries, parseNumstatOutput(stagedNumstatRes.stdout), parseNumstatOutput(unstagedNumstatRes.stdout));
|
|
36
|
+
const stagedEntries = entries.filter((entry) => entry.staged);
|
|
37
|
+
const unstagedEntries = entries.filter((entry) => entry.unstaged);
|
|
38
|
+
const untrackedEntries = entries.filter((entry) => entry.untracked);
|
|
39
|
+
const conflictedEntries = entries.filter((entry) => entry.conflicted);
|
|
40
|
+
const stagedTotals = sumLines(stagedEntries, "staged_lines_added", "staged_lines_removed");
|
|
41
|
+
const unstagedTotals = sumLines(unstagedEntries, "unstaged_lines_added", "unstaged_lines_removed");
|
|
42
|
+
return {
|
|
43
|
+
status,
|
|
44
|
+
entries,
|
|
45
|
+
staged_entries: stagedEntries,
|
|
46
|
+
unstaged_entries: unstagedEntries,
|
|
47
|
+
untracked_entries: untrackedEntries,
|
|
48
|
+
conflicted_entries: conflictedEntries,
|
|
49
|
+
staged_diff: String(stagedDiffRes.stdout || ""),
|
|
50
|
+
unstaged_diff: String(unstagedDiffRes.stdout || ""),
|
|
51
|
+
staged_lines_added: stagedTotals.lines_added,
|
|
52
|
+
staged_lines_removed: stagedTotals.lines_removed,
|
|
53
|
+
unstaged_lines_added: unstagedTotals.lines_added,
|
|
54
|
+
unstaged_lines_removed: unstagedTotals.lines_removed,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function readRepositoryStagedFile(repository, options) {
|
|
58
|
+
await assertRepositoryReady(repository);
|
|
59
|
+
const filePath = normalizeFilePath(options);
|
|
60
|
+
const objectSpec = `:${filePath}`;
|
|
61
|
+
const [revRes, sizeRes, contentRes] = await Promise.all([
|
|
62
|
+
runGit(["rev-parse", "--verify", objectSpec], { cwd: repository.path }),
|
|
63
|
+
runGit(["cat-file", "-s", objectSpec], { cwd: repository.path }),
|
|
64
|
+
runGitBuffer(["show", objectSpec], { cwd: repository.path }),
|
|
65
|
+
]);
|
|
66
|
+
if (!revRes.ok) {
|
|
67
|
+
throw new GitHostError("git_command_failed", text(revRes.stderr, "Staged file does not exist."), {
|
|
68
|
+
path: filePath,
|
|
69
|
+
repositoryId: repository.id,
|
|
70
|
+
source: "staged",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (!sizeRes.ok) {
|
|
74
|
+
throw new GitHostError("git_command_failed", text(sizeRes.stderr, "Failed to read staged file size."), {
|
|
75
|
+
path: filePath,
|
|
76
|
+
repositoryId: repository.id,
|
|
77
|
+
source: "staged",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (!contentRes.ok) {
|
|
81
|
+
throw new GitHostError("git_command_failed", text(contentRes.stderr, "Failed to read staged file content."), {
|
|
82
|
+
path: filePath,
|
|
83
|
+
repositoryId: repository.id,
|
|
84
|
+
source: "staged",
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
object: text(revRes.stdout),
|
|
89
|
+
path: filePath,
|
|
90
|
+
size: Number(text(sizeRes.stdout)) || 0,
|
|
91
|
+
source: "staged",
|
|
92
|
+
...decodeFileContent(contentRes.stdout),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function readRepositoryUnstagedFile(repository, options) {
|
|
96
|
+
await assertRepositoryReady(repository);
|
|
97
|
+
const filePath = normalizeFilePath(options);
|
|
98
|
+
const content = readWorkingTreeFileBuffer(repository, filePath);
|
|
99
|
+
return {
|
|
100
|
+
object: null,
|
|
101
|
+
path: filePath,
|
|
102
|
+
size: content.byteLength,
|
|
103
|
+
source: "unstaged",
|
|
104
|
+
...decodeFileContent(content),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export { readRepositoryStagedFile, readRepositoryUnstagedFile, readRepositoryWorkingTree };
|
|
108
|
+
//# sourceMappingURL=read.js.map
|