mirror of
https://github.com/Microsoft/vscode
synced 2024-10-31 01:12:58 +00:00
git api: repository state
This commit is contained in:
parent
2c43eaebec
commit
6d2598ad88
6 changed files with 72 additions and 40 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { Model } from '../model';
|
||||
import { Repository as BaseRepository } from '../repository';
|
||||
import { InputBox, Git, API, Repository, Remote } from './git';
|
||||
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, Ref, Submodule, Commit } from './git';
|
||||
import { Event, SourceControlInputBox, Uri } from 'vscode';
|
||||
import { mapEvent } from '../util';
|
||||
|
||||
|
@ -17,13 +17,24 @@ class ApiInputBox implements InputBox {
|
|||
constructor(private _inputBox: SourceControlInputBox) { }
|
||||
}
|
||||
|
||||
export class ApiRepositoryState implements RepositoryState {
|
||||
|
||||
get HEAD(): Branch | undefined { return this._repository.HEAD; }
|
||||
get refs(): Ref[] { return [...this._repository.refs]; }
|
||||
get remotes(): Remote[] { return [...this._repository.remotes]; }
|
||||
get submodules(): Submodule[] { return [...this._repository.submodules]; }
|
||||
get rebaseCommit(): Commit | undefined { return this._repository.rebaseCommit; }
|
||||
|
||||
readonly onDidChange: Event<void> = this._repository.onDidRunGitStatus;
|
||||
|
||||
constructor(private _repository: BaseRepository) { }
|
||||
}
|
||||
|
||||
export class ApiRepository implements Repository {
|
||||
|
||||
readonly rootUri: Uri = Uri.file(this._repository.root);
|
||||
readonly inputBox: InputBox = new ApiInputBox(this._repository.inputBox);
|
||||
get remotes(): Remote[] { return [...this._repository.remotes]; }
|
||||
|
||||
readonly onDidRunGitStatus: Event<void> = this._repository.onDidRunGitStatus;
|
||||
readonly state: RepositoryState = new ApiRepositoryState(this._repository);
|
||||
|
||||
constructor(private _repository: BaseRepository) { }
|
||||
|
||||
|
|
49
extensions/git/src/api/git.d.ts
vendored
49
extensions/git/src/api/git.d.ts
vendored
|
@ -14,6 +14,42 @@ export interface InputBox {
|
|||
value: string;
|
||||
}
|
||||
|
||||
export const enum RefType {
|
||||
Head,
|
||||
RemoteHead,
|
||||
Tag
|
||||
}
|
||||
|
||||
export interface Ref {
|
||||
readonly type: RefType;
|
||||
readonly name?: string;
|
||||
readonly commit?: string;
|
||||
readonly remote?: string;
|
||||
}
|
||||
|
||||
export interface UpstreamRef {
|
||||
readonly remote: string;
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
export interface Branch extends Ref {
|
||||
readonly upstream?: UpstreamRef;
|
||||
readonly ahead?: number;
|
||||
readonly behind?: number;
|
||||
}
|
||||
|
||||
export interface Commit {
|
||||
readonly hash: string;
|
||||
readonly message: string;
|
||||
readonly parents: string[];
|
||||
}
|
||||
|
||||
export interface Submodule {
|
||||
readonly name: string;
|
||||
readonly path: string;
|
||||
readonly url: string;
|
||||
}
|
||||
|
||||
export interface Remote {
|
||||
readonly name: string;
|
||||
readonly fetchUrl?: string;
|
||||
|
@ -21,12 +57,19 @@ export interface Remote {
|
|||
readonly isReadOnly: boolean;
|
||||
}
|
||||
|
||||
export interface RepositoryState {
|
||||
readonly HEAD: Branch | undefined;
|
||||
readonly refs: Ref[];
|
||||
readonly remotes: Remote[];
|
||||
readonly submodules: Submodule[];
|
||||
readonly rebaseCommit: Commit | undefined;
|
||||
readonly onDidChange: Event<void>;
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
readonly remotes: Remote[];
|
||||
|
||||
readonly onDidRunGitStatus: Event<void>;
|
||||
readonly state: RepositoryState;
|
||||
|
||||
status(): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
'use strict';
|
||||
|
||||
import { Uri, commands, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceState, TextDocumentShowOptions, ViewColumn, ProgressLocation, TextEditor, MessageOptions } from 'vscode';
|
||||
import { Ref, RefType, Git, GitErrorCodes, Branch } from './git';
|
||||
import { Git, GitErrorCodes } from './git';
|
||||
import { Repository, Resource, Status, CommitOptions, ResourceGroupType } from './repository';
|
||||
import { Model } from './model';
|
||||
import { toGitUri, fromGitUri } from './uri';
|
||||
|
@ -17,6 +17,7 @@ import { lstat, Stats } from 'fs';
|
|||
import * as os from 'os';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { Ref, RefType, Branch } from './api/git';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import * as filetype from 'file-type';
|
|||
import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent } from './util';
|
||||
import { CancellationToken } from 'vscode';
|
||||
import { detectEncoding } from './encoding';
|
||||
import { Ref, RefType, Branch, Remote } from './api/git';
|
||||
|
||||
const readfile = denodeify<string, string | null, string>(fs.readFile);
|
||||
|
||||
|
@ -31,40 +32,15 @@ export interface IFileStatus {
|
|||
rename?: string;
|
||||
}
|
||||
|
||||
export interface Remote {
|
||||
name: string;
|
||||
fetchUrl?: string;
|
||||
pushUrl?: string;
|
||||
isReadOnly: boolean;
|
||||
}
|
||||
|
||||
export interface Stash {
|
||||
index: number;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export enum RefType {
|
||||
Head,
|
||||
RemoteHead,
|
||||
Tag
|
||||
}
|
||||
|
||||
export interface Ref {
|
||||
type: RefType;
|
||||
name?: string;
|
||||
commit?: string;
|
||||
remote?: string;
|
||||
}
|
||||
|
||||
export interface UpstreamRef {
|
||||
remote: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Branch extends Ref {
|
||||
upstream?: UpstreamRef;
|
||||
ahead?: number;
|
||||
behind?: number;
|
||||
interface MutableRemote extends Remote {
|
||||
fetchUrl?: string;
|
||||
pushUrl?: string;
|
||||
isReadOnly: boolean;
|
||||
}
|
||||
|
||||
function parseVersion(raw: string): string {
|
||||
|
@ -1320,7 +1296,7 @@ export class Repository {
|
|||
async getRemotes(): Promise<Remote[]> {
|
||||
const result = await this.run(['remote', '--verbose']);
|
||||
const lines = result.stdout.trim().split('\n').filter(l => !!l);
|
||||
const remotes: Remote[] = [];
|
||||
const remotes: MutableRemote[] = [];
|
||||
|
||||
for (const line of lines) {
|
||||
const parts = line.split(/\s/);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
'use strict';
|
||||
|
||||
import { commands, Uri, Command, EventEmitter, Event, scm, SourceControl, SourceControlInputBox, SourceControlResourceGroup, SourceControlResourceState, SourceControlResourceDecorations, SourceControlInputBoxValidation, Disposable, ProgressLocation, window, workspace, WorkspaceEdit, ThemeColor, DecorationData, Memento, SourceControlInputBoxValidationType } from 'vscode';
|
||||
import { Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash, RefType, GitError, Submodule, DiffOptions } from './git';
|
||||
import { Repository as BaseRepository, Commit, GitErrorCodes, Stash, GitError, Submodule, DiffOptions } from './git';
|
||||
import { anyEvent, filterEvent, eventToPromise, dispose, find, isDescendant, IDisposable, onceEvent, EmptyDisposable, debounceEvent } from './util';
|
||||
import { memoize, throttle, debounce } from './decorators';
|
||||
import { toGitUri } from './uri';
|
||||
|
@ -15,6 +15,7 @@ import * as path from 'path';
|
|||
import * as nls from 'vscode-nls';
|
||||
import * as fs from 'fs';
|
||||
import { StatusBarCommands } from './statusbar';
|
||||
import { Branch, Ref, Remote, RefType } from './api/git';
|
||||
|
||||
const timeout = (millis: number) => new Promise(c => setTimeout(c, millis));
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
'use strict';
|
||||
|
||||
import { Disposable, Command, EventEmitter, Event } from 'vscode';
|
||||
import { Branch } from './git';
|
||||
import { Repository, Operation } from './repository';
|
||||
import { anyEvent, dispose } from './util';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { Branch } from './api/git';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
|
Loading…
Reference in a new issue