diff options
| author | Aiden Cline <[email protected]> | 2025-11-12 19:03:37 -0600 |
|---|---|---|
| committer | Aiden Cline <[email protected]> | 2025-11-12 19:03:46 -0600 |
| commit | 09fa84ccfc134c0fdede815e33868c9fbe256ad8 (patch) | |
| tree | 60d1e417f506d6bcf4916664aadd4fb663024008 | |
| parent | b981f0a205ea77bab5eaf3add492b6d47c4ecfc8 (diff) | |
| download | opencode-09fa84ccfc134c0fdede815e33868c9fbe256ad8.tar.gz opencode-09fa84ccfc134c0fdede815e33868c9fbe256ad8.zip | |
fix: dirty check
| -rw-r--r-- | packages/opencode/src/cli/cmd/github.ts | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/packages/opencode/src/cli/cmd/github.ts b/packages/opencode/src/cli/cmd/github.ts index 34d47ee5c..1f60e81e9 100644 --- a/packages/opencode/src/cli/cmd/github.ts +++ b/packages/opencode/src/cli/cmd/github.ts @@ -442,9 +442,10 @@ export const GithubRunCommand = cmd({ const head = (await $`git rev-parse HEAD`).stdout.toString().trim() const dataPrompt = buildPromptDataForPR(prData) const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles) - if (await branchIsDirty(head)) { + const { dirty, uncommittedChanges } = await branchIsDirty(head) + if (dirty) { const summary = await summarize(response) - await pushToLocalBranch(summary) + await pushToLocalBranch(summary, uncommittedChanges) } const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`)) await updateComment(`${response}${footer({ image: !hasShared })}`) @@ -455,9 +456,10 @@ export const GithubRunCommand = cmd({ const head = (await $`git rev-parse HEAD`).stdout.toString().trim() const dataPrompt = buildPromptDataForPR(prData) const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles) - if (await branchIsDirty(head)) { + const { dirty, uncommittedChanges } = await branchIsDirty(head) + if (dirty) { const summary = await summarize(response) - await pushToForkBranch(summary, prData) + await pushToForkBranch(summary, prData, uncommittedChanges) } const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`)) await updateComment(`${response}${footer({ image: !hasShared })}`) @@ -470,9 +472,10 @@ export const GithubRunCommand = cmd({ const issueData = await fetchIssue() const dataPrompt = buildPromptDataForIssue(issueData) const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles) - if (await branchIsDirty(head)) { + const { dirty, uncommittedChanges } = await branchIsDirty(head) + if (dirty) { const summary = await summarize(response) - await pushToNewBranch(summary, branch) + await pushToNewBranch(summary, branch, uncommittedChanges) const pr = await createPR( repoData.data.default_branch, branch, @@ -805,33 +808,39 @@ export const GithubRunCommand = cmd({ return `opencode/${type}${issueId}-${timestamp}` } - async function pushToNewBranch(summary: string, branch: string) { + async function pushToNewBranch(summary: string, branch: string, commit: boolean) { console.log("Pushing to new branch...") - await $`git add .` - await $`git commit -m "${summary} + if (commit) { + await $`git add .` + await $`git commit -m "${summary} Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"` + } await $`git push -u origin ${branch}` } - async function pushToLocalBranch(summary: string) { + async function pushToLocalBranch(summary: string, commit: boolean) { console.log("Pushing to local branch...") - await $`git add .` - await $`git commit -m "${summary} + if (commit) { + await $`git add .` + await $`git commit -m "${summary} Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"` + } await $`git push` } - async function pushToForkBranch(summary: string, pr: GitHubPullRequest) { + async function pushToForkBranch(summary: string, pr: GitHubPullRequest, commit: boolean) { console.log("Pushing to fork branch...") const remoteBranch = pr.headRefName - await $`git add .` - await $`git commit -m "${summary} + if (commit) { + await $`git add .` + await $`git commit -m "${summary} Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"` + } await $`git push fork HEAD:${remoteBranch}` } @@ -839,9 +848,17 @@ Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"` console.log("Checking if branch is dirty...") const ret = await $`git status --porcelain` const status = ret.stdout.toString().trim() - if (status.length > 0) return true + if (status.length > 0) { + return { + dirty: true, + uncommittedChanges: true, + } + } const head = await $`git rev-parse HEAD` - return head.stdout.toString().trim() !== originalHead + return { + dirty: head.stdout.toString().trim() !== originalHead, + uncommittedChanges: false, + } } async function assertPermissions() { |
