From ff157f90a0604521b552afaa41dd8ce9a2e468dd Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 7 Jan 2019 11:22:26 +0100 Subject: [PATCH] add unshallow as an option for git pull --- extensions/git/src/api/api1.ts | 4 ++-- extensions/git/src/api/git.d.ts | 2 +- extensions/git/src/git.ts | 14 +++++++++++--- extensions/git/src/repository.ts | 10 +++++----- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/extensions/git/src/api/api1.ts b/extensions/git/src/api/api1.ts index b1dce7dd99f..22b2a87aef1 100644 --- a/extensions/git/src/api/api1.ts +++ b/extensions/git/src/api/api1.ts @@ -172,8 +172,8 @@ export class ApiRepository implements Repository { return this._repository.fetch(remote, ref, depth); } - pull(): Promise { - return this._repository.pull(); + pull(unshallow?: boolean): Promise { + return this._repository.pull(undefined, unshallow); } push(remoteName?: string, branchName?: string, setUpstream: boolean = false): Promise { diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index 258fe303917..1a67f8e23f5 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -154,7 +154,7 @@ export interface Repository { removeRemote(name: string): Promise; fetch(remote?: string, ref?: string, depth?: number): Promise; - pull(): Promise; + pull(unshallow?: boolean): Promise; push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise; } diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index c173d9e9c3b..26f5ae804d8 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -629,6 +629,10 @@ export interface CommitOptions { empty?: boolean; } +export interface PullOptions { + unshallow?: boolean; +} + export enum ForcePushMode { Force, ForceWithLease @@ -1183,7 +1187,7 @@ export class Repository { args.push('--prune'); } - if (options.depth) { + if (typeof options.depth === 'number') { args.push(`--depth=${options.depth}`); } @@ -1200,8 +1204,12 @@ export class Repository { } } - async pull(rebase?: boolean, remote?: string, branch?: string): Promise { - const args = ['pull', '--tags', '--unshallow']; + async pull(rebase?: boolean, remote?: string, branch?: string, options: PullOptions = {}): Promise { + const args = ['pull', '--tags']; + + if (options.unshallow) { + args.push('--unshallow'); + } if (rebase) { args.push('-r'); diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 0b173f4bfd9..1fb29e03f67 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -951,7 +951,7 @@ export class Repository implements Disposable { } @throttle - async pull(head?: Branch): Promise { + async pull(head?: Branch, unshallow?: boolean): Promise { let remote: string | undefined; let branch: string | undefined; @@ -960,19 +960,19 @@ export class Repository implements Disposable { branch = `${head.upstream.name}`; } - return this.pullFrom(false, remote, branch); + return this.pullFrom(false, remote, branch, unshallow); } - async pullFrom(rebase?: boolean, remote?: string, branch?: string): Promise { + async pullFrom(rebase?: boolean, remote?: string, branch?: string, unshallow?: boolean): Promise { await this.run(Operation.Pull, async () => { await this.maybeAutoStash(async () => { const config = workspace.getConfiguration('git', Uri.file(this.root)); const fetchOnPull = config.get('fetchOnPull'); if (fetchOnPull) { - await this.repository.pull(rebase); + await this.repository.pull(rebase, undefined, undefined, { unshallow }); } else { - await this.repository.pull(rebase, remote, branch); + await this.repository.pull(rebase, remote, branch, { unshallow }); } }); });