feat: improve necessary check for add fetch configs

This commit is contained in:
Cheng Liu 2024-05-08 13:27:10 -07:00
parent 16476655e4
commit 8879de5a9b
No known key found for this signature in database
GPG key ID: EEC8452F7DB85CD6
2 changed files with 11 additions and 5 deletions

View file

@ -292,10 +292,16 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
});
const remoteFetchGitConfig: string[] | undefined = result?.split('\n').filter(Boolean);
// Prevents adding the same remote branch multiple times
const targetConfig: string = `+refs/heads/${branch}:refs/remotes/${remote}/${branch}`;
if (remoteFetchGitConfig?.some((value: string) => value === targetConfig)) {
return;
if (remoteFetchGitConfig) {
const targetConfig: string = `+refs/heads/${branch}:refs/remotes/${remote}/${branch}`;
if (
// Prevents adding remote branch if it is not single branch mode
remoteFetchGitConfig.includes(`+refs/heads/*:refs/remotes/${remote}/*`) ||
// Prevents adding the same remote branch multiple times
remoteFetchGitConfig?.some((value: string) => value === targetConfig)
) {
return;
}
}
this._gitService.executeGitCommand({

View file

@ -68,7 +68,7 @@ export class FetchCommand implements ICommand<IFetchCommandOptions> {
private _revertSingleBranchIfNecessary = (remote: string): (() => void) | undefined => {
let remoteFetchGitConfig: string[] | undefined = this._getRemoteFetchGitConfig(remote);
let callback: (() => void) | undefined;
if (remoteFetchGitConfig) {
if (remoteFetchGitConfig && !remoteFetchGitConfig.includes(`+refs/heads/*:refs/remotes/${remote}/*`)) {
this._setAllBranchFetch(remote);
callback = () => {