(options: ResolveScopeOptions = {})
| 372 | } |
| 373 | |
| 374 | export function resolveScope(options: ResolveScopeOptions = {}): ResolvedScope { |
| 375 | const refs = options.refs === undefined ? [] : options.refs; |
| 376 | if (refs.length > 2) { |
| 377 | throw new Error("Expected at most two git ref arguments."); |
| 378 | } |
| 379 | if (refs.length > 0 && (options.base !== undefined || options.compare !== undefined)) { |
| 380 | throw new Error("Cannot use --base/--compare with positional git ref arguments."); |
| 381 | } |
| 382 | if (refs.length > 0 && options.workingTreeRef !== undefined) { |
| 383 | throw new Error("Cannot use --ref with positional git ref arguments."); |
| 384 | } |
| 385 | if (options.compare !== undefined && options.workingTreeRef !== undefined) { |
| 386 | throw new Error("Cannot use --compare with --ref."); |
| 387 | } |
| 388 | |
| 389 | if (options.compare !== undefined) { |
| 390 | if (options.base === undefined) { |
| 391 | throw new Error("--compare requires --base."); |
| 392 | } |
| 393 | return resolveCommittedComparison(options.base, options.compare); |
| 394 | } |
| 395 | |
| 396 | if (refs.length === 2) { |
| 397 | const left = refs[0]; |
| 398 | const right = refs[1]; |
| 399 | if (left === undefined || right === undefined) { |
| 400 | throw new Error("Expected both base and compare refs."); |
| 401 | } |
| 402 | return resolveCommittedComparison(left, right); |
| 403 | } |
| 404 | |
| 405 | if (refs.length === 1) { |
| 406 | const ref = refs[0]; |
| 407 | if (ref === undefined) { |
| 408 | throw new Error("Expected a git ref argument."); |
| 409 | } |
| 410 | |
| 411 | const range = parseRefRange(ref); |
| 412 | if (range) return resolveCommittedComparison(range.left, range.right); |
| 413 | |
| 414 | if (!canResolveRef(ref)) { |
| 415 | const workingTreeRef = parseWorkingTreeRefArg(ref); |
| 416 | if (workingTreeRef) { |
| 417 | return resolveSingleRefScope(detectBaseRef(), workingTreeRef); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | return resolveSingleRefScope(ref); |
| 422 | } |
| 423 | |
| 424 | const base = options.base === undefined ? detectBaseRef() : options.base; |
| 425 | return resolveSingleRefScope(base, options.workingTreeRef); |
| 426 | } |
no test coverage detected