Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/test/view/reviewManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,39 @@ describe('ReviewManager polling', function () {
assert.strictEqual(checkGitHubForPrBranch.called, false);
});

it('keeps an explicit pull request selected when validation overlaps its checkout', async function () {
await repository.createBranch('feature', true, 'head-sha');
let resolveUpdateRepositories!: (updated: boolean) => void;
sinon.stub(manager, 'updateRepositories').returns(new Promise<boolean>(resolve => {
resolveUpdateRepositories = resolve;
}));
const localMetadata = sinon.stub(manager, 'getMatchingPullRequestMetadataForBranch');
const requestedPullRequest = {
number: 7231,
remote: {
owner: 'owner',
repositoryName: 'repo',
},
} as PullRequestModel;
const internal = reviewManager as unknown as {
_switchedToPullRequest?: PullRequestModel;
_switchedToPullRequestBranch?: string;
validateState(silent: boolean, updateLayout: boolean): Promise<void>;
};

const validation = internal.validateState(true, false);
await flushMicrotasks();
reviewManager.switchingToReviewMode = true;
internal._switchedToPullRequest = requestedPullRequest;
internal._switchedToPullRequestBranch = undefined;
resolveUpdateRepositories(true);
await validation;

assert.strictEqual(internal._switchedToPullRequest, requestedPullRequest);
assert.strictEqual(internal._switchedToPullRequestBranch, undefined);
assert.strictEqual(localMetadata.called, false);
});

it('rechecks GitHub when active pull request metadata was not persisted', async function () {
await repository.createBranch('feature', true, 'head-sha');
sinon.stub(manager, 'updateRepositories').resolves(true);
Expand Down
5 changes: 5 additions & 0 deletions src/view/reviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ export class ReviewManager extends Disposable {
return;
}

// An explicit PR checkout is still in progress, so its destination branch is not known yet.
if (this._switchedToPullRequest && !this._switchedToPullRequestBranch && this.switchingToReviewMode) {
this._lastCommitSha = oldLastCommitSha;
return;
}
let switchedToPullRequest: PullRequestModel | undefined;
if (this._switchedToPullRequest && this._switchedToPullRequestBranch && this._switchedToPullRequestBranch === branch.name) {
switchedToPullRequest = this._switchedToPullRequest;
Expand Down