|
8 | 8 | writeFileSync, |
9 | 9 | } from "node:fs"; |
10 | 10 | import { dirname, resolve } from "node:path"; |
11 | | -import { exit } from "node:process"; |
| 11 | +import { exit, stderr } from "node:process"; |
12 | 12 | import { fileURLToPath } from "node:url"; |
13 | 13 | import { promisify } from "node:util"; |
14 | 14 | import { parse } from "yaml"; |
@@ -57,7 +57,15 @@ if (!resolvedRepoPath || !existsSync(resolvedPackageJsonPath)) { |
57 | 57 |
|
58 | 58 | const promiseExec = promisify(exec); |
59 | 59 | const execInRepo = async (cmd) => { |
60 | | - const result = await promiseExec(`cd ${agentforceMessagingRepoPath}; ${cmd}`); |
| 60 | + const result = await promiseExec( |
| 61 | + `cd ${agentforceMessagingRepoPath}; ${cmd}` |
| 62 | + ).catch((err) => ({ |
| 63 | + // this typically means the command returned a non-zero code |
| 64 | + // we will simply pass the `err` object back as the result |
| 65 | + // but we will copy `stdout` to `stderr` if `stderr` is blank |
| 66 | + ...err, |
| 67 | + stderr: err.stderr || err.stdout, |
| 68 | + })); |
61 | 69 | return result; |
62 | 70 | }; |
63 | 71 |
|
@@ -143,20 +151,37 @@ const mergeResult = await execInRepo( |
143 | 151 | `git merge origin/main --no-commit --squash -s ort -X theirs` |
144 | 152 | ); |
145 | 153 | if (mergeResult.stderr) { |
146 | | - if (!mergeResult.stderr.match(/Automatic merge went well/)) { |
| 154 | + if (mergeResult.stderr.match(/CONFLICT \(modify\/delete\)/)) { |
| 155 | + // ensure we are just dealing with deletions in origin/main |
| 156 | + const statusResult = await execInRepo("git status -s | grep -E '^[UAD][UAD]'"); |
| 157 | + if (!statusResult.stdout.split(/\n/g).every((line) => !line || /^[UAD][UAD]\s/.test(line))) { |
| 158 | + console.error(`Unexpected merge conflict while merging origin/main into ${releaseBranch} branch`, statusResult.stdout, mergeResult.stderr); |
| 159 | + exit(1); |
| 160 | + } |
| 161 | + const resolveResult = await execInRepo("git status -s | grep -E '^UD ' | awk '{print $2}' | xargs git rm"); |
| 162 | + if (resolveResult.stderr) { |
| 163 | + console.error(`Unexpected error while trying to resolve deleted files during merge of origin/main into ${releaseBranch} branch`, resolveResult.stderr, mergeResult.stderr); |
| 164 | + exit(1); |
| 165 | + } |
| 166 | + const unresolvedResult = await execInRepo("git status -s | grep -E '^[UAD][UAD]'"); |
| 167 | + if (unresolvedResult.stdout || unresolvedResult.stderr) { |
| 168 | + console.error(`Unsuccessful merge of origin/main into ${releaseBranch} branch`, unresolvedResult.stdout || unresolvedResult.stderr, mergeResult.stderr); |
| 169 | + exit(1); |
| 170 | + } |
| 171 | + } else if (!mergeResult.stderr.match(/Automatic merge went well/)) { |
147 | 172 | console.error( |
148 | 173 | `Error while merging origin/main into ${releaseBranch} branch`, |
149 | 174 | mergeResult.stderr |
150 | 175 | ); |
151 | 176 | exit(1); |
152 | 177 | } |
153 | | -} |
154 | | -if (mergeResult.stdout.match(/CONFLICT/)) { |
| 178 | +} else if (mergeResult.stdout.match(/CONFLICT/)) { |
155 | 179 | console.error( |
156 | 180 | `Conflicts encountered while merging origin/main even though we specified a merge strategy to accept remote changes. A manual merge and build will be required to release version ${newVersion}.` |
157 | 181 | ); |
158 | 182 | exit(1); |
159 | 183 | } |
| 184 | + |
160 | 185 | const squashMessagePath = resolve(resolvedRepoPath, ".git/SQUASH_MSG"); |
161 | 186 | if (!existsSync(squashMessagePath)) { |
162 | 187 | console.error( |
|
0 commit comments