Merge pull request #69 from tiktok/feat-improve-necessary-check

Feat improve necessary check
This commit is contained in:
Cheng Liu 2024-05-09 15:46:06 -07:00 committed by GitHub
commit bdd846b17a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 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 = () => {

View file

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Improve check logic to prevent unnecessary git operations when tracking remote branches",
"type": "none"
}
],
"packageName": "sparo"
}