From a6bb16889f65925c2347e300246a54f20c2bdfd7 Mon Sep 17 00:00:00 2001 From: Cheng Liu Date: Thu, 11 Jul 2024 15:08:02 -0700 Subject: [PATCH] feat: sparo fetch get aligned with git fetch --- apps/sparo-lib/src/cli/commands/fetch.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/sparo-lib/src/cli/commands/fetch.ts b/apps/sparo-lib/src/cli/commands/fetch.ts index 4f14674..974ecdb 100644 --- a/apps/sparo-lib/src/cli/commands/fetch.ts +++ b/apps/sparo-lib/src/cli/commands/fetch.ts @@ -41,13 +41,19 @@ export class FetchCommand implements ICommand { const { _gitService: gitService } = this; const { terminal } = terminalService; const repoInfo: GitRepoInfo = gitService.getRepoInfo(); - const { branch: defaultBranch } = repoInfo; + const { branch: currentBranch } = repoInfo; terminal.writeDebugLine(`got args in fetch command: ${JSON.stringify(args)}`); - const { all, branch = defaultBranch, remote = this._gitService.getBranchRemote(branch) } = args; + const { all, branch } = args; + let { remote } = args; const fetchArgs: string[] = ['fetch']; - await this._gitRemoteFetchConfigService.pruneRemoteBranchesInGitConfigAsync(remote || 'origin'); + // When no remote is specified, by default the origin remote will be used, + // unless there’s an upstream branch configured for the current branch. + remote = this._gitService.getBranchRemote(currentBranch) || 'origin'; + + this._gitRemoteFetchConfigService.addRemoteBranchIfNotExists(remote, currentBranch); + await this._gitRemoteFetchConfigService.pruneRemoteBranchesInGitConfigAsync(remote); let restoreSingleBranchCallback: (() => void) | undefined; if (all) { @@ -56,7 +62,13 @@ export class FetchCommand implements ICommand { fetchArgs.push('--all'); } else { - fetchArgs.push(remote, branch); + fetchArgs.push(remote); + if (branch) { + fetchArgs.push(branch); + } else { + // When no s appear on the command line, the refs to fetch are read from remote..fetch + // variables instead + } } gitService.executeGitCommand({ args: fetchArgs });