* Load local commits into memory for the current repository. * * @param branch The branch to query for unpublished commits. * @param skip The amount of commits to skip to support pagination loading of local commits. If skip is undefined, * this will reset the local commits cache and trea
(
branch: Branch | null,
skip?: number
)
| 606 | * @returns The list of commit SHAs that were ammended to the list of commits, or null if not applicable |
| 607 | */ |
| 608 | public async loadLocalCommits( |
| 609 | branch: Branch | null, |
| 610 | skip?: number |
| 611 | ): Promise<string[] | null> { |
| 612 | if (branch === null) { |
| 613 | this._localCommitSHAs = [] |
| 614 | return null |
| 615 | } |
| 616 | |
| 617 | let localCommits: ReadonlyArray<Commit> | undefined |
| 618 | if (branch.upstream) { |
| 619 | const range = revRange(branch.upstream, branch.name) |
| 620 | localCommits = await this.performFailableOperation(() => |
| 621 | getCommits(this.repository, range, CommitBatchSize, skip) |
| 622 | ) |
| 623 | } else { |
| 624 | localCommits = await this.performFailableOperation(() => |
| 625 | getCommits(this.repository, 'HEAD', CommitBatchSize, skip, [ |
| 626 | '--not', |
| 627 | '--remotes', |
| 628 | ]) |
| 629 | ) |
| 630 | } |
| 631 | |
| 632 | if (!localCommits) { |
| 633 | return null |
| 634 | } |
| 635 | |
| 636 | this.storeCommits(localCommits) |
| 637 | |
| 638 | let newCommitSHAs: string[] |
| 639 | |
| 640 | if (skip !== undefined) { |
| 641 | // perform a soft ammend to the list of local commits |
| 642 | const previousSHAs = new Set(this._localCommitSHAs) |
| 643 | newCommitSHAs = localCommits |
| 644 | .map(c => c.sha) |
| 645 | .filter(sha => !previousSHAs.has(sha)) |
| 646 | this._localCommitSHAs = [...this._localCommitSHAs, ...newCommitSHAs] |
| 647 | } else { |
| 648 | // reset the local commits since its a page reset |
| 649 | newCommitSHAs = localCommits.map(c => c.sha) |
| 650 | this._localCommitSHAs = Array.from(newCommitSHAs) |
| 651 | } |
| 652 | |
| 653 | this.emitUpdate() |
| 654 | |
| 655 | return newCommitSHAs |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * The ordered array of local commit SHAs. The commits themselves can be |
no test coverage detected