[PR #12568] fix(github): detect committed changes in branchIsDirty #14271

Open
opened 2026-02-16 18:19:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12568

State: open
Merged: No


Summary

The GitHub Action's branchIsDirty() in github/index.ts only checked git status --porcelain, which returns empty when the AI agent has already committed changes via git commit. This caused the push step to be skipped entirely, losing the commit.

Root Cause

When the AI agent commits changes during a /oc command, the working tree becomes clean (git status --porcelain returns nothing). The old branchIsDirty() incorrectly reported false, so the push was never executed.

Fix

Ported the fix from the CLI version (packages/opencode/src/cli/cmd/github.ts) to the GitHub Action version (github/index.ts):

  • Capture HEAD before AI chat begins (git rev-parse HEAD)
  • Compare HEAD after chat to detect new commits (even if working tree is clean)
  • Pass uncommittedChanges flag to push functions so they conditionally run git add . && git commit only when needed
  • Always push when dirty=true, regardless of whether changes are committed or not

This matches the behavior already implemented in the CLI version.

Testing

The fix is a direct port of the working CLI implementation. The three push paths (local PR, fork PR, issue→new branch) all now correctly handle:

  1. Uncommitted changes (existing behavior)
  2. Already-committed changes (new behavior — was broken)

Fixes #1417

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12568 **State:** open **Merged:** No --- ## Summary The GitHub Action's `branchIsDirty()` in `github/index.ts` only checked `git status --porcelain`, which returns empty when the AI agent has already committed changes via `git commit`. This caused the push step to be skipped entirely, losing the commit. ## Root Cause When the AI agent commits changes during a `/oc` command, the working tree becomes clean (`git status --porcelain` returns nothing). The old `branchIsDirty()` incorrectly reported `false`, so the push was never executed. ## Fix Ported the fix from the CLI version (`packages/opencode/src/cli/cmd/github.ts`) to the GitHub Action version (`github/index.ts`): - **Capture `HEAD`** before AI chat begins (`git rev-parse HEAD`) - **Compare `HEAD`** after chat to detect new commits (even if working tree is clean) - **Pass `uncommittedChanges` flag** to push functions so they conditionally run `git add . && git commit` only when needed - **Always push** when `dirty=true`, regardless of whether changes are committed or not This matches the behavior already implemented in the CLI version. ## Testing The fix is a direct port of the working CLI implementation. The three push paths (local PR, fork PR, issue→new branch) all now correctly handle: 1. ✅ Uncommitted changes (existing behavior) 2. ✅ Already-committed changes (new behavior — was broken) Fixes #1417
yindo added the pull-request label 2026-02-16 18:19:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14271