MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / hasWorktreeChanges

Function hasWorktreeChanges

source code/utils/worktree.ts:1146–1175  ·  view source on GitHub ↗
(
  worktreePath: string,
  headCommit: string,
)

Source from the content-addressed store, hash-verified

1144 * — callers use this to decide whether to remove a worktree, so fail-closed.
1145 */
1146export async function hasWorktreeChanges(
1147 worktreePath: string,
1148 headCommit: string,
1149): Promise<boolean> {
1150 const { code: statusCode, stdout: statusOutput } =
1151 await execFileNoThrowWithCwd(gitExe(), ['status', '--porcelain'], {
1152 cwd: worktreePath,
1153 })
1154 if (statusCode !== 0) {
1155 return true
1156 }
1157 if (statusOutput.trim().length > 0) {
1158 return true
1159 }
1160
1161 const { code: revListCode, stdout: revListOutput } =
1162 await execFileNoThrowWithCwd(
1163 gitExe(),
1164 ['rev-list', '--count', `${headCommit}..HEAD`],
1165 { cwd: worktreePath },
1166 )
1167 if (revListCode !== 0) {
1168 return true
1169 }
1170 if (parseInt(revListOutput.trim(), 10) > 0) {
1171 return true
1172 }
1173
1174 return false
1175}
1176
1177/**
1178 * Fast-path handler for --worktree --tmux.

Callers 1

cleanupWorktreeIfNeededFunction · 0.85

Calls 1

execFileNoThrowWithCwdFunction · 0.85

Tested by

no test coverage detected