mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 17:19:01 +01:00
Git - adopt #private in Git extension API (#236444)
* Git - adopt #private in Git extension API * Fix post commit command provider
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/* eslint-disable local/code-no-native-private */
|
||||
|
||||
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, CredentialsProvider, BranchQuery, PushErrorHandler, PublishEvent, FetchOptions, RemoteSourceProvider, RemoteSourcePublisher, PostCommitCommandsProvider, RefQuery, BranchProtectionProvider, InitOptions } from './git';
|
||||
@@ -15,222 +17,242 @@ import { PickRemoteSourceOptions } from './git-base';
|
||||
import { OperationKind, OperationResult } from '../operation';
|
||||
|
||||
class ApiInputBox implements InputBox {
|
||||
set value(value: string) { this._inputBox.value = value; }
|
||||
get value(): string { return this._inputBox.value; }
|
||||
constructor(private _inputBox: SourceControlInputBox) { }
|
||||
#inputBox: SourceControlInputBox;
|
||||
|
||||
constructor(inputBox: SourceControlInputBox) { this.#inputBox = inputBox; }
|
||||
|
||||
set value(value: string) { this.#inputBox.value = value; }
|
||||
get value(): string { return this.#inputBox.value; }
|
||||
}
|
||||
|
||||
export class ApiChange implements Change {
|
||||
#resource: Resource;
|
||||
constructor(resource: Resource) { this.#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) { }
|
||||
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; }
|
||||
}
|
||||
|
||||
export class ApiRepositoryState implements RepositoryState {
|
||||
#repository: BaseRepository;
|
||||
readonly onDidChange: Event<void>;
|
||||
|
||||
get HEAD(): Branch | undefined { return this._repository.HEAD; }
|
||||
constructor(repository: BaseRepository) {
|
||||
this.#repository = repository;
|
||||
this.onDidChange = this.#repository.onDidRunGitStatus;
|
||||
}
|
||||
|
||||
get HEAD(): Branch | undefined { return this.#repository.HEAD; }
|
||||
/**
|
||||
* @deprecated Use ApiRepository.getRefs() instead.
|
||||
*/
|
||||
get refs(): Ref[] { console.warn('Deprecated. Use ApiRepository.getRefs() instead.'); return []; }
|
||||
get remotes(): Remote[] { return [...this._repository.remotes]; }
|
||||
get submodules(): Submodule[] { return [...this._repository.submodules]; }
|
||||
get rebaseCommit(): Commit | undefined { return this._repository.rebaseCommit; }
|
||||
get remotes(): Remote[] { return [...this.#repository.remotes]; }
|
||||
get submodules(): Submodule[] { return [...this.#repository.submodules]; }
|
||||
get rebaseCommit(): Commit | undefined { return this.#repository.rebaseCommit; }
|
||||
|
||||
get mergeChanges(): Change[] { return this._repository.mergeGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
get indexChanges(): Change[] { return this._repository.indexGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
get workingTreeChanges(): Change[] { return this._repository.workingTreeGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
get untrackedChanges(): Change[] { return this._repository.untrackedGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
|
||||
readonly onDidChange: Event<void> = this._repository.onDidRunGitStatus;
|
||||
|
||||
constructor(private _repository: BaseRepository) { }
|
||||
get mergeChanges(): Change[] { return this.#repository.mergeGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
get indexChanges(): Change[] { return this.#repository.indexGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
get workingTreeChanges(): Change[] { return this.#repository.workingTreeGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
get untrackedChanges(): Change[] { return this.#repository.untrackedGroup.resourceStates.map(r => new ApiChange(r)); }
|
||||
}
|
||||
|
||||
export class ApiRepositoryUIState implements RepositoryUIState {
|
||||
#sourceControl: SourceControl;
|
||||
readonly onDidChange: Event<void>;
|
||||
|
||||
get selected(): boolean { return this._sourceControl.selected; }
|
||||
constructor(sourceControl: SourceControl) {
|
||||
this.#sourceControl = sourceControl;
|
||||
this.onDidChange = mapEvent<boolean, void>(this.#sourceControl.onDidChangeSelection, () => null);
|
||||
}
|
||||
|
||||
readonly onDidChange: Event<void> = mapEvent<boolean, void>(this._sourceControl.onDidChangeSelection, () => null);
|
||||
|
||||
constructor(private _sourceControl: SourceControl) { }
|
||||
get selected(): boolean { return this.#sourceControl.selected; }
|
||||
}
|
||||
|
||||
export class ApiRepository implements Repository {
|
||||
|
||||
readonly rootUri: Uri = Uri.file(this.repository.root);
|
||||
readonly inputBox: InputBox = new ApiInputBox(this.repository.inputBox);
|
||||
readonly state: RepositoryState = new ApiRepositoryState(this.repository);
|
||||
readonly ui: RepositoryUIState = new ApiRepositoryUIState(this.repository.sourceControl);
|
||||
#repository: BaseRepository;
|
||||
|
||||
readonly onDidCommit: Event<void> = mapEvent<OperationResult, void>(
|
||||
filterEvent(this.repository.onDidRunOperation, e => e.operation.kind === OperationKind.Commit), () => null);
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
readonly state: RepositoryState;
|
||||
readonly ui: RepositoryUIState;
|
||||
|
||||
readonly onDidCheckout: Event<void> = mapEvent<OperationResult, void>(
|
||||
filterEvent(this.repository.onDidRunOperation, e => e.operation.kind === OperationKind.Checkout || e.operation.kind === OperationKind.CheckoutTracking), () => null);
|
||||
readonly onDidCommit: Event<void>;
|
||||
readonly onDidCheckout: Event<void>;
|
||||
|
||||
constructor(readonly repository: BaseRepository) { }
|
||||
constructor(repository: BaseRepository) {
|
||||
this.#repository = repository;
|
||||
|
||||
this.rootUri = Uri.file(this.#repository.root);
|
||||
this.inputBox = new ApiInputBox(this.#repository.inputBox);
|
||||
this.state = new ApiRepositoryState(this.#repository);
|
||||
this.ui = new ApiRepositoryUIState(this.#repository.sourceControl);
|
||||
|
||||
this.onDidCommit = mapEvent<OperationResult, void>(
|
||||
filterEvent(this.#repository.onDidRunOperation, e => e.operation.kind === OperationKind.Commit), () => null);
|
||||
this.onDidCheckout = mapEvent<OperationResult, void>(
|
||||
filterEvent(this.#repository.onDidRunOperation, e => e.operation.kind === OperationKind.Checkout || e.operation.kind === OperationKind.CheckoutTracking), () => null);
|
||||
}
|
||||
|
||||
apply(patch: string, reverse?: boolean): Promise<void> {
|
||||
return this.repository.apply(patch, reverse);
|
||||
return this.#repository.apply(patch, reverse);
|
||||
}
|
||||
|
||||
getConfigs(): Promise<{ key: string; value: string }[]> {
|
||||
return this.repository.getConfigs();
|
||||
return this.#repository.getConfigs();
|
||||
}
|
||||
|
||||
getConfig(key: string): Promise<string> {
|
||||
return this.repository.getConfig(key);
|
||||
return this.#repository.getConfig(key);
|
||||
}
|
||||
|
||||
setConfig(key: string, value: string): Promise<string> {
|
||||
return this.repository.setConfig(key, value);
|
||||
return this.#repository.setConfig(key, value);
|
||||
}
|
||||
|
||||
getGlobalConfig(key: string): Promise<string> {
|
||||
return this.repository.getGlobalConfig(key);
|
||||
return this.#repository.getGlobalConfig(key);
|
||||
}
|
||||
|
||||
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }> {
|
||||
return this.repository.getObjectDetails(treeish, path);
|
||||
return this.#repository.getObjectDetails(treeish, path);
|
||||
}
|
||||
|
||||
detectObjectType(object: string): Promise<{ mimetype: string; encoding?: string }> {
|
||||
return this.repository.detectObjectType(object);
|
||||
return this.#repository.detectObjectType(object);
|
||||
}
|
||||
|
||||
buffer(ref: string, filePath: string): Promise<Buffer> {
|
||||
return this.repository.buffer(ref, filePath);
|
||||
return this.#repository.buffer(ref, filePath);
|
||||
}
|
||||
|
||||
show(ref: string, path: string): Promise<string> {
|
||||
return this.repository.show(ref, path);
|
||||
return this.#repository.show(ref, path);
|
||||
}
|
||||
|
||||
getCommit(ref: string): Promise<Commit> {
|
||||
return this.repository.getCommit(ref);
|
||||
return this.#repository.getCommit(ref);
|
||||
}
|
||||
|
||||
add(paths: string[]) {
|
||||
return this.repository.add(paths.map(p => Uri.file(p)));
|
||||
return this.#repository.add(paths.map(p => Uri.file(p)));
|
||||
}
|
||||
|
||||
revert(paths: string[]) {
|
||||
return this.repository.revert(paths.map(p => Uri.file(p)));
|
||||
return this.#repository.revert(paths.map(p => Uri.file(p)));
|
||||
}
|
||||
|
||||
clean(paths: string[]) {
|
||||
return this.repository.clean(paths.map(p => Uri.file(p)));
|
||||
return this.#repository.clean(paths.map(p => Uri.file(p)));
|
||||
}
|
||||
|
||||
diff(cached?: boolean) {
|
||||
return this.repository.diff(cached);
|
||||
return this.#repository.diff(cached);
|
||||
}
|
||||
|
||||
diffWithHEAD(): Promise<Change[]>;
|
||||
diffWithHEAD(path: string): Promise<string>;
|
||||
diffWithHEAD(path?: string): Promise<string | Change[]> {
|
||||
return this.repository.diffWithHEAD(path);
|
||||
return this.#repository.diffWithHEAD(path);
|
||||
}
|
||||
|
||||
diffWith(ref: string): Promise<Change[]>;
|
||||
diffWith(ref: string, path: string): Promise<string>;
|
||||
diffWith(ref: string, path?: string): Promise<string | Change[]> {
|
||||
return this.repository.diffWith(ref, path);
|
||||
return this.#repository.diffWith(ref, path);
|
||||
}
|
||||
|
||||
diffIndexWithHEAD(): Promise<Change[]>;
|
||||
diffIndexWithHEAD(path: string): Promise<string>;
|
||||
diffIndexWithHEAD(path?: string): Promise<string | Change[]> {
|
||||
return this.repository.diffIndexWithHEAD(path);
|
||||
return this.#repository.diffIndexWithHEAD(path);
|
||||
}
|
||||
|
||||
diffIndexWith(ref: string): Promise<Change[]>;
|
||||
diffIndexWith(ref: string, path: string): Promise<string>;
|
||||
diffIndexWith(ref: string, path?: string): Promise<string | Change[]> {
|
||||
return this.repository.diffIndexWith(ref, path);
|
||||
return this.#repository.diffIndexWith(ref, path);
|
||||
}
|
||||
|
||||
diffBlobs(object1: string, object2: string): Promise<string> {
|
||||
return this.repository.diffBlobs(object1, object2);
|
||||
return this.#repository.diffBlobs(object1, object2);
|
||||
}
|
||||
|
||||
diffBetween(ref1: string, ref2: string): Promise<Change[]>;
|
||||
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
|
||||
diffBetween(ref1: string, ref2: string, path?: string): Promise<string | Change[]> {
|
||||
return this.repository.diffBetween(ref1, ref2, path);
|
||||
return this.#repository.diffBetween(ref1, ref2, path);
|
||||
}
|
||||
|
||||
hashObject(data: string): Promise<string> {
|
||||
return this.repository.hashObject(data);
|
||||
return this.#repository.hashObject(data);
|
||||
}
|
||||
|
||||
createBranch(name: string, checkout: boolean, ref?: string | undefined): Promise<void> {
|
||||
return this.repository.branch(name, checkout, ref);
|
||||
return this.#repository.branch(name, checkout, ref);
|
||||
}
|
||||
|
||||
deleteBranch(name: string, force?: boolean): Promise<void> {
|
||||
return this.repository.deleteBranch(name, force);
|
||||
return this.#repository.deleteBranch(name, force);
|
||||
}
|
||||
|
||||
getBranch(name: string): Promise<Branch> {
|
||||
return this.repository.getBranch(name);
|
||||
return this.#repository.getBranch(name);
|
||||
}
|
||||
|
||||
getBranches(query: BranchQuery, cancellationToken?: CancellationToken): Promise<Ref[]> {
|
||||
return this.repository.getBranches(query, cancellationToken);
|
||||
return this.#repository.getBranches(query, cancellationToken);
|
||||
}
|
||||
|
||||
getBranchBase(name: string): Promise<Branch | undefined> {
|
||||
return this.repository.getBranchBase(name);
|
||||
return this.#repository.getBranchBase(name);
|
||||
}
|
||||
|
||||
setBranchUpstream(name: string, upstream: string): Promise<void> {
|
||||
return this.repository.setBranchUpstream(name, upstream);
|
||||
return this.#repository.setBranchUpstream(name, upstream);
|
||||
}
|
||||
|
||||
getRefs(query: RefQuery, cancellationToken?: CancellationToken): Promise<Ref[]> {
|
||||
return this.repository.getRefs(query, cancellationToken);
|
||||
return this.#repository.getRefs(query, cancellationToken);
|
||||
}
|
||||
|
||||
checkIgnore(paths: string[]): Promise<Set<string>> {
|
||||
return this.repository.checkIgnore(paths);
|
||||
return this.#repository.checkIgnore(paths);
|
||||
}
|
||||
|
||||
getMergeBase(ref1: string, ref2: string): Promise<string | undefined> {
|
||||
return this.repository.getMergeBase(ref1, ref2);
|
||||
return this.#repository.getMergeBase(ref1, ref2);
|
||||
}
|
||||
|
||||
tag(name: string, message: string, ref?: string | undefined): Promise<void> {
|
||||
return this.repository.tag({ name, message, ref });
|
||||
return this.#repository.tag({ name, message, ref });
|
||||
}
|
||||
|
||||
deleteTag(name: string): Promise<void> {
|
||||
return this.repository.deleteTag(name);
|
||||
return this.#repository.deleteTag(name);
|
||||
}
|
||||
|
||||
status(): Promise<void> {
|
||||
return this.repository.status();
|
||||
return this.#repository.status();
|
||||
}
|
||||
|
||||
checkout(treeish: string): Promise<void> {
|
||||
return this.repository.checkout(treeish);
|
||||
return this.#repository.checkout(treeish);
|
||||
}
|
||||
|
||||
addRemote(name: string, url: string): Promise<void> {
|
||||
return this.repository.addRemote(name, url);
|
||||
return this.#repository.addRemote(name, url);
|
||||
}
|
||||
|
||||
removeRemote(name: string): Promise<void> {
|
||||
return this.repository.removeRemote(name);
|
||||
return this.#repository.removeRemote(name);
|
||||
}
|
||||
|
||||
renameRemote(name: string, newName: string): Promise<void> {
|
||||
return this.repository.renameRemote(name, newName);
|
||||
return this.#repository.renameRemote(name, newName);
|
||||
}
|
||||
|
||||
fetch(arg0?: FetchOptions | string | undefined,
|
||||
@@ -239,86 +261,92 @@ export class ApiRepository implements Repository {
|
||||
prune?: boolean | undefined
|
||||
): Promise<void> {
|
||||
if (arg0 !== undefined && typeof arg0 !== 'string') {
|
||||
return this.repository.fetch(arg0);
|
||||
return this.#repository.fetch(arg0);
|
||||
}
|
||||
|
||||
return this.repository.fetch({ remote: arg0, ref, depth, prune });
|
||||
return this.#repository.fetch({ remote: arg0, ref, depth, prune });
|
||||
}
|
||||
|
||||
pull(unshallow?: boolean): Promise<void> {
|
||||
return this.repository.pull(undefined, unshallow);
|
||||
return this.#repository.pull(undefined, unshallow);
|
||||
}
|
||||
|
||||
push(remoteName?: string, branchName?: string, setUpstream: boolean = false, force?: ForcePushMode): Promise<void> {
|
||||
return this.repository.pushTo(remoteName, branchName, setUpstream, force);
|
||||
return this.#repository.pushTo(remoteName, branchName, setUpstream, force);
|
||||
}
|
||||
|
||||
blame(path: string): Promise<string> {
|
||||
return this.repository.blame(path);
|
||||
return this.#repository.blame(path);
|
||||
}
|
||||
|
||||
log(options?: LogOptions): Promise<Commit[]> {
|
||||
return this.repository.log(options);
|
||||
return this.#repository.log(options);
|
||||
}
|
||||
|
||||
commit(message: string, opts?: CommitOptions): Promise<void> {
|
||||
return this.repository.commit(message, { ...opts, postCommitCommand: null });
|
||||
return this.#repository.commit(message, { ...opts, postCommitCommand: null });
|
||||
}
|
||||
|
||||
merge(ref: string): Promise<void> {
|
||||
return this.repository.merge(ref);
|
||||
return this.#repository.merge(ref);
|
||||
}
|
||||
|
||||
mergeAbort(): Promise<void> {
|
||||
return this.repository.mergeAbort();
|
||||
return this.#repository.mergeAbort();
|
||||
}
|
||||
|
||||
applyStash(index?: number): Promise<void> {
|
||||
return this.repository.applyStash(index);
|
||||
return this.#repository.applyStash(index);
|
||||
}
|
||||
|
||||
popStash(index?: number): Promise<void> {
|
||||
return this.repository.popStash(index);
|
||||
return this.#repository.popStash(index);
|
||||
}
|
||||
|
||||
dropStash(index?: number): Promise<void> {
|
||||
return this.repository.dropStash(index);
|
||||
return this.#repository.dropStash(index);
|
||||
}
|
||||
}
|
||||
|
||||
export class ApiGit implements Git {
|
||||
#model: Model;
|
||||
|
||||
get path(): string { return this._model.git.path; }
|
||||
constructor(model: Model) { this.#model = model; }
|
||||
|
||||
constructor(private _model: Model) { }
|
||||
get path(): string { return this.#model.git.path; }
|
||||
}
|
||||
|
||||
export class ApiImpl implements API {
|
||||
#model: Model;
|
||||
readonly git: ApiGit;
|
||||
|
||||
readonly git = new ApiGit(this._model);
|
||||
constructor(model: Model) {
|
||||
this.#model = model;
|
||||
this.git = new ApiGit(this.#model);
|
||||
}
|
||||
|
||||
get state(): APIState {
|
||||
return this._model.state;
|
||||
return this.#model.state;
|
||||
}
|
||||
|
||||
get onDidChangeState(): Event<APIState> {
|
||||
return this._model.onDidChangeState;
|
||||
return this.#model.onDidChangeState;
|
||||
}
|
||||
|
||||
get onDidPublish(): Event<PublishEvent> {
|
||||
return this._model.onDidPublish;
|
||||
return this.#model.onDidPublish;
|
||||
}
|
||||
|
||||
get onDidOpenRepository(): Event<Repository> {
|
||||
return mapEvent(this._model.onDidOpenRepository, r => new ApiRepository(r));
|
||||
return mapEvent(this.#model.onDidOpenRepository, r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
get onDidCloseRepository(): Event<Repository> {
|
||||
return mapEvent(this._model.onDidCloseRepository, r => new ApiRepository(r));
|
||||
return mapEvent(this.#model.onDidCloseRepository, r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
get repositories(): Repository[] {
|
||||
return this._model.repositories.map(r => new ApiRepository(r));
|
||||
return this.#model.repositories.map(r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
toGitUri(uri: Uri, ref: string): Uri {
|
||||
@@ -326,14 +354,14 @@ export class ApiImpl implements API {
|
||||
}
|
||||
|
||||
getRepository(uri: Uri): Repository | null {
|
||||
const result = this._model.getRepository(uri);
|
||||
const result = this.#model.getRepository(uri);
|
||||
return result ? new ApiRepository(result) : null;
|
||||
}
|
||||
|
||||
async init(root: Uri, options?: InitOptions): Promise<Repository | null> {
|
||||
const path = root.fsPath;
|
||||
await this._model.git.init(path, options);
|
||||
await this._model.openRepository(path);
|
||||
await this.#model.git.init(path, options);
|
||||
await this.#model.openRepository(path);
|
||||
return this.getRepository(root) || null;
|
||||
}
|
||||
|
||||
@@ -342,7 +370,7 @@ export class ApiImpl implements API {
|
||||
return null;
|
||||
}
|
||||
|
||||
await this._model.openRepository(root.fsPath);
|
||||
await this.#model.openRepository(root.fsPath);
|
||||
return this.getRepository(root) || null;
|
||||
}
|
||||
|
||||
@@ -350,7 +378,7 @@ export class ApiImpl implements API {
|
||||
const disposables: Disposable[] = [];
|
||||
|
||||
if (provider.publishRepository) {
|
||||
disposables.push(this._model.registerRemoteSourcePublisher(provider as RemoteSourcePublisher));
|
||||
disposables.push(this.#model.registerRemoteSourcePublisher(provider as RemoteSourcePublisher));
|
||||
}
|
||||
disposables.push(GitBaseApi.getAPI().registerRemoteSourceProvider(provider));
|
||||
|
||||
@@ -358,26 +386,24 @@ export class ApiImpl implements API {
|
||||
}
|
||||
|
||||
registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable {
|
||||
return this._model.registerRemoteSourcePublisher(publisher);
|
||||
return this.#model.registerRemoteSourcePublisher(publisher);
|
||||
}
|
||||
|
||||
registerCredentialsProvider(provider: CredentialsProvider): Disposable {
|
||||
return this._model.registerCredentialsProvider(provider);
|
||||
return this.#model.registerCredentialsProvider(provider);
|
||||
}
|
||||
|
||||
registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable {
|
||||
return this._model.registerPostCommitCommandsProvider(provider);
|
||||
return this.#model.registerPostCommitCommandsProvider(provider);
|
||||
}
|
||||
|
||||
registerPushErrorHandler(handler: PushErrorHandler): Disposable {
|
||||
return this._model.registerPushErrorHandler(handler);
|
||||
return this.#model.registerPushErrorHandler(handler);
|
||||
}
|
||||
|
||||
registerBranchProtectionProvider(root: Uri, provider: BranchProtectionProvider): Disposable {
|
||||
return this._model.registerBranchProtectionProvider(root, provider);
|
||||
return this.#model.registerBranchProtectionProvider(root, provider);
|
||||
}
|
||||
|
||||
constructor(private _model: Model) { }
|
||||
}
|
||||
|
||||
function getRefType(type: RefType): string {
|
||||
|
||||
Reference in New Issue
Block a user