Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"sparo fetch" behaves the same as "git fetch" when no remote or no branches specified #81

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions apps/sparo-lib/src/cli/commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ export class FetchCommand implements ICommand<IFetchCommandOptions> {
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) {
Expand All @@ -56,7 +62,13 @@ export class FetchCommand implements ICommand<IFetchCommandOptions> {

fetchArgs.push('--all');
} else {
fetchArgs.push(remote, branch);
fetchArgs.push(remote);
if (branch) {
fetchArgs.push(branch);
} else {
// When no <refspec>s appear on the command line, the refs to fetch are read from remote.<repository>.fetch
// variables instead
}
}

gitService.executeGitCommand({ args: fetchArgs });
Expand Down
10 changes: 10 additions & 0 deletions common/changes/sparo/feat-fetch-behavior_2024-07-11-22-08.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "\"sparo fetch\" behaves the same as \"git fetch\" when no remote or no branches specified",
"type": "none"
}
],
"packageName": "sparo"
}
Loading