Skip to content

Commit

Permalink
Updates wip tracking when not in commit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 committed May 10, 2024
1 parent 6329df5 commit 7df3ace
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/webviews/commitDetails/commitDetailsWebview.ts
Expand Up @@ -948,9 +948,6 @@ export class CommitDetailsWebviewProvider
private async setMode(mode: Mode, repository?: Repository): Promise<void> {
this.updatePendingContext({ mode: mode });
if (mode === 'commit') {
this._wipSubscription?.subscription.dispose();
this._wipSubscription = undefined;

this.updateState(true);
} else {
await this.updateWipState(repository ?? this.container.git.getBestRepositoryOrFirst());
Expand Down Expand Up @@ -1028,6 +1025,18 @@ export class CommitDetailsWebviewProvider
}
}

const wip = current.wip;
if (wip == null && this._repositorySubscription) {
if (this._cancellationTokenSource == null) {
this._cancellationTokenSource = new CancellationTokenSource();
}
const cancellation = this._cancellationTokenSource.token;
setTimeout(() => {
if (cancellation.isCancellationRequested) return;
void this.updateWipState(this._repositorySubscription?.repo);
}, 100);
}

const state = serialize<State>({
...this.host.baseWebviewState,
mode: current.mode,
Expand All @@ -1038,7 +1047,7 @@ export class CommitDetailsWebviewProvider
includeRichContent: current.richStateLoaded,
autolinkedIssues: current.autolinkedIssues?.map(serializeIssueOrPullRequest),
pullRequest: current.pullRequest != null ? serializePullRequest(current.pullRequest) : undefined,
wip: serializeWipContext(current.wip),
wip: serializeWipContext(wip),
orgSettings: current.orgSettings,
inReview: current.inReview,
});
Expand Down Expand Up @@ -1081,7 +1090,7 @@ export class CommitDetailsWebviewProvider
}
}

if (wip.pullRequest?.state != 'opened') {
if (wip.pullRequest?.state !== 'opened') {
inReview = false;
}

Expand Down Expand Up @@ -1123,6 +1132,14 @@ export class CommitDetailsWebviewProvider
const branch = await repository.getBranch(branchName);
if (branch == null) return undefined;

if (this.mode === 'commit') {
return {
branch: branch,
pullRequest: undefined,
codeSuggestions: [],
};
}

const pullRequest = await branch.getAssociatedPullRequest({
expiryOverride: 1000 * 60 * 5, // 5 minutes
});
Expand Down Expand Up @@ -1645,6 +1662,8 @@ export class CommitDetailsWebviewProvider
}

private switchMode(params: SwitchModeParams) {
if (this.mode === params.mode) return;

let repo;
if (params.mode === 'wip') {
let { repoPath } = params;
Expand Down

0 comments on commit 7df3ace

Please sign in to comment.