Merge from master to resolve a conflict

This commit is contained in:
laphets
2018-11-08 23:59:47 +08:00
1142 changed files with 21175 additions and 13633 deletions

View File

@@ -5,7 +5,7 @@
import { Model } from '../model';
import { Repository as BaseRepository, Resource } from '../repository';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, Ref, Submodule, Commit, Change, RepositoryUIState } from './git';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, Ref, Submodule, Commit, Change, RepositoryUIState, Status } from './git';
import { Event, SourceControlInputBox, Uri, SourceControl } from 'vscode';
import { mapEvent } from '../util';
@@ -17,7 +17,12 @@ class ApiInputBox implements InputBox {
export class ApiChange implements Change {
constructor(_resource: Resource) { }
get uri(): Uri { return this.resource.resourceUri; }
get originalUri(): Uri { return this.resource.original; }
get renameUri(): Uri | undefined { return this.resource.renameResourceUri; }
get status(): Status { return this.resource.type; }
constructor(private readonly resource: Resource) { }
}
export class ApiRepositoryState implements RepositoryState {
@@ -67,6 +72,18 @@ export class ApiRepository implements Repository {
return this._repository.setConfig(key, value);
}
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number; }> {
return this._repository.getObjectDetails(treeish, path);
}
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }> {
return this._repository.detectObjectType(object);
}
buffer(ref: string, filePath: string): Promise<Buffer> {
return this._repository.buffer(ref, filePath);
}
show(ref: string, path: string): Promise<string> {
return this._repository.show(ref, path);
}
@@ -75,8 +92,8 @@ export class ApiRepository implements Repository {
return this._repository.getCommit(ref);
}
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number; }> {
return this._repository.getObjectDetails(treeish, path);
clean(paths: string[]) {
return this._repository.clean(paths.map(p => Uri.file(p)));
}
diffWithHEAD(path: string): Promise<string> {
@@ -111,8 +128,8 @@ export class ApiRepository implements Repository {
return this._repository.branch(name, checkout, ref);
}
deleteBranch(name: string): Promise<void> {
return this._repository.deleteBranch(name);
deleteBranch(name: string, force?: boolean): Promise<void> {
return this._repository.deleteBranch(name, force);
}
getBranch(name: string): Promise<Branch> {
@@ -150,6 +167,10 @@ export class ApiRepository implements Repository {
pull(): Promise<void> {
return this._repository.pull();
}
push(remoteName?: string, branchName?: string, setUpstream: boolean = false): Promise<void> {
return this._repository.pushTo(remoteName, branchName, setUpstream);
}
}
export class ApiGit implements Git {

View File

@@ -6,6 +6,8 @@
import { Model } from '../model';
import { GitExtension, Repository, API } from './git';
import { ApiRepository, ApiImpl } from './api1';
import { Event, EventEmitter } from 'vscode';
import { latchEvent } from '../util';
export function deprecated(_target: any, key: string, descriptor: any): void {
if (typeof descriptor.value !== 'function') {
@@ -19,50 +21,56 @@ export function deprecated(_target: any, key: string, descriptor: any): void {
};
}
class NoModelGitExtension implements GitExtension {
export class GitExtensionImpl implements GitExtension {
enabled: boolean = false;
private _onDidChangeEnablement = new EventEmitter<boolean>();
readonly onDidChangeEnablement: Event<boolean> = latchEvent(this._onDidChangeEnablement.event);
private _model: Model | undefined = undefined;
set model(model: Model | undefined) {
this._model = model;
this.enabled = !!model;
this._onDidChangeEnablement.fire(this.enabled);
}
constructor(model?: Model) {
if (model) {
this.enabled = true;
this._model = model;
}
}
@deprecated
async getGitPath(): Promise<string> {
throw new Error('Git model not found');
}
if (!this._model) {
throw new Error('Git model not found');
}
@deprecated
async getRepositories(): Promise<Repository[]> {
throw new Error('Git model not found');
}
getAPI(): API {
throw new Error('Git model not found');
}
}
class GitExtensionImpl implements GitExtension {
constructor(private _model: Model) { }
@deprecated
async getGitPath(): Promise<string> {
return this._model.git.path;
}
@deprecated
async getRepositories(): Promise<Repository[]> {
if (!this._model) {
throw new Error('Git model not found');
}
return this._model.repositories.map(repository => new ApiRepository(repository));
}
getAPI(version: number): API {
if (!this._model) {
throw new Error('Git model not found');
}
if (version !== 1) {
throw new Error(`No API version ${version} found.`);
}
return new ApiImpl(this._model);
}
}
export function createGitExtension(model?: Model): GitExtension {
if (!model) {
return new NoModelGitExtension();
}
return new GitExtensionImpl(model);
}
}

View File

@@ -61,8 +61,38 @@ export interface Remote {
readonly isReadOnly: boolean;
}
export const enum Status {
INDEX_MODIFIED,
INDEX_ADDED,
INDEX_DELETED,
INDEX_RENAMED,
INDEX_COPIED,
MODIFIED,
DELETED,
UNTRACKED,
IGNORED,
ADDED_BY_US,
ADDED_BY_THEM,
DELETED_BY_US,
DELETED_BY_THEM,
BOTH_ADDED,
BOTH_DELETED,
BOTH_MODIFIED
}
export interface Change {
// TODO
/**
* Returns either `originalUri` or `renameUri`, depending
* on whether this change is a rename change. When
* in doubt always use `uri` over the other two alternatives.
*/
readonly uri: Uri;
readonly originalUri: Uri;
readonly renameUri: Uri | undefined;
readonly status: Status;
}
export interface RepositoryState {
@@ -95,9 +125,13 @@ export interface Repository {
getConfig(key: string): Promise<string>;
setConfig(key: string, value: string): Promise<string>;
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>;
buffer(ref: string, path: string): Promise<Buffer>;
show(ref: string, path: string): Promise<string>;
getCommit(ref: string): Promise<Commit>;
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
clean(paths: string[]): Promise<void>;
diffWithHEAD(path: string): Promise<string>;
diffWith(ref: string, path: string): Promise<string>;
@@ -109,7 +143,7 @@ export interface Repository {
hashObject(data: string): Promise<string>;
createBranch(name: string, checkout: boolean, ref?: string): Promise<void>;
deleteBranch(name: string): Promise<void>;
deleteBranch(name: string, force?: boolean): Promise<void>;
getBranch(name: string): Promise<Branch>;
setBranchUpstream(name: string, upstream: string): Promise<void>;
@@ -123,6 +157,7 @@ export interface Repository {
fetch(remote?: string, ref?: string): Promise<void>;
pull(): Promise<void>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise<void>;
}
export interface API {
@@ -134,9 +169,16 @@ export interface API {
export interface GitExtension {
readonly enabled: boolean;
readonly onDidChangeEnablement: Event<boolean>;
/**
* Returns a specific API version.
*
* Throws error if git extension is disabled. You can listed to the
* [GitExtension.onDidChangeEnablement](#GitExtension.onDidChangeEnablement) event
* to know when the extension becomes enabled/disabled.
*
* @param version Version number.
* @returns API instance
*/