Skip to content

Commit

Permalink
Fixes timing issue with deep link switch check
Browse files Browse the repository at this point in the history
  • Loading branch information
axosoft-ramint committed Aug 23, 2024
1 parent d659c10 commit 63152d8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/uris/deepLinks/deepLinkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getBranchNameWithoutRemote } from '../../git/models/branch';
import type { GitCommit } from '../../git/models/commit';
import type { GitReference } from '../../git/models/reference';
import { createReference, isSha } from '../../git/models/reference';
import type { RepositoryChangeEvent } from '../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../git/models/repository';
import type { GitTag } from '../../git/models/tag';
import { parseGitRemoteUrl } from '../../git/parsers/remoteParser';
import type { RepositoryIdentity } from '../../gk/models/repositoryIdentities';
Expand Down Expand Up @@ -1337,7 +1339,22 @@ export class DeepLinkService implements Disposable {

// Only proceed if the branch switch occurred in the current window. This is necessary because the switch flow may
// open a new window, and if it does, we need to end things here.
if ((await repo.getBranch())?.name === this._context.currentBranch) {
const didChangeBranch = await Promise.race([
new Promise<boolean>(resolve => setTimeout(() => resolve(false), 10000)),
new Promise<boolean>(resolve =>
once(repo.onDidChange)(async (e: RepositoryChangeEvent) => {
if (e.changed(RepositoryChange.Head, RepositoryChangeComparisonMode.Any)) {
if ((await repo.getBranch())?.name !== this._context.currentBranch) {
resolve(true);
} else {
resolve(false);
}
}
}),
),
]);

if (!didChangeBranch) {
action = DeepLinkServiceAction.DeepLinkResolved;
break;
}
Expand Down

0 comments on commit 63152d8

Please sign in to comment.