Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 6d36dbf

Browse files
authored
fix: github action dirty check (anomalyco#4262)
1 parent 4ab4baf commit 6d36dbf

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

packages/opencode/src/cli/cmd/github.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,10 @@ export const GithubRunCommand = cmd({
439439
// Local PR
440440
if (prData.headRepository.nameWithOwner === prData.baseRepository.nameWithOwner) {
441441
await checkoutLocalBranch(prData)
442+
const head = (await $`git rev-parse HEAD`).stdout.toString().trim()
442443
const dataPrompt = buildPromptDataForPR(prData)
443444
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
444-
if (await branchIsDirty()) {
445+
if (await branchIsDirty(head)) {
445446
const summary = await summarize(response)
446447
await pushToLocalBranch(summary)
447448
}
@@ -451,9 +452,10 @@ export const GithubRunCommand = cmd({
451452
// Fork PR
452453
else {
453454
await checkoutForkBranch(prData)
455+
const head = (await $`git rev-parse HEAD`).stdout.toString().trim()
454456
const dataPrompt = buildPromptDataForPR(prData)
455457
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
456-
if (await branchIsDirty()) {
458+
if (await branchIsDirty(head)) {
457459
const summary = await summarize(response)
458460
await pushToForkBranch(summary, prData)
459461
}
@@ -464,10 +466,11 @@ export const GithubRunCommand = cmd({
464466
// Issue
465467
else {
466468
const branch = await checkoutNewBranch()
469+
const head = (await $`git rev-parse HEAD`).stdout.toString().trim()
467470
const issueData = await fetchIssue()
468471
const dataPrompt = buildPromptDataForIssue(issueData)
469472
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
470-
if (await branchIsDirty()) {
473+
if (await branchIsDirty(head)) {
471474
const summary = await summarize(response)
472475
await pushToNewBranch(summary, branch)
473476
const pr = await createPR(
@@ -832,10 +835,13 @@ Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
832835
await $`git push fork HEAD:${remoteBranch}`
833836
}
834837

835-
async function branchIsDirty() {
838+
async function branchIsDirty(originalHead: string) {
836839
console.log("Checking if branch is dirty...")
837840
const ret = await $`git status --porcelain`
838-
return ret.stdout.toString().trim().length > 0
841+
const status = ret.stdout.toString().trim()
842+
if (status.length > 0) return true
843+
const head = await $`git rev-parse HEAD`
844+
return head.stdout.toString().trim() !== originalHead
839845
}
840846

841847
async function assertPermissions() {

0 commit comments

Comments
 (0)