@webpieces/pr-gate 0.4.975 → 0.4.976
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/package.json +6 -6
- package/src/scripts/commands/await-checks-command.d.ts +6 -3
- package/src/scripts/commands/await-checks-command.js +17 -12
- package/src/scripts/commands/await-checks-command.js.map +1 -1
- package/src/scripts/commands/await-reviews-command.d.ts +1 -1
- package/src/scripts/commands/await-reviews-command.js +3 -3
- package/src/scripts/commands/await-reviews-command.js.map +1 -1
- package/src/scripts/commands/check-pr-command.d.ts +3 -1
- package/src/scripts/commands/check-pr-command.js +12 -9
- package/src/scripts/commands/check-pr-command.js.map +1 -1
- package/src/scripts/commands/finish-push-dev-command.js +3 -4
- package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
- package/src/scripts/commands/finish-update-command.js +1 -1
- package/src/scripts/commands/finish-update-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +65 -62
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
- package/src/scripts/commands/human-post-pr-command.js +32 -31
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +5 -1
- package/src/scripts/commands/land-pr-command.js +36 -22
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/commands/main-checkout.d.ts +4 -1
- package/src/scripts/commands/main-checkout.js +22 -22
- package/src/scripts/commands/main-checkout.js.map +1 -1
- package/src/scripts/commands/push-dev-command.js +28 -29
- package/src/scripts/commands/push-dev-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.js +9 -9
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/start-update-command.d.ts +1 -1
- package/src/scripts/commands/start-update-command.js +3 -3
- package/src/scripts/commands/start-update-command.js.map +1 -1
- package/src/scripts/commands/start-upsert-pr-command.js +4 -4
- package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/sync-main-command.js +2 -2
- package/src/scripts/commands/sync-main-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
- package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/commands/working-tree-gate.d.ts +4 -1
- package/src/scripts/commands/working-tree-gate.js +14 -11
- package/src/scripts/commands/working-tree-gate.js.map +1 -1
- package/src/scripts/commands/write-review-command.js +4 -6
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.js +3 -4
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/git-finishUpsertPr.js +2 -2
- package/src/scripts/git-finishUpsertPr.js.map +1 -1
- package/src/scripts/git-gatherInfo.js +6 -7
- package/src/scripts/git-gatherInfo.js.map +1 -1
- package/src/scripts/pr-gate-container.d.ts +9 -0
- package/src/scripts/pr-gate-container.js +19 -0
- package/src/scripts/pr-gate-container.js.map +1 -0
- package/src/scripts/workflow/await-loop.d.ts +1 -1
- package/src/scripts/workflow/await-loop.js +1 -1
- package/src/scripts/workflow/await-loop.js.map +1 -1
- package/src/scripts/workflow/build-affected.js +1 -1
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
- package/src/scripts/workflow/build-artifact-gate.js +3 -3
- package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +9 -6
- package/src/scripts/workflow/build-gate-log.js +34 -40
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
- package/src/scripts/workflow/checklist-scanner.js +8 -8
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
- package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
- package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
- package/src/scripts/workflow/dev-deploy-refs.js +8 -8
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
- package/src/scripts/workflow/dev-resolve-runner.js +30 -30
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/diff-basis.d.ts +4 -2
- package/src/scripts/workflow/diff-basis.js +18 -15
- package/src/scripts/workflow/diff-basis.js.map +1 -1
- package/src/scripts/workflow/diff-materializer.d.ts +5 -3
- package/src/scripts/workflow/diff-materializer.js +18 -15
- package/src/scripts/workflow/diff-materializer.js.map +1 -1
- package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
- package/src/scripts/workflow/gated-pr-publisher.js +23 -22
- package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
- package/src/scripts/workflow/generated-artifact-registry.js +11 -8
- package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
- package/src/scripts/workflow/git-exec.d.ts +22 -12
- package/src/scripts/workflow/git-exec.js +45 -29
- package/src/scripts/workflow/git-exec.js.map +1 -1
- package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
- package/src/scripts/workflow/git-findForkPoint.js +31 -23
- package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
- package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
- package/src/scripts/workflow/git-readAiBranchName.js +8 -5
- package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
- package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
- package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
- package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
- package/src/scripts/workflow/landed-tree-resolver.js +11 -8
- package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
- package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
- package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
- package/src/scripts/workflow/merge-end.d.ts +2 -2
- package/src/scripts/workflow/merge-end.js +22 -24
- package/src/scripts/workflow/merge-end.js.map +1 -1
- package/src/scripts/workflow/merge-start.d.ts +5 -1
- package/src/scripts/workflow/merge-start.js +56 -49
- package/src/scripts/workflow/merge-start.js.map +1 -1
- package/src/scripts/workflow/open-pr-check.d.ts +4 -2
- package/src/scripts/workflow/open-pr-check.js +11 -8
- package/src/scripts/workflow/open-pr-check.js.map +1 -1
- package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
- package/src/scripts/workflow/pr-comment-upserter.js +15 -14
- package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
- package/src/scripts/workflow/pr-merger.d.ts +8 -5
- package/src/scripts/workflow/pr-merger.js +32 -27
- package/src/scripts/workflow/pr-merger.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
- package/src/scripts/workflow/provenance-enforcer.js +19 -17
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +7 -6
- package/src/scripts/workflow/review-round-state.js +33 -38
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/run-update.js +1 -1
- package/src/scripts/workflow/run-update.js.map +1 -1
- package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
- package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
- package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
- package/src/scripts/wp-await-checks.js +2 -2
- package/src/scripts/wp-await-checks.js.map +1 -1
- package/src/scripts/wp-await-reviews.js +2 -2
- package/src/scripts/wp-await-reviews.js.map +1 -1
- package/src/scripts/wp-build.js +2 -2
- package/src/scripts/wp-build.js.map +1 -1
- package/src/scripts/wp-check-pr.js +2 -2
- package/src/scripts/wp-check-pr.js.map +1 -1
- package/src/scripts/wp-cleanup.js +2 -2
- package/src/scripts/wp-cleanup.js.map +1 -1
- package/src/scripts/wp-finish-push-dev.js +2 -2
- package/src/scripts/wp-finish-push-dev.js.map +1 -1
- package/src/scripts/wp-finish-update.js +2 -2
- package/src/scripts/wp-finish-update.js.map +1 -1
- package/src/scripts/wp-human-post-pr.js +2 -2
- package/src/scripts/wp-human-post-pr.js.map +1 -1
- package/src/scripts/wp-land-pr.js +2 -2
- package/src/scripts/wp-land-pr.js.map +1 -1
- package/src/scripts/wp-push-dev.js +2 -2
- package/src/scripts/wp-push-dev.js.map +1 -1
- package/src/scripts/wp-reap-worktree.js +2 -2
- package/src/scripts/wp-reap-worktree.js.map +1 -1
- package/src/scripts/wp-review-upsert-pr.js +2 -2
- package/src/scripts/wp-review-upsert-pr.js.map +1 -1
- package/src/scripts/wp-start-update.js +2 -2
- package/src/scripts/wp-start-update.js.map +1 -1
- package/src/scripts/wp-start-upsert-pr.js +2 -2
- package/src/scripts/wp-start-upsert-pr.js.map +1 -1
- package/src/scripts/wp-sync-main.js +2 -2
- package/src/scripts/wp-sync-main.js.map +1 -1
- package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
- package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
- package/src/scripts/wp-write-review-fixes.js +2 -2
- package/src/scripts/wp-write-review-fixes.js.map +1 -1
- package/src/scripts/wp-write-review.js +2 -2
- package/src/scripts/wp-write-review.js.map +1 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GitExec = exports.GitOutcome = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
7
7
|
const inversify_1 = require("inversify");
|
|
8
8
|
const git_status_1 = require("./git-status");
|
|
9
9
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
@@ -28,13 +28,19 @@ class GitOutcome {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.GitOutcome = GitOutcome;
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Shared git precondition checks + push logic for the PR/merge workflow. Every git it runs goes through
|
|
33
|
+
* the injected {@link GitProcessApi} edge (#1381), so a feature test scripts git's answers instead of
|
|
34
|
+
* building a repository.
|
|
35
|
+
*/
|
|
32
36
|
let GitExec = class GitExec {
|
|
33
37
|
repoRootFinder;
|
|
34
38
|
statusParser;
|
|
35
|
-
|
|
39
|
+
git;
|
|
40
|
+
constructor(repoRootFinder, statusParser, git) {
|
|
36
41
|
this.repoRootFinder = repoRootFinder;
|
|
37
42
|
this.statusParser = statusParser;
|
|
43
|
+
this.git = git;
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Raw `git status --porcelain` with ONLY the trailing newline(s) stripped — never `.trim()`.
|
|
@@ -49,15 +55,16 @@ let GitExec = class GitExec {
|
|
|
49
55
|
* Tracked changes (staged + unstaged) AND untracked files, EXCLUDING gitignored paths — so
|
|
50
56
|
* `.webpieces/` tooling artifacts never count. Empty string = fully committed.
|
|
51
57
|
*/
|
|
52
|
-
porcelainStatus(cwd) {
|
|
53
|
-
|
|
58
|
+
async porcelainStatus(cwd) {
|
|
59
|
+
const raw = await this.rawGitQuery(['status', '--porcelain'], cwd, 'Failed to run `git status --porcelain` to check the working tree.');
|
|
60
|
+
return raw.replace(/\n+$/, '');
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
56
63
|
* The same status, PARSED: two status columns, an unquoted path, and explicit
|
|
57
64
|
* `isStaged()`/`isUnstaged()`/`isUntracked()` answers. Use this for every semantic question.
|
|
58
65
|
*/
|
|
59
|
-
statusEntries(cwd) {
|
|
60
|
-
return this.statusParser.parse(this.porcelainStatus(cwd));
|
|
66
|
+
async statusEntries(cwd) {
|
|
67
|
+
return this.statusParser.parse(await this.porcelainStatus(cwd));
|
|
61
68
|
}
|
|
62
69
|
// Untracked files only (respects .gitignore). Empty string = none.
|
|
63
70
|
untrackedFiles(cwd) {
|
|
@@ -68,8 +75,8 @@ let GitExec = class GitExec {
|
|
|
68
75
|
* webpieces tooling deliberately does NOT `git add`/`commit` the developer's work for them. Aborts
|
|
69
76
|
* with instructions if anything is uncommitted (tracked or untracked, excluding gitignored).
|
|
70
77
|
*/
|
|
71
|
-
assertCleanTree(cwd) {
|
|
72
|
-
const dirty = this.porcelainStatus(cwd);
|
|
78
|
+
async assertCleanTree(cwd) {
|
|
79
|
+
const dirty = await this.porcelainStatus(cwd);
|
|
73
80
|
if (dirty === '')
|
|
74
81
|
return;
|
|
75
82
|
throw new rules_config_1.CliExitError(1, '\n' + SEP +
|
|
@@ -87,8 +94,8 @@ let GitExec = class GitExec {
|
|
|
87
94
|
* the tree but untracked files must NOT be swept into the squash commit. Lists any untracked files
|
|
88
95
|
* and aborts so the AI commits or deletes them explicitly.
|
|
89
96
|
*/
|
|
90
|
-
assertNoUntracked(cwd) {
|
|
91
|
-
const untracked = this.untrackedFiles(cwd);
|
|
97
|
+
async assertNoUntracked(cwd) {
|
|
98
|
+
const untracked = await this.untrackedFiles(cwd);
|
|
92
99
|
if (untracked === '')
|
|
93
100
|
return;
|
|
94
101
|
throw new rules_config_1.CliExitError(1, '\n' + SEP +
|
|
@@ -103,25 +110,29 @@ let GitExec = class GitExec {
|
|
|
103
110
|
/**
|
|
104
111
|
* Run a git command that is expected to succeed; abort the process with a clear message if it
|
|
105
112
|
* fails. Used for fetch/pull/checkout/commit where silently continuing on failure would operate on
|
|
106
|
-
* stale or wrong state.
|
|
113
|
+
* stale or wrong state. Its output goes straight to the terminal.
|
|
107
114
|
*/
|
|
108
|
-
runGitChecked(args, errMsg) {
|
|
109
|
-
const result =
|
|
110
|
-
if (result.
|
|
111
|
-
throw new rules_config_1.CliExitError(1, `❌ ${errMsg} (git ${args.join(' ')} exited ${String(result.
|
|
115
|
+
async runGitChecked(args, errMsg) {
|
|
116
|
+
const result = await this.git.passThrough(args);
|
|
117
|
+
if (!result.ok) {
|
|
118
|
+
throw new rules_config_1.CliExitError(1, `❌ ${errMsg} (git ${args.join(' ')} exited ${String(result.code)})`);
|
|
112
119
|
}
|
|
113
120
|
}
|
|
121
|
+
/** Run git with its output on the terminal and return its exit code — for a caller that decides itself. */
|
|
122
|
+
async passThrough(args, cwd) {
|
|
123
|
+
return (await this.git.passThrough(args, cwd)).code;
|
|
124
|
+
}
|
|
114
125
|
/**
|
|
115
126
|
* Push HEAD to origin/<currentBranch>. Uses --force-with-lease for an existing remote branch (the
|
|
116
127
|
* 3-point squash rewrites history) and -u for a brand-new branch.
|
|
117
128
|
*/
|
|
118
|
-
ensurePushed(currentBranch) {
|
|
119
|
-
const remoteExists = (
|
|
129
|
+
async ensurePushed(currentBranch) {
|
|
130
|
+
const remoteExists = (await this.git.run(['ls-remote', '--exit-code', '--heads', 'origin', currentBranch])).ok;
|
|
120
131
|
if (remoteExists) {
|
|
121
|
-
this.runGitChecked(['push', '--force-with-lease', 'origin', `HEAD:${currentBranch}`], 'Failed to push branch');
|
|
132
|
+
await this.runGitChecked(['push', '--force-with-lease', 'origin', `HEAD:${currentBranch}`], 'Failed to push branch');
|
|
122
133
|
}
|
|
123
134
|
else {
|
|
124
|
-
this.runGitChecked(['push', '-u', 'origin', `HEAD:${currentBranch}`], 'Failed to push new branch');
|
|
135
|
+
await this.runGitChecked(['push', '-u', 'origin', `HEAD:${currentBranch}`], 'Failed to push new branch');
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
138
|
/**
|
|
@@ -130,18 +141,22 @@ let GitExec = class GitExec {
|
|
|
130
141
|
* conflict?). Distinct from {@link runGitChecked}, which exists for the commands where continuing on
|
|
131
142
|
* failure would operate on wrong state.
|
|
132
143
|
*/
|
|
133
|
-
tryGit(args, cwd) {
|
|
134
|
-
const out =
|
|
135
|
-
return new GitOutcome(out.
|
|
144
|
+
async tryGit(args, cwd) {
|
|
145
|
+
const out = await this.git.run(args, cwd);
|
|
146
|
+
return new GitOutcome(out.code, out.stdout.trim(), out.stderr.trim());
|
|
147
|
+
}
|
|
148
|
+
/** `git branch --show-current` in `cwd` — '' on a detached HEAD. Must succeed. */
|
|
149
|
+
currentBranch(cwd) {
|
|
150
|
+
return this.gitQuery(['branch', '--show-current'], cwd, 'Failed to read the current branch (git branch --show-current).');
|
|
136
151
|
}
|
|
137
152
|
/** Read-only git query that MUST succeed, trimmed. Public sibling of the private raw form. */
|
|
138
|
-
gitQuery(args, cwd, failMsg) {
|
|
139
|
-
return this.rawGitQuery(args, cwd, failMsg).trim();
|
|
153
|
+
async gitQuery(args, cwd, failMsg) {
|
|
154
|
+
return (await this.rawGitQuery(args, cwd, failMsg)).trim();
|
|
140
155
|
}
|
|
141
156
|
// The untrimmed sibling — see porcelainStatus for why trimming is not always safe.
|
|
142
|
-
rawGitQuery(args, cwd, failMsg) {
|
|
143
|
-
const out =
|
|
144
|
-
if (out.
|
|
157
|
+
async rawGitQuery(args, cwd, failMsg) {
|
|
158
|
+
const out = await this.git.run(args, cwd);
|
|
159
|
+
if (!out.ok) {
|
|
145
160
|
throw new rules_config_1.CliExitError(1, `❌ ${failMsg}`);
|
|
146
161
|
}
|
|
147
162
|
return out.stdout;
|
|
@@ -151,6 +166,7 @@ exports.GitExec = GitExec;
|
|
|
151
166
|
exports.GitExec = GitExec = tslib_1.__decorate([
|
|
152
167
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
153
168
|
tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
|
|
154
|
-
git_status_1.GitStatusParser
|
|
169
|
+
git_status_1.GitStatusParser,
|
|
170
|
+
tooling_common_1.GitProcessApi])
|
|
155
171
|
], GitExec);
|
|
156
172
|
//# sourceMappingURL=git-exec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-exec.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-exec.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAAuE;AACvE,yCAA2D;AAC3D,6CAA+D;AAE/D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AACvE,oGAAoG;AACpG,qGAAqG;AACrG,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAE1D;;;GAGG;AACH,MAAa,UAAU;IACnB,MAAM,CAAS;IACf,MAAM,CAAS;IACf,MAAM,CAAS;IAEf,YAAY,MAAc,EAAE,MAAc,EAAE,MAAc;QACtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;IAC7B,CAAC;CACJ;AAdD,gCAcC;AAED,6EAA6E;AAEtE,IAAM,OAAO,GAAb,MAAM,OAAO;IAEK;IACA;IAFrB,YACqB,cAA8B,EAC9B,YAA6B;QAD7B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAiB;IAC/C,CAAC;IAEJ;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,GAAW;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,aAAa,CAAC,EAAE,GAAG,EAClD,mEAAmE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACjG,CAAC;IAED;;;OAGG;IACH,aAAa,CAAC,GAAW;QACrB,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;I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AE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,CAAC;IAED,mFAAmF;IAC3E,WAAW,CAAC,IAAc,EAAE,GAAW,EAAE,OAAe;QAC5D,MAAM,GAAG,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9D,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,KAAK,OAAO,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,GAAG,CAAC,MAAM,CAAC;IACtB,CAAC;CACJ,CAAA;AA/HY,0BAAO;kBAAP,OAAO;IADnB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,4BAAe;GAHzC,OAAO,CA+HnB","sourcesContent":["import { spawnSync } from 'child_process';\nimport { CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GitStatusEntry, GitStatusParser } from './git-status';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n// The AI-facing doc the failure messages point at (generated under `.webpieces/instruct-ai`, at the\n// REPO ROOT — resolved absolute so the AI opens it regardless of the cwd it reads the message from).\nconst GIT_WORKFLOW_DOC_NAME = 'webpieces.git-workflow.md';\n\n/**\n * The result of a git command that was allowed to fail. Data-only (per CLAUDE.md) so a caller asks\n * `outcome.ok` rather than re-deriving \"did it work\" from a status number at every site.\n */\nexport class GitOutcome {\n status: number;\n stdout: string;\n stderr: string;\n\n constructor(status: number, stdout: string, stderr: string) {\n this.status = status;\n this.stdout = stdout;\n this.stderr = stderr;\n }\n\n get ok(): boolean {\n return this.status === 0;\n }\n}\n\n/** Shared git precondition checks + push logic for the PR/merge workflow. */\n@injectable(bindingScopeValues.Singleton)\nexport class GitExec {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly statusParser: GitStatusParser,\n ) {}\n\n /**\n * Raw `git status --porcelain` with ONLY the trailing newline(s) stripped — never `.trim()`.\n *\n * There used to be a trimmed sibling here (`uncommittedFiles`) and it was a data-destroying trap:\n * porcelain column 1 is the index state and column 2 the worktree state, so an unstaged\n * modification is \" M path\"; `trim()` eats that leading space and the line then reads \"M path\",\n * i.e. STAGED — the exact inverse of the truth. It is deleted. This method is for EMPTINESS\n * (\"is the tree dirty at all?\") and for PRINTING; anything that reasons about the two columns\n * calls {@link statusEntries} and reads booleans instead of re-parsing a string.\n *\n * Tracked changes (staged + unstaged) AND untracked files, EXCLUDING gitignored paths — so\n * `.webpieces/` tooling artifacts never count. Empty string = fully committed.\n */\n porcelainStatus(cwd: string): string {\n return this.rawGitQuery(['status', '--porcelain'], cwd,\n 'Failed to run `git status --porcelain` to check the working tree.').replace(/\\n+$/, '');\n }\n\n /**\n * The same status, PARSED: two status columns, an unquoted path, and explicit\n * `isStaged()`/`isUnstaged()`/`isUntracked()` answers. Use this for every semantic question.\n */\n statusEntries(cwd: string): GitStatusEntry[] {\n return this.statusParser.parse(this.porcelainStatus(cwd));\n }\n\n // Untracked files only (respects .gitignore). Empty string = none.\n untrackedFiles(cwd: string): string {\n return this.gitQuery(['ls-files', '--others', '--exclude-standard'], cwd, 'Failed to list untracked files (git ls-files --others).');\n }\n\n /**\n * Precondition for every PR/merge entry point: the working tree must be fully committed. The\n * webpieces tooling deliberately does NOT `git add`/`commit` the developer's work for them. Aborts\n * with instructions if anything is uncommitted (tracked or untracked, excluding gitignored).\n */\n assertCleanTree(cwd: string): void {\n const dirty = this.porcelainStatus(cwd);\n if (dirty === '') return;\n throw new CliExitError(1,\n '\\n' + SEP +\n '❌ ERROR: You have uncommitted or untracked changes\\n' +\n SEP + '\\n' +\n 'The webpieces PR tooling will NOT commit your work for you. Commit your\\n' +\n 'changes, and either commit or delete any untracked files, then re-run.\\n\\n' +\n 'Working tree (git status --porcelain):\\n' +\n dirty + '\\n\\n' +\n `See ${this.repoRootFinder.docPathFrom(cwd, GIT_WORKFLOW_DOC_NAME)} for the full merge + PR process.\\n` +\n SEP,\n );\n }\n\n /**\n * Narrower guard for the merge-resolve commit point, where tracked resolutions are legitimately in\n * the tree but untracked files must NOT be swept into the squash commit. Lists any untracked files\n * and aborts so the AI commits or deletes them explicitly.\n */\n assertNoUntracked(cwd: string): void {\n const untracked = this.untrackedFiles(cwd);\n if (untracked === '') return;\n throw new CliExitError(1,\n '\\n' + SEP +\n '❌ ERROR: Untracked files present during merge finalize\\n' +\n SEP + '\\n' +\n 'The tooling will not sweep untracked files into the squash commit. Commit\\n' +\n 'or delete these, then re-run:\\n\\n' +\n untracked + '\\n\\n' +\n `See ${this.repoRootFinder.docPathFrom(cwd, GIT_WORKFLOW_DOC_NAME)} for the full merge + PR process.\\n` +\n SEP,\n );\n }\n\n /**\n * Run a git command that is expected to succeed; abort the process with a clear message if it\n * fails. Used for fetch/pull/checkout/commit where silently continuing on failure would operate on\n * stale or wrong state.\n */\n runGitChecked(args: string[], errMsg: string): void {\n const result = spawnSync('git', args, { stdio: 'inherit' });\n if (result.status !== 0) {\n throw new CliExitError(1, `❌ ${errMsg} (git ${args.join(' ')} exited ${String(result.status)})`);\n }\n }\n\n /**\n * Push HEAD to origin/<currentBranch>. Uses --force-with-lease for an existing remote branch (the\n * 3-point squash rewrites history) and -u for a brand-new branch.\n */\n ensurePushed(currentBranch: string): void {\n const remoteExists = spawnSync('git', ['ls-remote', '--exit-code', '--heads', 'origin', currentBranch]).status === 0;\n if (remoteExists) {\n this.runGitChecked(['push', '--force-with-lease', 'origin', `HEAD:${currentBranch}`], 'Failed to push branch');\n } else {\n this.runGitChecked(['push', '-u', 'origin', `HEAD:${currentBranch}`], 'Failed to push new branch');\n }\n }\n\n /**\n * Run a git command that MAY legitimately fail and report the outcome instead of aborting — for the\n * questions whose \"no\" is an answer rather than an error (does this remote ref exist? did this merge\n * conflict?). Distinct from {@link runGitChecked}, which exists for the commands where continuing on\n * failure would operate on wrong state.\n */\n tryGit(args: string[], cwd: string): GitOutcome {\n const out = spawnSync('git', args, { encoding: 'utf8', cwd });\n return new GitOutcome(out.status ?? 1, (out.stdout ?? '').trim(), (out.stderr ?? '').trim());\n }\n\n /** Read-only git query that MUST succeed, trimmed. Public sibling of the private raw form. */\n gitQuery(args: string[], cwd: string, failMsg: string): string {\n return this.rawGitQuery(args, cwd, failMsg).trim();\n }\n\n // The untrimmed sibling — see porcelainStatus for why trimming is not always safe.\n private rawGitQuery(args: string[], cwd: string, failMsg: string): string {\n const out = spawnSync('git', args, { encoding: 'utf8', cwd });\n if (out.status !== 0) {\n throw new CliExitError(1, `❌ ${failMsg}`);\n }\n return out.stdout;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git-exec.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-exec.ts"],"names":[],"mappings":";;;;AAAA,0DAAuE;AACvE,8DAA0D;AAC1D,yCAA2D;AAC3D,6CAA+D;AAE/D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AACvE,oGAAoG;AACpG,qGAAqG;AACrG,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAE1D;;;GAGG;AACH,MAAa,UAAU;IACnB,MAAM,CAAS;IACf,MAAM,CAAS;IACf,MAAM,CAAS;IAEf,YAAY,MAAc,EAAE,MAAc,EAAE,MAAc;QACtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;IAC7B,CAAC;CACJ;AAdD,gCAcC;AAED;;;;GAIG;AAEI,IAAM,OAAO,GAAb,MAAM,OAAO;IAEK;IACA;IACA;IAHrB,YACqB,cAA8B,EA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AAO,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,GAAG,CAAC,MAAM,CAAC;IACtB,CAAC;CACJ,CAAA;AA3IY,0BAAO;kBAAP,OAAO;IADnB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,4BAAe;QACxB,8BAAa;GAJ9B,OAAO,CA2InB","sourcesContent":["import { CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { GitProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GitStatusEntry, GitStatusParser } from './git-status';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n// The AI-facing doc the failure messages point at (generated under `.webpieces/instruct-ai`, at the\n// REPO ROOT — resolved absolute so the AI opens it regardless of the cwd it reads the message from).\nconst GIT_WORKFLOW_DOC_NAME = 'webpieces.git-workflow.md';\n\n/**\n * The result of a git command that was allowed to fail. Data-only (per CLAUDE.md) so a caller asks\n * `outcome.ok` rather than re-deriving \"did it work\" from a status number at every site.\n */\nexport class GitOutcome {\n status: number;\n stdout: string;\n stderr: string;\n\n constructor(status: number, stdout: string, stderr: string) {\n this.status = status;\n this.stdout = stdout;\n this.stderr = stderr;\n }\n\n get ok(): boolean {\n return this.status === 0;\n }\n}\n\n/**\n * Shared git precondition checks + push logic for the PR/merge workflow. Every git it runs goes through\n * the injected {@link GitProcessApi} edge (#1381), so a feature test scripts git's answers instead of\n * building a repository.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GitExec {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly statusParser: GitStatusParser,\n private readonly git: GitProcessApi,\n ) {}\n\n /**\n * Raw `git status --porcelain` with ONLY the trailing newline(s) stripped — never `.trim()`.\n *\n * There used to be a trimmed sibling here (`uncommittedFiles`) and it was a data-destroying trap:\n * porcelain column 1 is the index state and column 2 the worktree state, so an unstaged\n * modification is \" M path\"; `trim()` eats that leading space and the line then reads \"M path\",\n * i.e. STAGED — the exact inverse of the truth. It is deleted. This method is for EMPTINESS\n * (\"is the tree dirty at all?\") and for PRINTING; anything that reasons about the two columns\n * calls {@link statusEntries} and reads booleans instead of re-parsing a string.\n *\n * Tracked changes (staged + unstaged) AND untracked files, EXCLUDING gitignored paths — so\n * `.webpieces/` tooling artifacts never count. Empty string = fully committed.\n */\n async porcelainStatus(cwd: string): Promise<string> {\n const raw = await this.rawGitQuery(['status', '--porcelain'], cwd,\n 'Failed to run `git status --porcelain` to check the working tree.');\n return raw.replace(/\\n+$/, '');\n }\n\n /**\n * The same status, PARSED: two status columns, an unquoted path, and explicit\n * `isStaged()`/`isUnstaged()`/`isUntracked()` answers. Use this for every semantic question.\n */\n async statusEntries(cwd: string): Promise<GitStatusEntry[]> {\n return this.statusParser.parse(await this.porcelainStatus(cwd));\n }\n\n // Untracked files only (respects .gitignore). Empty string = none.\n untrackedFiles(cwd: string): Promise<string> {\n return this.gitQuery(['ls-files', '--others', '--exclude-standard'], cwd, 'Failed to list untracked files (git ls-files --others).');\n }\n\n /**\n * Precondition for every PR/merge entry point: the working tree must be fully committed. The\n * webpieces tooling deliberately does NOT `git add`/`commit` the developer's work for them. Aborts\n * with instructions if anything is uncommitted (tracked or untracked, excluding gitignored).\n */\n async assertCleanTree(cwd: string): Promise<void> {\n const dirty = await this.porcelainStatus(cwd);\n if (dirty === '') return;\n throw new CliExitError(1,\n '\\n' + SEP +\n '❌ ERROR: You have uncommitted or untracked changes\\n' +\n SEP + '\\n' +\n 'The webpieces PR tooling will NOT commit your work for you. Commit your\\n' +\n 'changes, and either commit or delete any untracked files, then re-run.\\n\\n' +\n 'Working tree (git status --porcelain):\\n' +\n dirty + '\\n\\n' +\n `See ${this.repoRootFinder.docPathFrom(cwd, GIT_WORKFLOW_DOC_NAME)} for the full merge + PR process.\\n` +\n SEP,\n );\n }\n\n /**\n * Narrower guard for the merge-resolve commit point, where tracked resolutions are legitimately in\n * the tree but untracked files must NOT be swept into the squash commit. Lists any untracked files\n * and aborts so the AI commits or deletes them explicitly.\n */\n async assertNoUntracked(cwd: string): Promise<void> {\n const untracked = await this.untrackedFiles(cwd);\n if (untracked === '') return;\n throw new CliExitError(1,\n '\\n' + SEP +\n '❌ ERROR: Untracked files present during merge finalize\\n' +\n SEP + '\\n' +\n 'The tooling will not sweep untracked files into the squash commit. Commit\\n' +\n 'or delete these, then re-run:\\n\\n' +\n untracked + '\\n\\n' +\n `See ${this.repoRootFinder.docPathFrom(cwd, GIT_WORKFLOW_DOC_NAME)} for the full merge + PR process.\\n` +\n SEP,\n );\n }\n\n /**\n * Run a git command that is expected to succeed; abort the process with a clear message if it\n * fails. Used for fetch/pull/checkout/commit where silently continuing on failure would operate on\n * stale or wrong state. Its output goes straight to the terminal.\n */\n async runGitChecked(args: string[], errMsg: string): Promise<void> {\n const result = await this.git.passThrough(args);\n if (!result.ok) {\n throw new CliExitError(1, `❌ ${errMsg} (git ${args.join(' ')} exited ${String(result.code)})`);\n }\n }\n\n /** Run git with its output on the terminal and return its exit code — for a caller that decides itself. */\n async passThrough(args: string[], cwd?: string): Promise<number> {\n return (await this.git.passThrough(args, cwd)).code;\n }\n\n /**\n * Push HEAD to origin/<currentBranch>. Uses --force-with-lease for an existing remote branch (the\n * 3-point squash rewrites history) and -u for a brand-new branch.\n */\n async ensurePushed(currentBranch: string): Promise<void> {\n const remoteExists = (await this.git.run(['ls-remote', '--exit-code', '--heads', 'origin', currentBranch])).ok;\n if (remoteExists) {\n await this.runGitChecked(['push', '--force-with-lease', 'origin', `HEAD:${currentBranch}`], 'Failed to push branch');\n } else {\n await this.runGitChecked(['push', '-u', 'origin', `HEAD:${currentBranch}`], 'Failed to push new branch');\n }\n }\n\n /**\n * Run a git command that MAY legitimately fail and report the outcome instead of aborting — for the\n * questions whose \"no\" is an answer rather than an error (does this remote ref exist? did this merge\n * conflict?). Distinct from {@link runGitChecked}, which exists for the commands where continuing on\n * failure would operate on wrong state.\n */\n async tryGit(args: string[], cwd: string): Promise<GitOutcome> {\n const out = await this.git.run(args, cwd);\n return new GitOutcome(out.code, out.stdout.trim(), out.stderr.trim());\n }\n\n /** `git branch --show-current` in `cwd` — '' on a detached HEAD. Must succeed. */\n currentBranch(cwd: string): Promise<string> {\n return this.gitQuery(['branch', '--show-current'], cwd, 'Failed to read the current branch (git branch --show-current).');\n }\n\n /** Read-only git query that MUST succeed, trimmed. Public sibling of the private raw form. */\n async gitQuery(args: string[], cwd: string, failMsg: string): Promise<string> {\n return (await this.rawGitQuery(args, cwd, failMsg)).trim();\n }\n\n // The untrimmed sibling — see porcelainStatus for why trimming is not always safe.\n private async rawGitQuery(args: string[], cwd: string, failMsg: string): Promise<string> {\n const out = await this.git.run(args, cwd);\n if (!out.ok) {\n throw new CliExitError(1, `❌ ${failMsg}`);\n }\n return out.stdout;\n }\n}\n"]}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { RepoRootFinder } from '@webpieces/rules-config';
|
|
2
|
+
import { GitProcessApi } from '@webpieces/tooling-common';
|
|
2
3
|
import { AiBranchName } from './git-readAiBranchName';
|
|
4
|
+
import { GitExec } from './git-exec';
|
|
3
5
|
import { MergeState } from './merge-state';
|
|
4
6
|
/** Computes the 3-point fork point and guards against improper merges-from-main. */
|
|
5
7
|
export declare class ForkPoint {
|
|
6
8
|
private readonly repoRootFinder;
|
|
7
9
|
private readonly aiBranchName;
|
|
8
10
|
private readonly mergeState;
|
|
9
|
-
|
|
11
|
+
private readonly gitExec;
|
|
12
|
+
private readonly git;
|
|
13
|
+
constructor(repoRootFinder: RepoRootFinder, aiBranchName: AiBranchName, mergeState: MergeState, gitExec: GitExec, git: GitProcessApi);
|
|
10
14
|
forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string;
|
|
11
15
|
/**
|
|
12
16
|
* The 3-point FORK POINT: where this branch diverged from main. `git merge-base origin/main HEAD`,
|
|
@@ -22,7 +26,7 @@ export declare class ForkPoint {
|
|
|
22
26
|
* Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always
|
|
23
27
|
* succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.
|
|
24
28
|
*/
|
|
25
|
-
resolveForkPoint(repoRoot: string): string
|
|
29
|
+
resolveForkPoint(repoRoot: string): Promise<string>;
|
|
26
30
|
findForkPoint(workflow: string): Promise<void>;
|
|
27
31
|
private checkMergeCommits;
|
|
28
32
|
private printMergeFromMainError;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ForkPoint = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
7
6
|
const path = tslib_1.__importStar(require("path"));
|
|
8
7
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
9
9
|
const inversify_1 = require("inversify");
|
|
10
10
|
const git_readAiBranchName_1 = require("./git-readAiBranchName");
|
|
11
|
+
const git_exec_1 = require("./git-exec");
|
|
11
12
|
const merge_state_1 = require("./merge-state");
|
|
12
13
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
13
14
|
/** Computes the 3-point fork point and guards against improper merges-from-main. */
|
|
@@ -15,10 +16,14 @@ let ForkPoint = class ForkPoint {
|
|
|
15
16
|
repoRootFinder;
|
|
16
17
|
aiBranchName;
|
|
17
18
|
mergeState;
|
|
18
|
-
|
|
19
|
+
gitExec;
|
|
20
|
+
git;
|
|
21
|
+
constructor(repoRootFinder, aiBranchName, mergeState, gitExec, git) {
|
|
19
22
|
this.repoRootFinder = repoRootFinder;
|
|
20
23
|
this.aiBranchName = aiBranchName;
|
|
21
24
|
this.mergeState = mergeState;
|
|
25
|
+
this.gitExec = gitExec;
|
|
26
|
+
this.git = git;
|
|
22
27
|
}
|
|
23
28
|
// Single source of truth for the per-feature dir fork-point output is written to — the SAME nested
|
|
24
29
|
// home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;
|
|
@@ -41,11 +46,11 @@ let ForkPoint = class ForkPoint {
|
|
|
41
46
|
* Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always
|
|
42
47
|
* succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.
|
|
43
48
|
*/
|
|
44
|
-
resolveForkPoint(repoRoot) {
|
|
49
|
+
async resolveForkPoint(repoRoot) {
|
|
45
50
|
for (const ref of ['origin/main', 'main']) {
|
|
46
|
-
const result =
|
|
47
|
-
const sha =
|
|
48
|
-
if (result.
|
|
51
|
+
const result = await this.git.run(['merge-base', ref, 'HEAD'], repoRoot);
|
|
52
|
+
const sha = result.stdout.trim();
|
|
53
|
+
if (result.ok && sha !== '')
|
|
49
54
|
return sha;
|
|
50
55
|
}
|
|
51
56
|
return '';
|
|
@@ -56,29 +61,30 @@ let ForkPoint = class ForkPoint {
|
|
|
56
61
|
'Usage: git-findForkPoint <workflow>\n' +
|
|
57
62
|
" workflow: 'review' or 'merge'");
|
|
58
63
|
}
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
64
|
+
const cwd = process.cwd();
|
|
65
|
+
const featureName = await this.aiBranchName.getFeatureName();
|
|
66
|
+
const currentBranch = await this.gitExec.currentBranch(cwd);
|
|
67
|
+
const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);
|
|
62
68
|
const outputDir = this.forkPointOutputDir(repoRoot, featureName, workflow);
|
|
63
69
|
const prefix = workflow === 'review' ? 'review-' : 'updatemain-';
|
|
64
70
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
65
|
-
|
|
66
|
-
const featureHead =
|
|
67
|
-
const originMain =
|
|
71
|
+
await this.git.run(['fetch', 'origin', 'main']);
|
|
72
|
+
const featureHead = await this.gitExec.gitQuery(['rev-parse', 'HEAD'], cwd, 'Failed to read HEAD (git rev-parse HEAD).');
|
|
73
|
+
const originMain = await this.gitExec.gitQuery(['rev-parse', 'origin/main'], cwd, 'Failed to read origin/main (git rev-parse origin/main).');
|
|
68
74
|
process.stderr.write('Finding fork point using git merge-base...\n');
|
|
69
75
|
// ONE implementation of the fork-point computation, shared with ChecklistScanner. The fetch above is
|
|
70
76
|
// what this flow needs beyond it (hash point C = main's current head), not the fork point itself.
|
|
71
|
-
const forkPoint = this.resolveForkPoint(repoRoot);
|
|
77
|
+
const forkPoint = await this.resolveForkPoint(repoRoot);
|
|
72
78
|
if (!forkPoint) {
|
|
73
79
|
throw new rules_config_1.CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');
|
|
74
80
|
}
|
|
75
81
|
process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\n`);
|
|
76
82
|
process.stderr.write('Checking for improper merges from main...\n');
|
|
77
|
-
const mergeCommitsResult =
|
|
78
|
-
const mergeCommitsRaw =
|
|
83
|
+
const mergeCommitsResult = await this.git.run(['log', `${forkPoint}..HEAD`, '--merges', '--format=%H']);
|
|
84
|
+
const mergeCommitsRaw = mergeCommitsResult.stdout.trim();
|
|
79
85
|
const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\n') : [];
|
|
80
86
|
if (mergeCommits.length > 0) {
|
|
81
|
-
this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);
|
|
87
|
+
await this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);
|
|
82
88
|
}
|
|
83
89
|
else {
|
|
84
90
|
process.stderr.write('✅ No merge commits found (clean history)\n');
|
|
@@ -92,15 +98,15 @@ let ForkPoint = class ForkPoint {
|
|
|
92
98
|
fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\n');
|
|
93
99
|
process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\n`);
|
|
94
100
|
}
|
|
95
|
-
checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch) {
|
|
101
|
+
async checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch) {
|
|
96
102
|
process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\n`);
|
|
97
103
|
for (const commit of mergeCommits) {
|
|
98
|
-
const parentsResult =
|
|
99
|
-
const parents =
|
|
104
|
+
const parentsResult = await this.git.run(['rev-list', '--parents', '-n', '1', commit]);
|
|
105
|
+
const parents = parentsResult.stdout.trim().split(' ').slice(1);
|
|
100
106
|
for (const parent of parents) {
|
|
101
|
-
const ancestorCheck =
|
|
102
|
-
const reverseCheck =
|
|
103
|
-
if (ancestorCheck.
|
|
107
|
+
const ancestorCheck = await this.git.run(['merge-base', '--is-ancestor', parent, 'origin/main']);
|
|
108
|
+
const reverseCheck = await this.git.run(['merge-base', '--is-ancestor', 'origin/main', parent]);
|
|
109
|
+
if (ancestorCheck.ok && reverseCheck.ok) {
|
|
104
110
|
const errorJson = JSON.stringify({
|
|
105
111
|
error: 'Merge from main detected',
|
|
106
112
|
mergeCommit: commit,
|
|
@@ -166,6 +172,8 @@ exports.ForkPoint = ForkPoint = tslib_1.__decorate([
|
|
|
166
172
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
167
173
|
tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
|
|
168
174
|
git_readAiBranchName_1.AiBranchName,
|
|
169
|
-
merge_state_1.MergeState
|
|
175
|
+
merge_state_1.MergeState,
|
|
176
|
+
git_exec_1.GitExec,
|
|
177
|
+
tooling_common_1.GitProcessApi])
|
|
170
178
|
], ForkPoint);
|
|
171
179
|
//# sourceMappingURL=git-findForkPoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-findForkPoint.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-findForkPoint.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,+CA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IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC1D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iDAAiD,aAAa,KAAK,CAAC,CAAC;QAC1F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACzD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,WAAW,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,aAAa,IAAI,CAAC,CAAC;QACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACJ,CAAA;AAvKY,8BAAS;oBAAT,SAAS;IADrB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACd,wBAAU;GAJlC,SAAS,CAuKrB","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { MergeState } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** Computes the 3-point fork point and guards against improper merges-from-main. */\n@injectable(bindingScopeValues.Singleton)\nexport class ForkPoint {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly mergeState: MergeState,\n ) {}\n\n // Single source of truth for the per-feature dir fork-point output is written to — the SAME nested\n // home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;\n // the review flow reads from prDirFor). Routing the writer through these same helpers is what keeps\n // them from diverging again — guarded by git-findForkPoint.spec.ts.\n forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string {\n return workflow === 'review' ? prDirFor(repoRoot, featureName) : this.mergeState.mergeDirFor(repoRoot, featureName);\n }\n\n /**\n * The 3-point FORK POINT: where this branch diverged from main. `git merge-base origin/main HEAD`,\n * falling back to a local `main`, and '' when neither ref resolves.\n *\n * Deliberately does NOT fetch. The fork point is ABSOLUTE — advancing main cannot move it, because\n * merge-base is the most recent common ancestor and main's new commits are not on this branch. (Verified\n * on this repo: main went f415456 → ba8f674 → 61432d6 while merge-base with one branch stayed f415456\n * throughout.) So a caller that needs only the fork point — see ChecklistScanner — pays no network cost\n * and works offline. `findForkPoint` below still fetches, because the MERGE flow additionally needs\n * main's CURRENT head as hash point C, which genuinely does require a fetch.\n *\n * Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always\n * succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.\n */\n resolveForkPoint(repoRoot: string): string {\n for (const ref of ['origin/main', 'main']) {\n const result = spawnSync('git', ['merge-base', ref, 'HEAD'], { cwd: repoRoot, encoding: 'utf8' });\n const sha = (result.stdout ?? '').trim();\n if (result.status === 0 && sha !== '') return sha;\n }\n return '';\n }\n\n async findForkPoint(workflow: string): Promise<void> {\n if (workflow !== 'review' && workflow !== 'merge') {\n throw new CliExitError(1,\n 'ERROR: Workflow argument required\\n' +\n 'Usage: git-findForkPoint <workflow>\\n' +\n \" workflow: 'review' or 'merge'\",\n );\n }\n\n const featureName = this.aiBranchName.getFeatureName();\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n\n const outputDir = this.forkPointOutputDir(repoRoot, featureName, workflow);\n const prefix = workflow === 'review' ? 'review-' : 'updatemain-';\n fs.mkdirSync(outputDir, { recursive: true });\n\n spawnSync('git', ['fetch', 'origin', 'main'], { stdio: 'ignore' });\n\n const featureHead = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();\n const originMain = execSync('git rev-parse origin/main', { encoding: 'utf8' }).trim();\n\n process.stderr.write('Finding fork point using git merge-base...\\n');\n\n // ONE implementation of the fork-point computation, shared with ChecklistScanner. The fetch above is\n // what this flow needs beyond it (hash point C = main's current head), not the fork point itself.\n const forkPoint = this.resolveForkPoint(repoRoot);\n\n if (!forkPoint) {\n throw new CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');\n }\n\n process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\\n`);\n process.stderr.write('Checking for improper merges from main...\\n');\n\n const mergeCommitsResult = spawnSync('git', ['log', `${forkPoint}..HEAD`, '--merges', '--format=%H'], { encoding: 'utf8' });\n const mergeCommitsRaw = (mergeCommitsResult.stdout ?? '').trim();\n const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\\n') : [];\n\n if (mergeCommits.length > 0) {\n this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);\n } else {\n process.stderr.write('✅ No merge commits found (clean history)\\n');\n }\n\n const hashesJson = JSON.stringify({\n hashForkPoint: forkPoint,\n hashFeatureHead: featureHead,\n hashMainHead: originMain,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\\n');\n process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\\n`);\n }\n\n private checkMergeCommits(mergeCommits: string[], outputDir: string, prefix: string, featureName: string, currentBranch: string): void {\n process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\\n`);\n\n for (const commit of mergeCommits) {\n const parentsResult = spawnSync('git', ['rev-list', '--parents', '-n', '1', commit], { encoding: 'utf8' });\n const parents = (parentsResult.stdout ?? '').trim().split(' ').slice(1);\n\n for (const parent of parents) {\n const ancestorCheck = spawnSync('git', ['merge-base', '--is-ancestor', parent, 'origin/main']);\n const reverseCheck = spawnSync('git', ['merge-base', '--is-ancestor', 'origin/main', parent]);\n\n if (ancestorCheck.status === 0 && reverseCheck.status === 0) {\n const errorJson = JSON.stringify({\n error: 'Merge from main detected',\n mergeCommit: commit,\n parentFromMain: parent,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}forkpoint-error.json`), errorJson + '\\n');\n this.printMergeFromMainError(commit, parent, featureName, currentBranch);\n throw new CliExitError(1, '');\n }\n }\n }\n process.stderr.write('✅ No improper merges from main detected\\n');\n }\n\n private printMergeFromMainError(commit: string, parent: string, featureName: string, currentBranch: string): void {\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('❌ This branch merged main without the gated update (pnpm wp-start-update, or\\n');\n process.stderr.write(' pnpm wp-start-upsert-pr when a PR is open)\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write(`Merge commit detected: ${commit}\\n`);\n process.stderr.write(`Parent from main: ${parent}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('This prevents clean squash-merge. To recover, follow these steps:\\n');\n process.stderr.write('\\n');\n process.stderr.write('1. Fetch the latest main (works on the primary repo AND in a worktree):\\n');\n process.stderr.write(' git fetch origin main\\n');\n process.stderr.write('\\n');\n // The \"do NOT `git checkout main`\" caveat is scoped to the WORKTREE case, where it is true.\n // Stated unconditionally it forbids a command that is perfectly good in the primary clone —\n // and that `.claude/rules/finishing-a-feature.md`'s own post-merge cleanup recipe uses\n // — which is how an agent talked\n // itself into believing a new branch was its only exit.\n process.stderr.write('2. Create a new branch OFF origin/main (this form works from ANY tree; inside a\\n');\n process.stderr.write(' worktree do NOT `git checkout main` first — it fatals with \"main is already\\n');\n process.stderr.write(' checked out at <primary>\"):\\n');\n process.stderr.write(` git checkout -b ${featureName}-v2 origin/main\\n`);\n process.stderr.write('\\n');\n process.stderr.write('3. Squash merge your old branch — THIS STEP IS FOR THE HUMAN TO RUN:\\n');\n process.stderr.write(` git merge --squash ${currentBranch}\\n`);\n process.stderr.write(' AI: `git merge` is blocked for you (redirect-how-to-merge-main) and you must NOT\\n');\n process.stderr.write(' work around it. Ask the human to run that one command, and warn them:\\n');\n process.stderr.write(' \"This is a raw git merge. It is only correct here because the branch is already\\n');\n process.stderr.write(' broken and is being rebuilt onto origin/main. For a NORMAL update from main,\\n');\n process.stderr.write(' push back and tell me to use the gated 3-point merge instead: `pnpm wp-start-update`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-update`) when no PR is open, or `pnpm wp-start-upsert-pr`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-upsert-pr`) when one is.\"\\n');\n process.stderr.write('\\n');\n process.stderr.write('4. Commit the squashed changes:\\n');\n process.stderr.write(` git add -A && git commit -m \"Squashed from ${currentBranch}\"\\n`);\n process.stderr.write('\\n');\n process.stderr.write('5. If you have an existing PR:\\n');\n process.stderr.write(` - Create a NEW PR for ${featureName}-v2\\n`);\n process.stderr.write(` - Close the old PR for ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git-findForkPoint.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-findForkPoint.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAiF;AACjF,8DAA0D;AAC1D,yCAA2D;AAC3D,iEAAsD;AACtD,yCAAqC;AACrC,+CAA2C;AAE3C,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,oFAAoF;AAE7E,IAAM,SAAS,GAAf,MAAM,SAAS;IAEG;IACA;IACA;IACA;IACA;IALrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,UAAsB,EACtB,OAAgB,EAChB,GAAkB;QAJlB,mBAAc,GAAd,cAAc,C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AW,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,aAAa,IAAI,CAAC,CAAC;QACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACJ,CAAA;AA1KY,8BAAS;oBAAT,SAAS;IADrB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACd,wBAAU;QACb,kBAAO;QACX,8BAAa;GAN9B,SAAS,CA0KrB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { GitProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { GitExec } from './git-exec';\nimport { MergeState } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** Computes the 3-point fork point and guards against improper merges-from-main. */\n@injectable(bindingScopeValues.Singleton)\nexport class ForkPoint {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly mergeState: MergeState,\n private readonly gitExec: GitExec,\n private readonly git: GitProcessApi,\n ) {}\n\n // Single source of truth for the per-feature dir fork-point output is written to — the SAME nested\n // home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;\n // the review flow reads from prDirFor). Routing the writer through these same helpers is what keeps\n // them from diverging again — guarded by git-findForkPoint.spec.ts.\n forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string {\n return workflow === 'review' ? prDirFor(repoRoot, featureName) : this.mergeState.mergeDirFor(repoRoot, featureName);\n }\n\n /**\n * The 3-point FORK POINT: where this branch diverged from main. `git merge-base origin/main HEAD`,\n * falling back to a local `main`, and '' when neither ref resolves.\n *\n * Deliberately does NOT fetch. The fork point is ABSOLUTE — advancing main cannot move it, because\n * merge-base is the most recent common ancestor and main's new commits are not on this branch. (Verified\n * on this repo: main went f415456 → ba8f674 → 61432d6 while merge-base with one branch stayed f415456\n * throughout.) So a caller that needs only the fork point — see ChecklistScanner — pays no network cost\n * and works offline. `findForkPoint` below still fetches, because the MERGE flow additionally needs\n * main's CURRENT head as hash point C, which genuinely does require a fetch.\n *\n * Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always\n * succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.\n */\n async resolveForkPoint(repoRoot: string): Promise<string> {\n for (const ref of ['origin/main', 'main']) {\n const result = await this.git.run(['merge-base', ref, 'HEAD'], repoRoot);\n const sha = result.stdout.trim();\n if (result.ok && sha !== '') return sha;\n }\n return '';\n }\n\n async findForkPoint(workflow: string): Promise<void> {\n if (workflow !== 'review' && workflow !== 'merge') {\n throw new CliExitError(1,\n 'ERROR: Workflow argument required\\n' +\n 'Usage: git-findForkPoint <workflow>\\n' +\n \" workflow: 'review' or 'merge'\",\n );\n }\n\n const cwd = process.cwd();\n const featureName = await this.aiBranchName.getFeatureName();\n const currentBranch = await this.gitExec.currentBranch(cwd);\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n\n const outputDir = this.forkPointOutputDir(repoRoot, featureName, workflow);\n const prefix = workflow === 'review' ? 'review-' : 'updatemain-';\n fs.mkdirSync(outputDir, { recursive: true });\n\n await this.git.run(['fetch', 'origin', 'main']);\n\n const featureHead = await this.gitExec.gitQuery(['rev-parse', 'HEAD'], cwd, 'Failed to read HEAD (git rev-parse HEAD).');\n const originMain = await this.gitExec.gitQuery(['rev-parse', 'origin/main'], cwd, 'Failed to read origin/main (git rev-parse origin/main).');\n\n process.stderr.write('Finding fork point using git merge-base...\\n');\n\n // ONE implementation of the fork-point computation, shared with ChecklistScanner. The fetch above is\n // what this flow needs beyond it (hash point C = main's current head), not the fork point itself.\n const forkPoint = await this.resolveForkPoint(repoRoot);\n\n if (!forkPoint) {\n throw new CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');\n }\n\n process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\\n`);\n process.stderr.write('Checking for improper merges from main...\\n');\n\n const mergeCommitsResult = await this.git.run(['log', `${forkPoint}..HEAD`, '--merges', '--format=%H']);\n const mergeCommitsRaw = mergeCommitsResult.stdout.trim();\n const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\\n') : [];\n\n if (mergeCommits.length > 0) {\n await this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);\n } else {\n process.stderr.write('✅ No merge commits found (clean history)\\n');\n }\n\n const hashesJson = JSON.stringify({\n hashForkPoint: forkPoint,\n hashFeatureHead: featureHead,\n hashMainHead: originMain,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\\n');\n process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\\n`);\n }\n\n private async checkMergeCommits(mergeCommits: string[], outputDir: string, prefix: string, featureName: string, currentBranch: string): Promise<void> {\n process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\\n`);\n\n for (const commit of mergeCommits) {\n const parentsResult = await this.git.run(['rev-list', '--parents', '-n', '1', commit]);\n const parents = parentsResult.stdout.trim().split(' ').slice(1);\n\n for (const parent of parents) {\n const ancestorCheck = await this.git.run(['merge-base', '--is-ancestor', parent, 'origin/main']);\n const reverseCheck = await this.git.run(['merge-base', '--is-ancestor', 'origin/main', parent]);\n\n if (ancestorCheck.ok && reverseCheck.ok) {\n const errorJson = JSON.stringify({\n error: 'Merge from main detected',\n mergeCommit: commit,\n parentFromMain: parent,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}forkpoint-error.json`), errorJson + '\\n');\n this.printMergeFromMainError(commit, parent, featureName, currentBranch);\n throw new CliExitError(1, '');\n }\n }\n }\n process.stderr.write('✅ No improper merges from main detected\\n');\n }\n\n private printMergeFromMainError(commit: string, parent: string, featureName: string, currentBranch: string): void {\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('❌ This branch merged main without the gated update (pnpm wp-start-update, or\\n');\n process.stderr.write(' pnpm wp-start-upsert-pr when a PR is open)\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write(`Merge commit detected: ${commit}\\n`);\n process.stderr.write(`Parent from main: ${parent}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('This prevents clean squash-merge. To recover, follow these steps:\\n');\n process.stderr.write('\\n');\n process.stderr.write('1. Fetch the latest main (works on the primary repo AND in a worktree):\\n');\n process.stderr.write(' git fetch origin main\\n');\n process.stderr.write('\\n');\n // The \"do NOT `git checkout main`\" caveat is scoped to the WORKTREE case, where it is true.\n // Stated unconditionally it forbids a command that is perfectly good in the primary clone —\n // and that `.claude/rules/finishing-a-feature.md`'s own post-merge cleanup recipe uses\n // — which is how an agent talked\n // itself into believing a new branch was its only exit.\n process.stderr.write('2. Create a new branch OFF origin/main (this form works from ANY tree; inside a\\n');\n process.stderr.write(' worktree do NOT `git checkout main` first — it fatals with \"main is already\\n');\n process.stderr.write(' checked out at <primary>\"):\\n');\n process.stderr.write(` git checkout -b ${featureName}-v2 origin/main\\n`);\n process.stderr.write('\\n');\n process.stderr.write('3. Squash merge your old branch — THIS STEP IS FOR THE HUMAN TO RUN:\\n');\n process.stderr.write(` git merge --squash ${currentBranch}\\n`);\n process.stderr.write(' AI: `git merge` is blocked for you (redirect-how-to-merge-main) and you must NOT\\n');\n process.stderr.write(' work around it. Ask the human to run that one command, and warn them:\\n');\n process.stderr.write(' \"This is a raw git merge. It is only correct here because the branch is already\\n');\n process.stderr.write(' broken and is being rebuilt onto origin/main. For a NORMAL update from main,\\n');\n process.stderr.write(' push back and tell me to use the gated 3-point merge instead: `pnpm wp-start-update`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-update`) when no PR is open, or `pnpm wp-start-upsert-pr`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-upsert-pr`) when one is.\"\\n');\n process.stderr.write('\\n');\n process.stderr.write('4. Commit the squashed changes:\\n');\n process.stderr.write(` git add -A && git commit -m \"Squashed from ${currentBranch}\"\\n`);\n process.stderr.write('\\n');\n process.stderr.write('5. If you have an existing PR:\\n');\n process.stderr.write(` - Create a NEW PR for ${featureName}-v2\\n`);\n process.stderr.write(` - Close the old PR for ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n }\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BranchNaming } from './branch-naming';
|
|
2
|
+
import { GitExec } from './git-exec';
|
|
2
3
|
/** The stable feature identity used to key the merge-context + PR-body dirs. */
|
|
3
4
|
export declare class AiBranchName {
|
|
4
5
|
private readonly branchNaming;
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
private readonly gitExec;
|
|
7
|
+
constructor(branchNaming: BranchNaming, gitExec: GitExec);
|
|
8
|
+
getFeatureName(): Promise<string>;
|
|
7
9
|
}
|
|
@@ -2,26 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AiBranchName = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const inversify_1 = require("inversify");
|
|
7
6
|
const branch_naming_1 = require("./branch-naming");
|
|
7
|
+
const git_exec_1 = require("./git-exec");
|
|
8
8
|
/** The stable feature identity used to key the merge-context + PR-body dirs. */
|
|
9
9
|
let AiBranchName = class AiBranchName {
|
|
10
10
|
branchNaming;
|
|
11
|
-
|
|
11
|
+
gitExec;
|
|
12
|
+
constructor(branchNaming, gitExec) {
|
|
12
13
|
this.branchNaming = branchNaming;
|
|
14
|
+
this.gitExec = gitExec;
|
|
13
15
|
}
|
|
14
16
|
// Stable feature identity used to key the merge-context dir and PR-body dir. It MUST stay constant
|
|
15
17
|
// across a sync's transient `<feature>Squash` temp branch (and any leftover `…wpN` from the old
|
|
16
18
|
// scheme), so derive it from baseBranchName (strips `Squash` + a legacy `wpN`) before slugifying.
|
|
17
|
-
getFeatureName() {
|
|
18
|
-
const branch =
|
|
19
|
+
async getFeatureName() {
|
|
20
|
+
const branch = await this.gitExec.currentBranch(process.cwd());
|
|
19
21
|
return this.branchNaming.baseBranchName(branch).replace(/\//g, '-');
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
exports.AiBranchName = AiBranchName;
|
|
23
25
|
exports.AiBranchName = AiBranchName = tslib_1.__decorate([
|
|
24
26
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
25
|
-
tslib_1.__metadata("design:paramtypes", [branch_naming_1.BranchNaming
|
|
27
|
+
tslib_1.__metadata("design:paramtypes", [branch_naming_1.BranchNaming,
|
|
28
|
+
git_exec_1.GitExec])
|
|
26
29
|
], AiBranchName);
|
|
27
30
|
//# sourceMappingURL=git-readAiBranchName.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-readAiBranchName.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-readAiBranchName.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"git-readAiBranchName.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-readAiBranchName.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,mDAA+C;AAC/C,yCAAqC;AAErC,gFAAgF;AAEzE,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEA;IACA;IAFrB,YACqB,YAA0B,EAC1B,OAAgB;QADhB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAS;IAClC,CAAC;IAEJ,mGAAmG;IACnG,gGAAgG;IAChG,kGAAkG;IAClG,KAAK,CAAC,cAAc;QAChB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxE,CAAC;CACJ,CAAA;AAbY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,4BAAY;QACjB,kBAAO;GAH5B,YAAY,CAaxB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { BranchNaming } from './branch-naming';\nimport { GitExec } from './git-exec';\n\n/** The stable feature identity used to key the merge-context + PR-body dirs. */\n@injectable(bindingScopeValues.Singleton)\nexport class AiBranchName {\n constructor(\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n ) {}\n\n // Stable feature identity used to key the merge-context dir and PR-body dir. It MUST stay constant\n // across a sync's transient `<feature>Squash` temp branch (and any leftover `…wpN` from the old\n // scheme), so derive it from baseBranchName (strips `Squash` + a legacy `wpN`) before slugifying.\n async getFeatureName(): Promise<string> {\n const branch = await this.gitExec.currentBranch(process.cwd());\n return this.branchNaming.baseBranchName(branch).replace(/\\//g, '-');\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NativeProcessApi } from '@webpieces/tooling-common';
|
|
1
2
|
import { GatedPrPublisher } from './gated-pr-publisher';
|
|
2
3
|
import { GitExec } from './git-exec';
|
|
3
4
|
/**
|
|
@@ -14,8 +15,8 @@ import { GitExec } from './git-exec';
|
|
|
14
15
|
*/
|
|
15
16
|
export declare class HotfixPrPublisher extends GatedPrPublisher {
|
|
16
17
|
private readonly hotfixGit;
|
|
17
|
-
constructor(hotfixGit: GitExec);
|
|
18
|
+
constructor(hotfixGit: GitExec, processes: NativeProcessApi);
|
|
18
19
|
/** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */
|
|
19
|
-
pushFastForward(cwd: string, branch: string): void
|
|
20
|
-
protected push(baseBranch: string): void
|
|
20
|
+
pushFastForward(cwd: string, branch: string): Promise<void>;
|
|
21
|
+
protected push(baseBranch: string): Promise<void>;
|
|
21
22
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HotfixPrPublisher = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
7
|
const inversify_1 = require("inversify");
|
|
7
8
|
const gated_pr_publisher_1 = require("./gated-pr-publisher");
|
|
8
9
|
const git_exec_1 = require("./git-exec");
|
|
@@ -20,13 +21,13 @@ const git_exec_1 = require("./git-exec");
|
|
|
20
21
|
*/
|
|
21
22
|
let HotfixPrPublisher = class HotfixPrPublisher extends gated_pr_publisher_1.GatedPrPublisher {
|
|
22
23
|
hotfixGit;
|
|
23
|
-
constructor(hotfixGit) {
|
|
24
|
-
super(hotfixGit);
|
|
24
|
+
constructor(hotfixGit, processes) {
|
|
25
|
+
super(hotfixGit, processes);
|
|
25
26
|
this.hotfixGit = hotfixGit;
|
|
26
27
|
}
|
|
27
28
|
/** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */
|
|
28
|
-
pushFastForward(cwd, branch) {
|
|
29
|
-
const out = this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);
|
|
29
|
+
async pushFastForward(cwd, branch) {
|
|
30
|
+
const out = await this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);
|
|
30
31
|
if (out.ok)
|
|
31
32
|
return;
|
|
32
33
|
throw new rules_config_1.CliExitError(1, `❌ git push of the hotfix branch '${branch}' failed (exit ${String(out.status)}). A hotfix push is\n` +
|
|
@@ -35,12 +36,12 @@ let HotfixPrPublisher = class HotfixPrPublisher extends gated_pr_publisher_1.Gat
|
|
|
35
36
|
` git said: ${out.stderr === '' ? '(nothing)' : out.stderr}`);
|
|
36
37
|
}
|
|
37
38
|
push(baseBranch) {
|
|
38
|
-
this.pushFastForward(process.cwd(), baseBranch);
|
|
39
|
+
return this.pushFastForward(process.cwd(), baseBranch);
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
exports.HotfixPrPublisher = HotfixPrPublisher;
|
|
42
43
|
exports.HotfixPrPublisher = HotfixPrPublisher = tslib_1.__decorate([
|
|
43
44
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
44
|
-
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec])
|
|
45
|
+
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec, tooling_common_1.NativeProcessApi])
|
|
45
46
|
], HotfixPrPublisher);
|
|
46
47
|
//# sourceMappingURL=hotfix-pr-publisher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hotfix-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,yCAA2D;AAC3D,6DAAwD;AACxD,yCAAqC;AAErC;;;;;;;;;;;GAWG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,qCAAgB;IACtB;IAA7B,YAA6B,SAAkB;
|
|
1
|
+
{"version":3,"file":"hotfix-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,8DAA6D;AAC7D,yCAA2D;AAC3D,6DAAwD;AACxD,yCAAqC;AAErC;;;;;;;;;;;GAWG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,qCAAgB;IACtB;IAA7B,YAA6B,SAAkB,EAAE,SAA2B;QACxE,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QADH,cAAS,GAAT,SAAS,CAAS;IAE/C,CAAC;IAED,8FAA8F;IAC9F,KAAK,CAAC,eAAe,CAAC,GAAW,EAAE,MAAc;QAC7C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;QACzF,IAAI,GAAG,CAAC,EAAE;YAAE,OAAO;QACnB,MAAM,IAAI,2BAAY,CAClB,CAAC,EACD,oCAAoC,MAAM,kBAAkB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,uBAAuB;YACjG,mGAAmG;YACnG,wBAAwB;YACxB,gBAAgB,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CACrE,CAAC;IACN,CAAC;IAEkB,IAAI,CAAC,UAAkB;QACtC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AArBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEG,kBAAO,EAAa,iCAAgB;GADnE,iBAAiB,CAqB7B","sourcesContent":["import { CliExitError } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GatedPrPublisher } from './gated-pr-publisher';\nimport { GitExec } from './git-exec';\n\n/**\n * The gated publisher for a `/hotfix/` branch: the same body-before-push ordering, with a push that can\n * NEVER rewrite the remote branch.\n *\n * The normal flow pushes with `--force-with-lease`, because its 3-point squash rewrites history on every\n * update. A hotfix branch is never rewritten — it only ever grows by the fix commits added on top of the\n * production sha — so its push is a plain fast-forward. If the remote branch has diverged (somebody else\n * pushed to it), the push FAILS instead of overwriting their commits, and nothing is lost.\n *\n * The push runs as a CHILD PROCESS of `wp-upsert-hotfix-pr`, which the PreToolUse hook never sees, so\n * `pr-creation-or-push-guard` keeps refusing every hand-typed `git push` exactly as before.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixPrPublisher extends GatedPrPublisher {\n constructor(private readonly hotfixGit: GitExec, processes: NativeProcessApi) {\n super(hotfixGit, processes);\n }\n\n /** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */\n async pushFastForward(cwd: string, branch: string): Promise<void> {\n const out = await this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);\n if (out.ok) return;\n throw new CliExitError(\n 1,\n `❌ git push of the hotfix branch '${branch}' failed (exit ${String(out.status)}). A hotfix push is\\n` +\n ' fast-forward only — it never forces — so a remote branch that has diverged is refused rather\\n' +\n ' than overwritten.\\n' +\n ` git said: ${out.stderr === '' ? '(nothing)' : out.stderr}`,\n );\n }\n\n protected override push(baseBranch: string): Promise<void> {\n return this.pushFastForward(process.cwd(), baseBranch);\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Worktree, WorktreeService } from '@webpieces/repo-workflow-core';
|
|
2
|
+
import { GitProcessApi } from '@webpieces/tooling-common';
|
|
2
3
|
/**
|
|
3
4
|
* WHICH LOCAL TREE HOLDS THE COMMIT GITHUB JUST SQUASHED — asked as a fact, answered from anywhere.
|
|
4
5
|
*
|
|
@@ -62,7 +63,8 @@ export declare class LandedTree {
|
|
|
62
63
|
}
|
|
63
64
|
export declare class LandedTreeResolver {
|
|
64
65
|
private readonly worktrees;
|
|
65
|
-
|
|
66
|
+
private readonly git;
|
|
67
|
+
constructor(worktrees: WorktreeService, git: GitProcessApi);
|
|
66
68
|
/**
|
|
67
69
|
* The four-row table this whole design exists to implement, in order of what it can prove.
|
|
68
70
|
*
|
|
@@ -70,6 +72,6 @@ export declare class LandedTreeResolver {
|
|
|
70
72
|
* into a mismatch — a fact we do not have is not evidence of disagreement — so the local tip is taken
|
|
71
73
|
* as the landed one, which is exactly what the old `ref.headRefOid !== ''` guard did.
|
|
72
74
|
*/
|
|
73
|
-
resolve(repoRoot: string, branch: string, headRefOid: string): LandedTree
|
|
75
|
+
resolve(repoRoot: string, branch: string, headRefOid: string): Promise<LandedTree>;
|
|
74
76
|
private revParse;
|
|
75
77
|
}
|