( worktreePath: string, headCommit: string, )
| 1144 | * — callers use this to decide whether to remove a worktree, so fail-closed. |
| 1145 | */ |
| 1146 | export 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. |
no test coverage detected