mirror of
https://github.com/tiktok/sparo.git
synced 2024-11-14 19:35:12 -05:00
fix: duplicate add remote branch
This commit is contained in:
parent
b25a722b85
commit
331d60520e
1 changed files with 19 additions and 3 deletions
|
@ -237,9 +237,8 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
|
||||||
this._gitService.executeGitCommand({
|
this._gitService.executeGitCommand({
|
||||||
args: ['branch', branch, `${remote}/${branch}`]
|
args: ['branch', branch, `${remote}/${branch}`]
|
||||||
});
|
});
|
||||||
this._gitService.executeGitCommand({
|
|
||||||
args: ['remote', 'set-branches', '--add', remote, branch]
|
this._addRemoteBranchIfNotExists(remote, branch);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const branchExistsInLocal: boolean = Boolean(
|
const branchExistsInLocal: boolean = Boolean(
|
||||||
|
@ -279,4 +278,21 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
|
||||||
);
|
);
|
||||||
return tagExistsInLocal;
|
return tagExistsInLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _addRemoteBranchIfNotExists(remote: string, branch: string): void {
|
||||||
|
const result: string | undefined = this._gitService.getGitConfig(`remote.${remote}.fetch`, {
|
||||||
|
array: true
|
||||||
|
});
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._gitService.executeGitCommand({
|
||||||
|
args: ['remote', 'set-branches', '--add', remote, branch]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue