Skip to content

Commit

Permalink
fix: git configs for tracking branch
Browse files Browse the repository at this point in the history
  • Loading branch information
chengcyber committed Sep 23, 2024
1 parent fe38729 commit f07b54a
Show file tree
Hide file tree
Showing 2 changed files with 14 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

0 comments on commit f07b54a

Please sign in to comment.