Skip to content

Commit d5de56b

Browse files
authored
Adopt unset config (#6592)
1 parent 6f30673 commit d5de56b

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

src/api/api.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export interface Repository {
153153
* The counterpart of `getConfig`
154154
*/
155155
setConfig(key: string, value: string): Promise<string>;
156+
unsetConfig?(key: string): Promise<string>;
156157
getGlobalConfig(key: string): Promise<string>;
157158

158159
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }>;

src/github/folderRepositoryManager.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,24 +1961,27 @@ export class FolderRepositoryManager extends Disposable {
19611961
progress.report({ message: vscode.l10n.t('Deleted {0} of {1} branches', deletedBranches, totalBranches) });
19621962
};
19631963

1964-
const hideConfig = async (branch: string) => {
1964+
const deleteConfig = async (branch: string) => {
1965+
await PullRequestGitHelper.associateBaseBranchWithBranch(this.repository, branch, undefined);
19651966
await PullRequestGitHelper.associateBranchWithPullRequest(this.repository, undefined, branch);
19661967
};
19671968

1969+
// delete configs first since that can't be parallelized
1970+
for (const pick of picks) {
1971+
await deleteConfig(pick.label);
1972+
}
1973+
19681974
// batch deleting the branches to avoid consuming all available resources
19691975
await batchPromiseAll(picks, 5, async (pick) => {
19701976
try {
19711977
await this.repository.deleteBranch(pick.label, true);
19721978
if ((await PullRequestGitHelper.getMatchingPullRequestMetadataForBranch(this.repository, pick.label))) {
1973-
await hideConfig(pick.label);
1979+
console.log(`Branch ${pick.label} was not deleted`);
19741980
}
19751981
reportProgress();
19761982
} catch (e) {
19771983
if (typeof e.stderr === 'string' && e.stderr.includes('not found')) {
1978-
// TODO: The git extension API doesn't support removing configs
1979-
// If that support is added we should remove the config as it is no longer useful.
19801984
nonExistantBranches.add(pick.label);
1981-
await hideConfig(pick.label);
19821985
reportProgress();
19831986
} else if (typeof e.stderr === 'string' && e.stderr.includes('unable to access') && needsRetry) {
19841987
// There is contention for the related git files

src/github/pullRequestGitHelper.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { IResolvedPullRequestModel, PullRequestModel } from './pullRequestModel'
1717
const PullRequestRemoteMetadataKey = 'github-pr-remote';
1818
export const PullRequestMetadataKey = 'github-pr-owner-number';
1919
const BaseBranchMetadataKey = 'github-pr-base-branch';
20+
const VscodeBaseBranchMetadataKey = 'vscode-merge-base';
2021
const PullRequestBranchRegex = /branch\.(.+)\.github-pr-owner-number/;
2122
const PullRequestRemoteRegex = /branch\.(.+)\.remote/;
2223

@@ -389,7 +390,11 @@ export class PullRequestGitHelper {
389390
Logger.appendLine(`associate ${branchName} with Pull Request #${pullRequest.number}`, PullRequestGitHelper.ID);
390391
}
391392
const prConfigKey = `branch.${branchName}.${PullRequestMetadataKey}`;
392-
await repository.setConfig(prConfigKey, pullRequest ? PullRequestGitHelper.buildPullRequestMetadata(pullRequest) : ' ');
393+
if (pullRequest) {
394+
await repository.setConfig(prConfigKey, PullRequestGitHelper.buildPullRequestMetadata(pullRequest));
395+
} else if (repository.unsetConfig) {
396+
await repository.unsetConfig(prConfigKey);
397+
}
393398
} catch (e) {
394399
if (pullRequest) {
395400
Logger.error(`associate ${branchName} with Pull Request #${pullRequest.number} failed`, PullRequestGitHelper.ID);
@@ -400,16 +405,24 @@ export class PullRequestGitHelper {
400405
static async associateBaseBranchWithBranch(
401406
repository: Repository,
402407
branch: string,
403-
owner: string,
404-
repo: string,
405-
baseBranch: string
408+
base: {
409+
owner: string,
410+
repo: string,
411+
branch: string
412+
} | undefined
406413
) {
407414
try {
408-
Logger.appendLine(`associate ${branch} with base branch ${owner}/${repo}#${baseBranch}`, PullRequestGitHelper.ID);
409415
const prConfigKey = `branch.${branch}.${BaseBranchMetadataKey}`;
410-
await repository.setConfig(prConfigKey, PullRequestGitHelper.buildBaseBranchMetadata(owner, repo, baseBranch));
416+
if (base) {
417+
Logger.appendLine(`associate ${branch} with base branch ${base.owner}/${base.repo}#${base.branch}`, PullRequestGitHelper.ID);
418+
await repository.setConfig(prConfigKey, PullRequestGitHelper.buildBaseBranchMetadata(base.owner, base.repo, base.branch));
419+
} else if (repository.unsetConfig) {
420+
await repository.unsetConfig(prConfigKey);
421+
const vscodeBaseBranchConfigKey = `branch.${branch}.${VscodeBaseBranchMetadataKey}`;
422+
await repository.unsetConfig(vscodeBaseBranchConfigKey);
423+
}
411424
} catch (e) {
412-
Logger.error(`associate ${branch} with base branch ${owner}/${repo}#${baseBranch} failed`, PullRequestGitHelper.ID);
425+
Logger.error(`associate ${branch} with base branch ${base?.owner}/${base?.repo}#${base?.branch} failed`, PullRequestGitHelper.ID);
413426
}
414427
}
415428
}

src/view/reviewManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class ReviewManager extends Disposable {
201201
// For forks, we use the upstream repo if it's available. Otherwise, fallback to the fork.
202202
githubRepository = this._folderRepoManager.gitHubRepositories.find(repo => repo.remote.owner === metadata.parent?.owner?.login && repo.remote.repositoryName === metadata.parent?.name) ?? githubRepository;
203203
}
204-
return PullRequestGitHelper.associateBaseBranchWithBranch(this.repository, newHead.name, githubRepository.remote.owner, githubRepository.remote.repositoryName, oldHead.name);
204+
return PullRequestGitHelper.associateBaseBranchWithBranch(this.repository, newHead.name, { owner: githubRepository.remote.owner, repo: githubRepository.remote.repositoryName, branch: oldHead.name });
205205
}
206206
}
207207

0 commit comments

Comments
 (0)