提交 28d2b5d2 编写于 作者: J Joao Moreno

wip: git api

上级 811a6be0
......@@ -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<void>;
}
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<string>;
setConfig(scope: ConfigScope, key: string, value: string): Promise<string>;
show(ref: string, path: string): Promise<string>;
getCommit(ref: string): Promise<Commit>;
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
diffWithHEAD(path: string): Promise<string>;
diffWith(ref: string, path: string): Promise<string>;
diffIndexWithHEAD(path: string): Promise<string>;
diffIndexWith(ref: string, path: string): Promise<string>;
diffBlobs(object1: string, object2: string): Promise<string>;
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
hashObject(data: string): Promise<string>;
createBranch(name: string, checkout: boolean, ref?: string): Promise<void>;
deleteBranch(name: string): Promise<void>;
getBranch(name: string): Promise<Branch>;
setBranchUpstream(name: string, upstream: string): Promise<void>;
getMergeBase(ref1: string, ref2: string): Promise<string>;
status(): Promise<void>;
checkout(treeish: string): Promise<void>;
addRemote(name: string, url: string): Promise<void>;
removeRemote(name: string): Promise<void>;
fetch(remote?: string, ref?: string): Promise<void>;
pull(): Promise<void>;
}
export interface API {
......
......@@ -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();
......
......@@ -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 })
......
......@@ -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);
......
......@@ -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<string> {
async diff(path: string, cached = false): Promise<string> {
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<string> {
const args = ['diff', `${ref1}...${ref2}`, '--', path];
const result = await this.run(args);
return result.stdout.trim();
}
async getMergeBase(ref1: string, ref2: string): Promise<string> {
const args = ['merge-base', ref1, ref2];
const result = await this.run(args);
return result.stdout.trim();
}
async add(paths: string[]): Promise<void> {
const args = ['add', '-A', '--'];
......@@ -961,8 +971,13 @@ export class Repository {
throw commitErr;
}
async branch(name: string, checkout: boolean): Promise<void> {
async branch(name: string, checkout: boolean, ref?: string): Promise<void> {
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<void> {
const args = ['branch', '--set-upstream-to', upstream, name];
await this.run(args);
}
async deleteRef(ref: string): Promise<void> {
const args = ['update-ref', '-d', ref];
await this.run(args);
......@@ -1073,7 +1093,22 @@ export class Repository {
}
}
async fetch(): Promise<void> {
async addRemote(name: string, url: string): Promise<void> {
const args = ['remote', 'add', name, url];
await this.run(args);
}
async fetch(remote?: string, ref?: string): Promise<void> {
const args = ['fetch'];
if (remote) {
args.push(remote);
if (ref) {
args.push(ref);
}
}
try {
await this.run(['fetch']);
} catch (err) {
......
......@@ -655,8 +655,8 @@ export class Repository implements Disposable {
await this.run(Operation.Status);
}
diff(path: string, options: DiffOptions = {}): Promise<string> {
return this.run(Operation.Diff, () => this.repository.diff(path, options));
diff(path: string, cached = false): Promise<string> {
return this.run(Operation.Diff, () => this.repository.diff(path, cached));
}
async add(resources: Uri[]): Promise<void> {
......@@ -746,7 +746,7 @@ export class Repository implements Disposable {
});
}
async branch(name: string): Promise<void> {
async branch(name: string, checkout: boolean, ref?: string): Promise<void> {
await this.run(Operation.Branch, () => this.repository.branch(name, true));
}
......@@ -783,7 +783,11 @@ export class Repository implements Disposable {
}
@throttle
async fetch(): Promise<void> {
async fetchDefault(): Promise<void> {
await this.run(Operation.Fetch, () => this.repository.fetch());
}
async fetch(remote?: string, ref?: string): Promise<void> {
await this.run(Operation.Fetch, () => this.repository.fetch());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册