@leitwerk-dev/coding 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -13
- package/dist/chunk-3WJRJ3Q7.js +220 -0
- package/dist/chunk-3WJRJ3Q7.js.map +1 -0
- package/dist/chunk-ABQH2WZT.js +36 -0
- package/dist/chunk-ABQH2WZT.js.map +1 -0
- package/dist/chunk-B3PE6DPF.js +820 -0
- package/dist/chunk-B3PE6DPF.js.map +1 -0
- package/dist/chunk-DNG7D77K.js +65 -0
- package/dist/chunk-DNG7D77K.js.map +1 -0
- package/dist/chunk-E3DB4TIZ.js +49 -0
- package/dist/chunk-E3DB4TIZ.js.map +1 -0
- package/dist/chunk-L2TFD72B.js +16320 -0
- package/dist/chunk-L2TFD72B.js.map +1 -0
- package/dist/chunk-M2VTUPFO.js +265 -0
- package/dist/chunk-M2VTUPFO.js.map +1 -0
- package/dist/{chunk-YSC5GEQJ.js → chunk-QD6FI4HR.js} +7 -3
- package/dist/chunk-QD6FI4HR.js.map +1 -0
- package/dist/chunk-SKGB4CZS.js +14 -0
- package/dist/chunk-SKGB4CZS.js.map +1 -0
- package/dist/chunk-SZ4WOGV2.js +120 -0
- package/dist/chunk-SZ4WOGV2.js.map +1 -0
- package/dist/finalization-git-internal.d.ts +9 -0
- package/dist/finalization-git-internal.d.ts.map +1 -1
- package/dist/finalization-git.d.ts +1 -1
- package/dist/finalization-git.d.ts.map +1 -1
- package/dist/finalization-git.js +6 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -591
- package/dist/index.js.map +1 -1
- package/dist/pull-request-publication-internal.d.ts +34 -24
- package/dist/pull-request-publication-internal.d.ts.map +1 -1
- package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
- package/dist/repository-change-launch-internal.d.ts +32 -11
- package/dist/repository-change-launch-internal.d.ts.map +1 -1
- package/dist/repository-change-launch.d.ts +4 -3
- package/dist/repository-change-launch.d.ts.map +1 -1
- package/dist/repository-change-launch.js +162 -34
- package/dist/repository-change-launch.js.map +1 -1
- package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
- package/dist/repository-change-process.d.ts +30 -25
- package/dist/repository-change-process.d.ts.map +1 -1
- package/dist/repository-change-publication.d.ts +76 -7
- package/dist/repository-change-publication.d.ts.map +1 -1
- package/dist/repository-change-publication.js +624 -136
- package/dist/repository-change-publication.js.map +1 -1
- package/dist/repository-change-state-internal.d.ts +18 -4
- package/dist/repository-change-state-internal.d.ts.map +1 -1
- package/dist/repository-change-ui-launcher-internal.d.ts +34 -22
- package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -1
- package/dist/repository-publication-receipt.d.ts +23 -0
- package/dist/repository-publication-receipt.d.ts.map +1 -0
- package/dist/repository-rebase/git.d.ts +8 -0
- package/dist/repository-rebase/git.d.ts.map +1 -1
- package/dist/repository-reconciliation.d.ts +47 -0
- package/dist/repository-reconciliation.d.ts.map +1 -0
- package/dist/repository-record.d.ts +6 -0
- package/dist/repository-record.d.ts.map +1 -0
- package/dist/settings.d.ts +15 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.d.ts +35 -0
- package/dist/turns/commit-message-evidence.d.ts.map +1 -0
- package/dist/turns/commit-message-evidence.js +9 -0
- package/dist/turns/generate-commit-message.d.ts +4 -1
- package/dist/turns/generate-commit-message.d.ts.map +1 -1
- package/dist/turns/generate-commit-message.js +7 -5
- package/dist/turns/generate-plan.d.ts.map +1 -1
- package/dist/turns/generate-plan.js +1 -1
- package/dist/turns/git-inspection-profile.d.ts +25 -0
- package/dist/turns/git-inspection-profile.d.ts.map +1 -0
- package/dist/turns/git-inspection-profile.js +8 -0
- package/dist/turns/implement.d.ts +1 -1
- package/dist/turns/implement.d.ts.map +1 -1
- package/dist/turns/implement.js +1 -1
- package/dist/turns/simplify-implementation.d.ts +1 -1
- package/dist/turns/simplify-implementation.d.ts.map +1 -1
- package/dist/turns/simplify-implementation.js +3 -3
- package/package.json +5 -9
- package/src/finalization-git-internal.ts +186 -114
- package/src/finalization-git.ts +1 -1
- package/src/index.ts +4 -1
- package/src/pull-request-publication-internal.ts +158 -79
- package/src/repository-change-launch-internal.ts +119 -12
- package/src/repository-change-launch.ts +8 -4
- package/src/repository-change-process.ts +252 -524
- package/src/repository-change-publication.ts +702 -121
- package/src/repository-change-state-internal.ts +34 -20
- package/src/repository-change-ui-launcher-internal.ts +139 -56
- package/src/repository-publication-receipt.ts +71 -0
- package/src/repository-rebase/git.ts +108 -29
- package/src/repository-reconciliation.ts +600 -0
- package/src/repository-record.ts +14 -0
- package/src/settings.ts +79 -0
- package/src/turns/commit-message-evidence.ts +241 -0
- package/src/turns/generate-commit-message.ts +53 -23
- package/src/turns/generate-plan.ts +26 -12
- package/src/turns/git-inspection-profile.ts +134 -0
- package/src/turns/implement.ts +13 -3
- package/src/turns/simplify-implementation.ts +10 -6
- package/dist/chunk-34B3Q75M.js +0 -25
- package/dist/chunk-34B3Q75M.js.map +0 -1
- package/dist/chunk-F6CEEAFE.js +0 -13
- package/dist/chunk-F6CEEAFE.js.map +0 -1
- package/dist/chunk-GO44KCUS.js +0 -154
- package/dist/chunk-GO44KCUS.js.map +0 -1
- package/dist/chunk-R3UCUGY6.js +0 -31
- package/dist/chunk-R3UCUGY6.js.map +0 -1
- package/dist/chunk-W7VJT6AN.js +0 -25
- package/dist/chunk-W7VJT6AN.js.map +0 -1
- package/dist/chunk-WKHVLLKE.js +0 -45
- package/dist/chunk-WKHVLLKE.js.map +0 -1
- package/dist/chunk-YSC5GEQJ.js.map +0 -1
- package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +0 -67
- package/dist/turns/review-implementation.d.ts +0 -4
- package/dist/turns/review-implementation.d.ts.map +0 -1
- package/dist/turns/review-implementation.js +0 -8
- package/dist/turns/review-plan.d.ts +0 -4
- package/dist/turns/review-plan.d.ts.map +0 -1
- package/dist/turns/review-plan.js +0 -8
- package/src/turns/review-implementation.ts +0 -30
- package/src/turns/review-plan.ts +0 -24
- /package/dist/turns/{review-implementation.js.map → commit-message-evidence.js.map} +0 -0
- /package/dist/turns/{review-plan.js.map → git-inspection-profile.js.map} +0 -0
|
@@ -4,6 +4,14 @@ import path from "node:path";
|
|
|
4
4
|
import { trimToNull, type WorkerErrorClass } from "@leitwerk-dev/domain";
|
|
5
5
|
import { repositoryGitArgs, repositoryGitSubprocessEnv } from "@leitwerk-dev/process-sdk";
|
|
6
6
|
import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
|
|
7
|
+
import {
|
|
8
|
+
pushWasRejected,
|
|
9
|
+
type RepositoryPublicationReceipt,
|
|
10
|
+
readPublicationReceipt,
|
|
11
|
+
readRepositoryBinding,
|
|
12
|
+
repositoryBindingMatches,
|
|
13
|
+
savePublicationReceipt,
|
|
14
|
+
} from "./repository-publication-receipt.js";
|
|
7
15
|
|
|
8
16
|
/** @public */
|
|
9
17
|
export interface GitIdentity {
|
|
@@ -25,14 +33,21 @@ export class DeterministicGitError extends Error {
|
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
|
|
36
|
+
/** @internal */
|
|
37
|
+
export class RemoteBranchChangedError extends DeterministicGitError {
|
|
38
|
+
constructor() {
|
|
39
|
+
super("The remote source branch changed before publication; reconcile and validate again");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
28
43
|
interface GitExecResult {
|
|
29
44
|
ok: boolean;
|
|
30
45
|
stdout: string;
|
|
31
46
|
stderr: string;
|
|
32
47
|
}
|
|
33
48
|
|
|
34
|
-
function gitConfigIdentityEnv(): NodeJS.ProcessEnv {
|
|
35
|
-
const env = repositoryGitSubprocessEnv(
|
|
49
|
+
function gitConfigIdentityEnv(projectKey: string): NodeJS.ProcessEnv {
|
|
50
|
+
const env = repositoryGitSubprocessEnv(projectKey, { GIT_TERMINAL_PROMPT: "0" });
|
|
36
51
|
for (const key of [
|
|
37
52
|
"GIT_AUTHOR_NAME",
|
|
38
53
|
"GIT_AUTHOR_EMAIL",
|
|
@@ -54,126 +69,183 @@ function gitIdentityArgs(identity: GitIdentity): string[] {
|
|
|
54
69
|
return ["-c", `user.name=${name}`, "-c", `user.email=${email}`];
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
function repositoryGit(projectKey: string, repoPath: string) {
|
|
73
|
+
function runGit(args: readonly string[], identity?: GitIdentity): GitExecResult {
|
|
74
|
+
const trustedArgs = identity ? [...gitIdentityArgs(identity), ...args] : args;
|
|
75
|
+
try {
|
|
76
|
+
const stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(trustedArgs), {
|
|
77
|
+
cwd: repoPath,
|
|
78
|
+
encoding: "utf8",
|
|
79
|
+
env: gitConfigIdentityEnv(projectKey),
|
|
80
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
81
|
+
});
|
|
82
|
+
return { ok: true, stdout, stderr: "" };
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const execError = error as {
|
|
85
|
+
stdout?: string | Buffer;
|
|
86
|
+
stderr?: string | Buffer;
|
|
87
|
+
message?: string;
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
ok: false,
|
|
91
|
+
stdout: execError.stdout?.toString() ?? "",
|
|
92
|
+
stderr: execError.stderr?.toString() ?? trimToNull(execError.message) ?? "",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
78
95
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function checkedGit(
|
|
82
|
-
repoPath: string,
|
|
83
|
-
args: readonly string[],
|
|
84
|
-
failureMessage: string,
|
|
85
|
-
identity?: GitIdentity,
|
|
86
|
-
): string {
|
|
87
|
-
const result = runGit(repoPath, args, identity);
|
|
88
|
-
if (!result.ok) {
|
|
89
|
-
const detail = trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? "unknown git error";
|
|
90
|
-
throw new DeterministicGitError(`${failureMessage}: ${detail}`);
|
|
91
|
-
}
|
|
92
|
-
return result.stdout.trim();
|
|
93
|
-
}
|
|
94
96
|
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
function checkedGit(
|
|
98
|
+
args: readonly string[],
|
|
99
|
+
failureMessage: string,
|
|
100
|
+
identity?: GitIdentity,
|
|
101
|
+
): string {
|
|
102
|
+
const result = runGit(args, identity);
|
|
103
|
+
if (!result.ok) {
|
|
104
|
+
const detail = trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? "unknown git error";
|
|
105
|
+
throw new DeterministicGitError(`${failureMessage}: ${detail}`);
|
|
106
|
+
}
|
|
107
|
+
return result.stdout.trim();
|
|
108
|
+
}
|
|
98
109
|
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
110
|
+
function git(...args: string[]): string {
|
|
111
|
+
return checkedGit(args, `git ${args.join(" ")} failed in '${repoPath}'`);
|
|
112
|
+
}
|
|
103
113
|
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
.
|
|
107
|
-
|
|
108
|
-
.filter(Boolean)
|
|
109
|
-
.map((line) => line.slice(2).trim())
|
|
110
|
-
.filter(Boolean);
|
|
111
|
-
}
|
|
114
|
+
function gitOrNull(...args: string[]): string | null {
|
|
115
|
+
const result = runGit(args);
|
|
116
|
+
return result.ok ? trimToNull(result.stdout) : null;
|
|
117
|
+
}
|
|
112
118
|
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
function workingTreeStatus(): string[] {
|
|
120
|
+
return (gitOrNull("status", "--porcelain") ?? "")
|
|
121
|
+
.split(/\r?\n/)
|
|
122
|
+
.map((line) => line.replace(/\s+$/, ""))
|
|
123
|
+
.filter(Boolean)
|
|
124
|
+
.map((line) => line.slice(2).trim())
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
}
|
|
119
127
|
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
function conflictedFiles(): string[] {
|
|
129
|
+
return (gitOrNull("diff", "--name-only", "--diff-filter=U") ?? "")
|
|
130
|
+
.split(/\r?\n/)
|
|
131
|
+
.map((line) => line.trim())
|
|
132
|
+
.filter(Boolean);
|
|
133
|
+
}
|
|
124
134
|
|
|
125
|
-
function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
!runGit(repoPath, ["var", "GIT_COMMITTER_IDENT"], identity).ok
|
|
129
|
-
) {
|
|
130
|
-
throw new DeterministicGitError("Git author/committer identity is not configured");
|
|
135
|
+
function mergeInProgress(): boolean {
|
|
136
|
+
const gitDir = git("rev-parse", "--git-dir");
|
|
137
|
+
return existsSync(path.resolve(repoPath, gitDir, "MERGE_HEAD"));
|
|
131
138
|
}
|
|
132
|
-
}
|
|
133
139
|
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}): string {
|
|
142
|
-
if (workingTreeStatus(input.repoPath).length === 0)
|
|
143
|
-
return git(input.repoPath, "rev-parse", "HEAD");
|
|
144
|
-
assertGitIdentity(input.repoPath, input.gitIdentity);
|
|
145
|
-
checkedGit(input.repoPath, ["add", "--all"], "Failed to stage the completed change");
|
|
146
|
-
checkedGit(
|
|
147
|
-
input.repoPath,
|
|
148
|
-
["-c", "core.hooksPath=/dev/null", "commit", "--no-gpg-sign", "-m", input.commitMessage],
|
|
149
|
-
"Failed to commit the completed change",
|
|
150
|
-
input.gitIdentity,
|
|
151
|
-
);
|
|
152
|
-
const remaining = workingTreeStatus(input.repoPath);
|
|
153
|
-
if (remaining.length > 0) {
|
|
154
|
-
throw new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(", ")}`);
|
|
140
|
+
function assertGitIdentity(identity: GitIdentity): void {
|
|
141
|
+
if (
|
|
142
|
+
!runGit(["var", "GIT_AUTHOR_IDENT"], identity).ok ||
|
|
143
|
+
!runGit(["var", "GIT_COMMITTER_IDENT"], identity).ok
|
|
144
|
+
) {
|
|
145
|
+
throw new DeterministicGitError("Git author/committer identity is not configured");
|
|
146
|
+
}
|
|
155
147
|
}
|
|
156
|
-
return git(input.repoPath, "rev-parse", "HEAD");
|
|
157
|
-
}
|
|
158
148
|
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
throw new DeterministicGitError(
|
|
168
|
-
`Published '${pushTarget}' resolved to '${remoteHead ?? "missing"}', expected '${expectedHeadSha}'`,
|
|
149
|
+
function commitIfDirty(commitMessage: string, identity: GitIdentity): string {
|
|
150
|
+
if (workingTreeStatus().length === 0) return git("rev-parse", "HEAD");
|
|
151
|
+
assertGitIdentity(identity);
|
|
152
|
+
checkedGit(["add", "--all"], "Failed to stage the completed change");
|
|
153
|
+
checkedGit(
|
|
154
|
+
["-c", "core.hooksPath=/dev/null", "commit", "--no-gpg-sign", "-m", commitMessage],
|
|
155
|
+
"Failed to commit the completed change",
|
|
156
|
+
identity,
|
|
169
157
|
);
|
|
158
|
+
const remaining = workingTreeStatus();
|
|
159
|
+
if (remaining.length > 0) {
|
|
160
|
+
throw new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(", ")}`);
|
|
161
|
+
}
|
|
162
|
+
return git("rev-parse", "HEAD");
|
|
170
163
|
}
|
|
171
|
-
|
|
164
|
+
|
|
165
|
+
function pushAndVerify(
|
|
166
|
+
branch: string,
|
|
167
|
+
expectedHeadSha: string,
|
|
168
|
+
expectedRemoteHead?: string | null,
|
|
169
|
+
): string {
|
|
170
|
+
const ref = `refs/heads/${branch}`;
|
|
171
|
+
const pushTarget = `origin/${branch}`;
|
|
172
|
+
const observed = git("ls-remote", "--heads", "origin", ref).split(/\s+/)[0] || null;
|
|
173
|
+
const lease = expectedRemoteHead === undefined ? observed : expectedRemoteHead;
|
|
174
|
+
const directory = git("rev-parse", "--absolute-git-dir");
|
|
175
|
+
const binding = readRepositoryBinding(git, branch);
|
|
176
|
+
if (binding.origin !== binding.pushOrigin)
|
|
177
|
+
throw new DeterministicGitError("Fetch and push endpoints must match for publication");
|
|
178
|
+
const previous = readPublicationReceipt(directory);
|
|
179
|
+
if (!repositoryBindingMatches(previous, binding))
|
|
180
|
+
throw new DeterministicGitError("Repository publication receipt binding changed");
|
|
181
|
+
const receipt: RepositoryPublicationReceipt = {
|
|
182
|
+
...binding,
|
|
183
|
+
expectedHead: lease,
|
|
184
|
+
candidate: expectedHeadSha,
|
|
185
|
+
status: "attempting",
|
|
186
|
+
};
|
|
187
|
+
// Recover a successful push whose acknowledgement was lost.
|
|
188
|
+
if (observed === expectedHeadSha) {
|
|
189
|
+
savePublicationReceipt(directory, { ...receipt, status: "accepted" });
|
|
190
|
+
return pushTarget;
|
|
191
|
+
}
|
|
192
|
+
if (previous?.status === "attempting")
|
|
193
|
+
throw new DeterministicGitError(
|
|
194
|
+
"A prior publication is unresolved; retain local work and reconcile its exact candidate first",
|
|
195
|
+
);
|
|
196
|
+
if (previous?.status === "accepted" && previous.candidate === expectedHeadSha)
|
|
197
|
+
throw new RemoteBranchChangedError();
|
|
198
|
+
if (observed !== lease) throw new RemoteBranchChangedError();
|
|
199
|
+
if (lease && !runGit(["merge-base", "--is-ancestor", lease, expectedHeadSha]).ok)
|
|
200
|
+
throw new DeterministicGitError(
|
|
201
|
+
"Ordinary publication must preserve the captured remote head",
|
|
202
|
+
);
|
|
203
|
+
savePublicationReceipt(directory, receipt);
|
|
204
|
+
const pushed = runGit([
|
|
205
|
+
"push",
|
|
206
|
+
"--porcelain",
|
|
207
|
+
"--no-follow-tags",
|
|
208
|
+
"--recurse-submodules=no",
|
|
209
|
+
`--force-with-lease=${ref}:${lease ?? ""}`,
|
|
210
|
+
"origin",
|
|
211
|
+
`${expectedHeadSha}:${ref}`,
|
|
212
|
+
]);
|
|
213
|
+
if (!pushed.ok) {
|
|
214
|
+
if (pushWasRejected(pushed.stdout))
|
|
215
|
+
savePublicationReceipt(directory, { ...receipt, status: "rejected" });
|
|
216
|
+
const latest = git("ls-remote", "--heads", "origin", ref).split(/\s+/)[0] || null;
|
|
217
|
+
if (latest === expectedHeadSha) {
|
|
218
|
+
savePublicationReceipt(directory, { ...receipt, status: "accepted" });
|
|
219
|
+
return pushTarget;
|
|
220
|
+
}
|
|
221
|
+
if (latest !== lease) throw new RemoteBranchChangedError();
|
|
222
|
+
throw new DeterministicGitError(`Failed to push HEAD to '${pushTarget}': ${pushed.stderr}`);
|
|
223
|
+
}
|
|
224
|
+
savePublicationReceipt(directory, { ...receipt, status: "accepted" });
|
|
225
|
+
const remoteHead = gitOrNull("ls-remote", "--heads", "origin", ref)?.split(/\s+/)[0]?.trim();
|
|
226
|
+
if (remoteHead !== expectedHeadSha) throw new RemoteBranchChangedError();
|
|
227
|
+
return pushTarget;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Inspect staged, unstaged, untracked, and already committed unpublished changes. @public */
|
|
234
|
+
export function repositoryHasChanges(
|
|
235
|
+
repoPath: string,
|
|
236
|
+
baseBranch: string,
|
|
237
|
+
projectKey = "repo",
|
|
238
|
+
): boolean {
|
|
239
|
+
const { git } = repositoryGit(projectKey, repoPath);
|
|
240
|
+
return Boolean(
|
|
241
|
+
git("status", "--porcelain") || git("diff", "--name-only", `origin/${baseBranch}...HEAD`),
|
|
242
|
+
);
|
|
172
243
|
}
|
|
173
244
|
|
|
174
245
|
/** Commit the current workspace change and non-force push only the feature branch. */
|
|
175
246
|
/** @public */
|
|
176
247
|
export function commitAndPushWorkBranch(input: {
|
|
248
|
+
/** @public */ projectKey?: string;
|
|
177
249
|
/** @public */
|
|
178
250
|
repoPath: string;
|
|
179
251
|
/** @public */
|
|
@@ -182,14 +254,18 @@ export function commitAndPushWorkBranch(input: {
|
|
|
182
254
|
commitMessage: string;
|
|
183
255
|
/** @public */
|
|
184
256
|
gitIdentity: GitIdentity;
|
|
257
|
+
/** Captured remote head; null requires branch creation. @internal */
|
|
258
|
+
expectedRemoteHead?: string | null;
|
|
185
259
|
}) {
|
|
186
260
|
const repoPath = path.resolve(input.repoPath);
|
|
187
|
-
|
|
261
|
+
const { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify } =
|
|
262
|
+
repositoryGit(input.projectKey ?? "repo", repoPath);
|
|
263
|
+
if (!existsSync(repoPath) || !runGit(["rev-parse", "--git-dir"]).ok) {
|
|
188
264
|
throw new DeterministicGitError(
|
|
189
265
|
`Repository workspace '${repoPath}' does not exist or is not a git repository`,
|
|
190
266
|
);
|
|
191
267
|
}
|
|
192
|
-
const branch = git(
|
|
268
|
+
const branch = git("branch", "--show-current");
|
|
193
269
|
if (branch !== input.workBranch) {
|
|
194
270
|
throw new DeterministicGitError(
|
|
195
271
|
`Expected '${repoPath}' to be checked out on '${input.workBranch}', but found '${branch || "detached HEAD"}'`,
|
|
@@ -198,21 +274,17 @@ export function commitAndPushWorkBranch(input: {
|
|
|
198
274
|
if (!trimToNull(input.commitMessage)) {
|
|
199
275
|
throw new DeterministicGitError("A generated commit message is required before publication");
|
|
200
276
|
}
|
|
201
|
-
const conflicts = conflictedFiles(
|
|
202
|
-
if (mergeInProgress(
|
|
277
|
+
const conflicts = conflictedFiles();
|
|
278
|
+
if (mergeInProgress() || conflicts.length > 0) {
|
|
203
279
|
throw new DeterministicGitError(
|
|
204
280
|
`Cannot publish a work branch with unresolved conflicts: ${conflicts.join(", ") || "merge in progress"}`,
|
|
205
281
|
);
|
|
206
282
|
}
|
|
207
|
-
const headSha = commitIfDirty(
|
|
208
|
-
repoPath,
|
|
209
|
-
commitMessage: input.commitMessage,
|
|
210
|
-
gitIdentity: input.gitIdentity,
|
|
211
|
-
});
|
|
283
|
+
const headSha = commitIfDirty(input.commitMessage, input.gitIdentity);
|
|
212
284
|
return {
|
|
213
285
|
/** @public */
|
|
214
286
|
headSha,
|
|
215
287
|
/** @internal */
|
|
216
|
-
pushTarget: pushAndVerify(
|
|
288
|
+
pushTarget: pushAndVerify(input.workBranch, headSha, input.expectedRemoteHead),
|
|
217
289
|
};
|
|
218
290
|
}
|
package/src/finalization-git.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { GitIdentity } from "./finalization-git-internal.js";
|
|
2
|
-
export { commitAndPushWorkBranch } from "./finalization-git-internal.js";
|
|
2
|
+
export { commitAndPushWorkBranch, repositoryHasChanges } from "./finalization-git-internal.js";
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import { codingSettings } from "./settings.js";
|
|
2
3
|
|
|
3
4
|
/** @internal */
|
|
4
5
|
const manifest = {
|
|
@@ -8,7 +9,7 @@ const manifest = {
|
|
|
8
9
|
version: "0.1.0",
|
|
9
10
|
} as const;
|
|
10
11
|
/** @public */
|
|
11
|
-
const extension: LeitwerkExtensionModule = { manifest };
|
|
12
|
+
const extension: LeitwerkExtensionModule = { manifest, scopedSettings: codingSettings };
|
|
12
13
|
export default extension;
|
|
13
14
|
|
|
14
15
|
export {
|
|
@@ -18,3 +19,5 @@ export {
|
|
|
18
19
|
requestRevisionForm,
|
|
19
20
|
} from "./actions.js";
|
|
20
21
|
export { createRepositoryChangeProcess } from "./repository-change-process.js";
|
|
22
|
+
|
|
23
|
+
export { codingPurposes, codingSettings } from "./settings.js";
|