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

Add 'prune' option to fetch in git extension API #117923

Merged
merged 2 commits into from Mar 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions extensions/git/src/api/api1.ts
Expand Up @@ -5,7 +5,7 @@

import { Model } from '../model';
import { Repository as BaseRepository, Resource } from '../repository';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, ForcePushMode, Ref, Submodule, Commit, Change, RepositoryUIState, Status, LogOptions, APIState, CommitOptions, RefType, RemoteSourceProvider, CredentialsProvider, BranchQuery, PushErrorHandler, PublishEvent } from './git';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, ForcePushMode, Ref, Submodule, Commit, Change, RepositoryUIState, Status, LogOptions, APIState, CommitOptions, RefType, RemoteSourceProvider, CredentialsProvider, BranchQuery, PushErrorHandler, PublishEvent, FetchOptions } from './git';
import { Event, SourceControlInputBox, Uri, SourceControl, Disposable, commands } from 'vscode';
import { mapEvent } from '../util';
import { toGitUri } from '../uri';
Expand Down Expand Up @@ -193,8 +193,16 @@ export class ApiRepository implements Repository {
return this._repository.renameRemote(name, newName);
}

fetch(remote?: string | undefined, ref?: string | undefined, depth?: number | undefined): Promise<void> {
return this._repository.fetch(remote, ref, depth);
fetch(arg0?: FetchOptions | string | undefined,
ref?: string | undefined,
depth?: number | undefined,
prune?: boolean | undefined
): Promise<void> {
if (arg0 !== undefined && typeof arg0 !== 'string') {
return this._repository.fetch(arg0);
}

return this._repository.fetch({ remote: arg0, ref, depth, prune });
}

pull(unshallow?: boolean): Promise<void> {
Expand Down
9 changes: 9 additions & 0 deletions extensions/git/src/api/git.d.ts
Expand Up @@ -139,6 +139,14 @@ export interface CommitOptions {
requireUserConfig?: boolean;
}

export interface FetchOptions {
remote?: string;
ref?: string;
all?: boolean;
prune?: boolean;
depth?: number;
}

export interface BranchQuery {
readonly remote?: boolean;
readonly pattern?: string;
Expand Down Expand Up @@ -197,6 +205,7 @@ export interface Repository {
removeRemote(name: string): Promise<void>;
renameRemote(name: string, newName: string): Promise<void>;

fetch(options?: FetchOptions): Promise<void>;
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
pull(unshallow?: boolean): Promise<void>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/src/commands.ts
Expand Up @@ -2247,7 +2247,7 @@ export class CommandCenter {
}

await repository.addRemote(name, url);
await repository.fetch(name);
await repository.fetch({ remote: name });
return name;
}

Expand Down
6 changes: 3 additions & 3 deletions extensions/git/src/repository.ts
Expand Up @@ -7,7 +7,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { CancellationToken, Command, Disposable, Event, EventEmitter, Memento, OutputChannel, ProgressLocation, ProgressOptions, scm, SourceControl, SourceControlInputBox, SourceControlInputBoxValidation, SourceControlInputBoxValidationType, SourceControlResourceDecorations, SourceControlResourceGroup, SourceControlResourceState, ThemeColor, Uri, window, workspace, WorkspaceEdit, FileDecoration, commands } from 'vscode';
import * as nls from 'vscode-nls';
import { Branch, Change, ForcePushMode, GitErrorCodes, LogOptions, Ref, RefType, Remote, Status, CommitOptions, BranchQuery } from './api/git';
import { Branch, Change, ForcePushMode, GitErrorCodes, LogOptions, Ref, RefType, Remote, Status, CommitOptions, BranchQuery, FetchOptions } from './api/git';
import { AutoFetcher } from './autofetch';
import { debounce, memoize, throttle } from './decorators';
import { Commit, GitError, Repository as BaseRepository, Stash, Submodule, LogFileOptions } from './git';
Expand Down Expand Up @@ -1319,8 +1319,8 @@ export class Repository implements Disposable {
await this._fetch({ all: true });
}

async fetch(remote?: string, ref?: string, depth?: number): Promise<void> {
await this._fetch({ remote, ref, depth });
async fetch(options: FetchOptions): Promise<void> {
await this._fetch(options);
}

private async _fetch(options: { remote?: string, ref?: string, all?: boolean, prune?: boolean, depth?: number, silent?: boolean; } = {}): Promise<void> {
Expand Down