( repository: Repository, includeUntracked = true, rejectOnError = false )
| 205 | rejectOnError: false |
| 206 | ): Promise<IStatusResult | null> |
| 207 | export async function getStatus( |
| 208 | repository: Repository, |
| 209 | includeUntracked = true, |
| 210 | rejectOnError = false |
| 211 | ): Promise<IStatusResult | null> { |
| 212 | const args = [ |
| 213 | '--no-optional-locks', |
| 214 | 'status', |
| 215 | ...(includeUntracked ? ['--untracked-files=all'] : []), |
| 216 | '--branch', |
| 217 | '--porcelain=2', |
| 218 | '-z', |
| 219 | ] |
| 220 | |
| 221 | const { stdout, exitCode } = await git(args, repository.path, 'getStatus', { |
| 222 | successExitCodes: new Set(rejectOnError ? [0] : [0, 128]), |
| 223 | encoding: 'buffer', |
| 224 | }) |
| 225 | |
| 226 | if (exitCode === 128) { |
| 227 | log.debug( |
| 228 | `'git status' returned 128 for '${repository.path}' and is likely missing its .git directory` |
| 229 | ) |
| 230 | return null |
| 231 | } |
| 232 | |
| 233 | const parsed = parsePorcelainStatus(stdout) |
| 234 | const headers = parsed.filter(isStatusHeader) |
| 235 | const entries = parsed.filter(isStatusEntry) |
| 236 | |
| 237 | const mergeHeadFound = await isMergeHeadSet(repository) |
| 238 | const conflictedFilesInIndex = entries.filter(e => |
| 239 | conflictStatusCodes.includes(e.statusCode) |
| 240 | ) |
| 241 | const rebaseInternalState = await getRebaseInternalState(repository) |
| 242 | |
| 243 | const conflictDetails = await getConflictDetails( |
| 244 | repository, |
| 245 | mergeHeadFound, |
| 246 | conflictedFilesInIndex, |
| 247 | rebaseInternalState |
| 248 | ) |
| 249 | |
| 250 | // Map of files keyed on their paths. |
| 251 | const files = entries.reduce( |
| 252 | (files, entry) => buildStatusMap(files, entry, conflictDetails), |
| 253 | new Map<string, WorkingDirectoryFileChange>() |
| 254 | ) |
| 255 | |
| 256 | const { |
| 257 | currentBranch, |
| 258 | currentUpstreamBranch, |
| 259 | currentTip, |
| 260 | branchAheadBehind, |
| 261 | } = headers.reduce(parseStatusHeader, { |
| 262 | currentBranch: undefined, |
| 263 | currentUpstreamBranch: undefined, |
| 264 | currentTip: undefined, |
no test coverage detected