diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index 698fcc4fb16..7d6f07a963d 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -56,21 +56,68 @@ export interface Remote { readonly isReadOnly: boolean; } +export interface Change { + // TODO +} + export interface RepositoryState { readonly HEAD: Branch | undefined; readonly refs: Ref[]; readonly remotes: Remote[]; readonly submodules: Submodule[]; readonly rebaseCommit: Commit | undefined; + + readonly mergeChanges: Change[]; + readonly indexChanges: Change[]; + readonly workingTreeChanges: Change[]; + readonly onDidChange: Event; } +export const enum ConfigScope { + System, + Global, + Local +} + export interface Repository { + readonly rootUri: Uri; readonly inputBox: InputBox; readonly state: RepositoryState; + getConfigs(scope: ConfigScope): Promise<{ key: string; value: string; }[]>; + getConfig(scope: ConfigScope, key: string): Promise; + setConfig(scope: ConfigScope, key: string, value: string): Promise; + + show(ref: string, path: string): Promise; + getCommit(ref: string): Promise; + getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>; + + diffWithHEAD(path: string): Promise; + diffWith(ref: string, path: string): Promise; + diffIndexWithHEAD(path: string): Promise; + diffIndexWith(ref: string, path: string): Promise; + diffBlobs(object1: string, object2: string): Promise; + diffBetween(ref1: string, ref2: string, path: string): Promise; + + hashObject(data: string): Promise; + + createBranch(name: string, checkout: boolean, ref?: string): Promise; + deleteBranch(name: string): Promise; + getBranch(name: string): Promise; + setBranchUpstream(name: string, upstream: string): Promise; + + getMergeBase(ref1: string, ref2: string): Promise; + status(): Promise; + checkout(treeish: string): Promise; + + addRemote(name: string, url: string): Promise; + removeRemote(name: string): Promise; + + fetch(remote?: string, ref?: string): Promise; + pull(): Promise; } export interface API { diff --git a/extensions/git/src/autofetch.ts b/extensions/git/src/autofetch.ts index 758dc82182c..3522414fb79 100644 --- a/extensions/git/src/autofetch.ts +++ b/extensions/git/src/autofetch.ts @@ -102,7 +102,7 @@ export class AutoFetcher { } try { - await this.repository.fetch(); + await this.repository.fetchDefault(); } catch (err) { if (err.gitErrorCode === GitErrorCodes.AuthenticationFailed) { this.disable(); diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 25f3bc2979e..13f6f4b687e 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1235,7 +1235,7 @@ export class CommandCenter { } const name = result.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-'); - await repository.branch(name); + await repository.branch(name, true); } @command('git.deleteBranch', { repository: true }) @@ -1355,7 +1355,7 @@ export class CommandCenter { return; } - await repository.fetch(); + await repository.fetchDefault(); } @command('git.pullFrom', { repository: true }) diff --git a/extensions/git/src/contentProvider.ts b/extensions/git/src/contentProvider.ts index 443dd774f2a..5c3dd22b1e4 100644 --- a/extensions/git/src/contentProvider.ts +++ b/extensions/git/src/contentProvider.ts @@ -92,7 +92,7 @@ export class GitContentProvider { return ''; } - return await repository.diff(path, { cached: ref === 'index' }); + return await repository.diff(path, ref === 'index'); } const repository = this.model.getRepository(uri); diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 36e7b4f53ec..f861de0393a 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -654,10 +654,6 @@ export function parseLsFiles(raw: string): LsFilesElement[] { .map(([, mode, object, stage, file]) => ({ mode, object, stage, file })); } -export interface DiffOptions { - cached?: boolean; -} - export class Repository { constructor( @@ -828,10 +824,10 @@ export class Repository { } } - async diff(path: string, options: DiffOptions = {}): Promise { + async diff(path: string, cached = false): Promise { const args = ['diff']; - if (options.cached) { + if (cached) { args.push('--cached'); } @@ -841,6 +837,20 @@ export class Repository { return result.stdout; } + async diffBetween(ref1: string, ref2: string, path: string): Promise { + const args = ['diff', `${ref1}...${ref2}`, '--', path]; + const result = await this.run(args); + + return result.stdout.trim(); + } + + async getMergeBase(ref1: string, ref2: string): Promise { + const args = ['merge-base', ref1, ref2]; + const result = await this.run(args); + + return result.stdout.trim(); + } + async add(paths: string[]): Promise { const args = ['add', '-A', '--']; @@ -961,8 +971,13 @@ export class Repository { throw commitErr; } - async branch(name: string, checkout: boolean): Promise { + async branch(name: string, checkout: boolean, ref?: string): Promise { const args = checkout ? ['checkout', '-q', '-b', name] : ['branch', '-q', name]; + + if (ref) { + args.push(ref); + } + await this.run(args); } @@ -976,6 +991,11 @@ export class Repository { await this.run(args); } + async setBranchUpstream(name: string, upstream: string): Promise { + const args = ['branch', '--set-upstream-to', upstream, name]; + await this.run(args); + } + async deleteRef(ref: string): Promise { const args = ['update-ref', '-d', ref]; await this.run(args); @@ -1073,7 +1093,22 @@ export class Repository { } } - async fetch(): Promise { + async addRemote(name: string, url: string): Promise { + const args = ['remote', 'add', name, url]; + await this.run(args); + } + + async fetch(remote?: string, ref?: string): Promise { + const args = ['fetch']; + + if (remote) { + args.push(remote); + + if (ref) { + args.push(ref); + } + } + try { await this.run(['fetch']); } catch (err) { diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 2135fa69091..d9caa7787d2 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -655,8 +655,8 @@ export class Repository implements Disposable { await this.run(Operation.Status); } - diff(path: string, options: DiffOptions = {}): Promise { - return this.run(Operation.Diff, () => this.repository.diff(path, options)); + diff(path: string, cached = false): Promise { + return this.run(Operation.Diff, () => this.repository.diff(path, cached)); } async add(resources: Uri[]): Promise { @@ -746,7 +746,7 @@ export class Repository implements Disposable { }); } - async branch(name: string): Promise { + async branch(name: string, checkout: boolean, ref?: string): Promise { await this.run(Operation.Branch, () => this.repository.branch(name, true)); } @@ -783,7 +783,11 @@ export class Repository implements Disposable { } @throttle - async fetch(): Promise { + async fetchDefault(): Promise { + await this.run(Operation.Fetch, () => this.repository.fetch()); + } + + async fetch(remote?: string, ref?: string): Promise { await this.run(Operation.Fetch, () => this.repository.fetch()); }