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