Skip to content

Commit

Permalink
Merge pull request #90 from tiktok/fix-branch-fetch-config
Browse files Browse the repository at this point in the history
Fix branch fetch config
  • Loading branch information
chengcyber authored Sep 26, 2024
2 parents fe38729 + ee3af3d commit 0494238
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/sparo-lib/src/cli/commands/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
}
}
}
} else {
const remote: string = this._gitService.getBranchRemote(operationBranch);
this._gitRemoteFetchConfigService.addRemoteBranchIfNotExists(remote, operationBranch);
}
}

Expand Down
11 changes: 11 additions & 0 deletions apps/sparo-lib/src/services/GitRemoteFetchConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export class GitRemoteFetchConfigService {
this._gitService.executeGitCommand({
args: ['remote', 'set-branches', '--add', remote, branch]
});

// Example: branch.feature-foo.remote=origin
this._gitService.setGitConfig(`branch.${branch}.remote`, remote);
// Example: branch.feature-foo.merge=refs/heads/feature-foo
this._gitService.setGitConfig(`branch.${branch}.merge`, `refs/heads/${branch}`);
}

public pruneRemoteBranchesInGitConfigAsync = async (remote: string): Promise<void> => {
Expand Down Expand Up @@ -96,6 +101,12 @@ export class GitRemoteFetchConfigService {
this._gracefulShutdownService.registerCallback(callback);
this._setRemoteFetchInGitConfig(remote, Array.from(nextRemoteFetchConfigSet));
this._gracefulShutdownService.unregisterCallback(callback);

// Clean up other git configurations
for (const invalidBranch of invalidBranches) {
this._gitService.unsetGitConfig(`branch.${invalidBranch}.remote`);
this._gitService.unsetGitConfig(`branch.${invalidBranch}.merge`);
}
}
};

Expand Down
10 changes: 10 additions & 0 deletions common/changes/sparo/fix-branch-fetch-config_2024-09-23-22-33.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Fix git configs for tracking branch",
"type": "none"
}
],
"packageName": "sparo"
}

0 comments on commit 0494238

Please sign in to comment.