Skip to content

Commit

Permalink
Merge pull request #69 from tiktok/feat-improve-necessary-check
Browse files Browse the repository at this point in the history
Feat improve necessary check
  • Loading branch information
chengcyber authored May 9, 2024
2 parents 1647665 + 6daefb1 commit bdd846b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
14 changes: 10 additions & 4 deletions apps/sparo-lib/src/cli/commands/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion apps/sparo-lib/src/cli/commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Improve check logic to prevent unnecessary git operations when tracking remote branches",
"type": "none"
}
],
"packageName": "sparo"
}

0 comments on commit bdd846b

Please sign in to comment.