MCPcopy Index your code
hub / github.com/anomalyco/opencode / branchIsDirty

Function branchIsDirty

packages/opencode/src/cli/cmd/github.handler.ts:1118–1139  ·  view source on GitHub ↗
(originalHead: string, expectedBranch: string)

Source from the content-addressed store, hash-verified

1116 }
1117
1118 async function branchIsDirty(originalHead: string, expectedBranch: string) {
1119 console.log("Checking if branch is dirty...")
1120 // Detect if the agent switched branches during chat (e.g. created
1121 // its own branch, committed, and possibly pushed/created a PR).
1122 const current = await gitText(["rev-parse", "--abbrev-ref", "HEAD"])
1123 if (current !== expectedBranch) {
1124 console.log(`Branch changed during chat: expected ${expectedBranch}, now on ${current}`)
1125 return { dirty: true, uncommittedChanges: false, switched: true }
1126 }
1127
1128 const ret = await gitStatus(["status", "--porcelain"])
1129 const status = ret.stdout.toString().trim()
1130 if (status.length > 0) {
1131 return { dirty: true, uncommittedChanges: true, switched: false }
1132 }
1133 const head = await gitText(["rev-parse", "HEAD"])
1134 return {
1135 dirty: head !== originalHead,
1136 uncommittedChanges: false,
1137 switched: false,
1138 }
1139 }
1140
1141 // Verify commits exist between base ref and a branch using rev-list.
1142 // Falls back to fetching from origin when local refs are missing

Callers 1

github.handler.tsFile · 0.70

Calls 3

gitTextFunction · 0.85
gitStatusFunction · 0.85
logMethod · 0.45

Tested by

no test coverage detected