提交 fe8ee2e7 编写于 作者: J Joao Moreno

git: repository == scm provider

上级 56d1dadf
......@@ -276,393 +276,393 @@
},
{
"command": "git.init",
"when": "config.git.enabled && scmProvider == git && gitState == norepo"
"when": "config.git.enabled"
},
{
"command": "git.refresh",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.openHEADFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.openChange",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.stageSelectedRanges",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.revertSelectedRanges",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.unstage",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.unstageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.unstageSelectedRanges",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.clean",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.cleanAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.commitStaged",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.commitStagedSigned",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.commitStagedAmend",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.commitAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.commitAllSigned",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.commitAllAmend",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.undoCommit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.checkout",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.branch",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.deleteBranch",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.pull",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.pullFrom",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.pullRebase",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.pullFrom",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.createTag",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.push",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.pushTo",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.pushWithTags",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.publish",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.showOutput",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.stashPop",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
},
{
"command": "git.stashPopLatest",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled"
}
],
"scm/title": [
{
"command": "git.init",
"group": "navigation",
"when": "config.git.enabled && scmProvider == git && gitState == norepo"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.commit",
"group": "navigation",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.refresh",
"group": "navigation",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.sync",
"group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.pull",
"group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.pullRebase",
"group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.pullFrom",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.push",
"group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.pushTo",
"group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.publish",
"group": "2_publish",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.commitStaged",
"group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.commitStagedSigned",
"group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.commitStagedAmend",
"group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.commitAll",
"group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.commitAllSigned",
"group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.commitAllAmend",
"group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.undoCommit",
"group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.unstageAll",
"group": "4_stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.cleanAll",
"group": "4_stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.showOutput",
"group": "6_output",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.stash",
"group": "5_stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.stashPop",
"group": "5_stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
},
{
"command": "git.stashPopLatest",
"group": "5_stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
"when": "config.git.enabled && scmProvider == git"
}
],
"scm/resourceGroup/context": [
{
"command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "1_modification"
},
{
"command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "inline"
},
{
"command": "git.unstageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "1_modification"
},
{
"command": "git.unstageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "inline"
},
{
"command": "git.cleanAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.cleanAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline"
},
{
"command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline"
}
],
"scm/resourceState/context": [
{
"command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "1_modification"
},
{
"command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "inline"
},
{
"command": "git.openChange",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "navigation"
},
{
"command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "navigation"
},
{
"command": "git.openHEADFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "navigation"
},
{
"command": "git.unstage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "1_modification"
},
{
"command": "git.unstage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "inline"
},
{
"command": "git.openChange",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.openHEADFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.clean",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.clean",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline"
},
{
"command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline"
},
{
"command": "git.ignore",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification@3"
}
],
......
......@@ -16,7 +16,7 @@ export class AutoFetcher {
private disposables: Disposable[] = [];
private timer: NodeJS.Timer;
constructor(private model: Repository) {
constructor(private repository: Repository) {
workspace.onDidChangeConfiguration(this.onConfiguration, this, this.disposables);
this.onConfiguration();
}
......@@ -47,7 +47,7 @@ export class AutoFetcher {
@throttle
private async fetch(): Promise<void> {
try {
await this.model.fetch();
await this.repository.fetch();
} catch (err) {
if (err.gitErrorCode === GitErrorCodes.AuthenticationFailed) {
this.disable();
......
此差异已折叠。
......@@ -30,9 +30,9 @@ export class GitContentProvider {
private cache: Cache = Object.create(null);
private disposables: Disposable[] = [];
constructor(private model: Repository) {
constructor(private repository: Repository) {
this.disposables.push(
model.onDidChangeRepository(this.eventuallyFireChangeEvents, this),
repository.onDidChangeRepository(this.eventuallyFireChangeEvents, this),
workspace.registerTextDocumentContentProvider('git', this)
);
......@@ -61,12 +61,12 @@ export class GitContentProvider {
if (ref === '~') {
const fileUri = Uri.file(path);
const uriString = fileUri.toString();
const [indexStatus] = this.model.indexGroup.resources.filter(r => r.original.toString() === uriString);
const [indexStatus] = this.repository.indexGroup.resourceStates.filter(r => r.original.toString() === uriString);
ref = indexStatus ? '' : 'HEAD';
}
try {
return await this.model.show(ref, path);
return await this.repository.show(ref, path);
} catch (err) {
return '';
}
......
......@@ -11,9 +11,7 @@ import { ExtensionContext, workspace, window, Disposable, commands, Uri } from '
import { findGit, Git, IGit } from './git';
import { Repository } from './repository';
import { Model } from './model';
import { GitSCMProvider } from './scmProvider';
import { CommandCenter } from './commands';
import { StatusBarCommands } from './statusbar';
import { GitContentProvider } from './contentProvider';
import { AutoFetcher } from './autofetch';
import { Askpass } from './askpass';
......@@ -56,14 +54,11 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
disposables.push(toDisposable(() => git.onOutput.removeListener('log', onOutput)));
const commandCenter = new CommandCenter(git, model, outputChannel, telemetryReporter);
const statusBarCommands = new StatusBarCommands(repository);
const provider = new GitSCMProvider(repository, statusBarCommands);
const contentProvider = new GitContentProvider(repository);
const autoFetcher = new AutoFetcher(repository);
disposables.push(
commandCenter,
provider,
contentProvider,
autoFetcher,
repository
......
......@@ -5,10 +5,11 @@
'use strict';
import { Uri, Command, EventEmitter, Event, SourceControlResourceState, SourceControlResourceDecorations, Disposable, ProgressLocation, window, workspace, WorkspaceEdit } from 'vscode';
import { Uri, Command, EventEmitter, Event, scm, commands, SourceControl, SourceControlResourceGroup, SourceControlResourceState, SourceControlResourceDecorations, Disposable, ProgressLocation, window, workspace, WorkspaceEdit } from 'vscode';
import { Git, Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash } from './git';
import { anyEvent, eventToPromise, filterEvent, EmptyDisposable, combinedDisposable, dispose, find } from './util';
import { memoize, throttle, debounce } from './decorators';
import { toGitUri } from './uri';
import * as path from 'path';
import * as nls from 'vscode-nls';
import * as fs from 'fs';
......@@ -49,6 +50,12 @@ export enum Status {
BOTH_MODIFIED
}
export enum ResourceGroupType {
Merge,
Index,
WorkingTree
}
export class Resource implements SourceControlResourceState {
@memoize
......@@ -69,7 +76,7 @@ export class Resource implements SourceControlResourceState {
};
}
get resourceGroup(): ResourceGroup { return this._resourceGroup; }
get resourceGroupType(): ResourceGroupType { return this._resourceGroupType; }
get type(): Status { return this._type; }
get original(): Uri { return this._resourceUri; }
get renameResourceUri(): Uri | undefined { return this._renameResourceUri; }
......@@ -149,52 +156,13 @@ export class Resource implements SourceControlResourceState {
constructor(
private workspaceRoot: Uri,
private _resourceGroup: ResourceGroup,
private _resourceGroupType: ResourceGroupType,
private _resourceUri: Uri,
private _type: Status,
private _renameResourceUri?: Uri
) { }
}
export abstract class ResourceGroup {
get id(): string { return this._id; }
get contextKey(): string { return this._id; }
get label(): string { return this._label; }
get resources(): Resource[] { return this._resources; }
constructor(private _id: string, private _label: string, private _resources: Resource[]) {
}
}
export class MergeGroup extends ResourceGroup {
static readonly ID = 'merge';
constructor(resources: Resource[] = []) {
super(MergeGroup.ID, localize('merge changes', "Merge Changes"), resources);
}
}
export class IndexGroup extends ResourceGroup {
static readonly ID = 'index';
constructor(resources: Resource[] = []) {
super(IndexGroup.ID, localize('staged changes', "Staged Changes"), resources);
}
}
export class WorkingTreeGroup extends ResourceGroup {
static readonly ID = 'workingTree';
constructor(resources: Resource[] = []) {
super(WorkingTreeGroup.ID, localize('changes', "Changes"), resources);
}
}
export enum Operation {
Status = 1 << 0,
Add = 1 << 1,
......@@ -302,6 +270,10 @@ export interface IRepository {
clean(resources: Uri[]): Promise<void>;
}
export interface GitResourceGroup extends SourceControlResourceGroup {
resourceStates: Resource[];
}
export class Repository implements IRepository, Disposable {
private _onDidChangeRepository = new EventEmitter<Uri>();
......@@ -310,12 +282,9 @@ export class Repository implements IRepository, Disposable {
private _onDidChangeState = new EventEmitter<State>();
readonly onDidChangeState: Event<State> = this._onDidChangeState.event;
private _onDidChangeResources = new EventEmitter<void>();
readonly onDidChangeResources: Event<void> = this._onDidChangeResources.event;
@memoize
get onDidChange(): Event<void> {
return anyEvent<any>(this.onDidChangeState, this.onDidChangeResources);
return anyEvent<any>(this.onDidChangeState);
}
private _onRunOperation = new EventEmitter<Operation>();
......@@ -329,14 +298,17 @@ export class Repository implements IRepository, Disposable {
return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>);
}
private _mergeGroup = new MergeGroup([]);
get mergeGroup(): MergeGroup { return this._mergeGroup; }
private _sourceControl: SourceControl;
get sourceControl(): SourceControl { return this._sourceControl; }
private _mergeGroup: SourceControlResourceGroup;
get mergeGroup(): GitResourceGroup { return this._mergeGroup as GitResourceGroup; }
private _indexGroup = new IndexGroup([]);
get indexGroup(): IndexGroup { return this._indexGroup; }
private _indexGroup: SourceControlResourceGroup;
get indexGroup(): GitResourceGroup { return this._indexGroup as GitResourceGroup; }
private _workingTreeGroup = new WorkingTreeGroup([]);
get workingTreeGroup(): WorkingTreeGroup { return this._workingTreeGroup; }
private _workingTreeGroup: SourceControlResourceGroup;
get workingTreeGroup(): GitResourceGroup { return this._workingTreeGroup as GitResourceGroup; }
private _HEAD: Branch | undefined;
get HEAD(): Branch | undefined {
......@@ -367,10 +339,11 @@ export class Repository implements IRepository, Disposable {
this._HEAD = undefined;
this._refs = [];
this._remotes = [];
this._mergeGroup = new MergeGroup();
this._indexGroup = new IndexGroup();
this._workingTreeGroup = new WorkingTreeGroup();
this._onDidChangeResources.fire();
this.mergeGroup.resourceStates = [];
this.indexGroup.resourceStates = [];
this.workingTreeGroup.resourceStates = [];
this._sourceControl.count = 0;
commands.executeCommand('setContext', 'gitState', '');
}
private onWorkspaceChange: Event<Uri>;
......@@ -387,9 +360,43 @@ export class Repository implements IRepository, Disposable {
this.onWorkspaceChange = anyEvent(fsWatcher.onDidChange, fsWatcher.onDidCreate, fsWatcher.onDidDelete);
this.disposables.push(fsWatcher);
this._sourceControl = scm.createSourceControl('git', 'Git');
this._sourceControl.acceptInputCommand = { command: 'git.commitWithInput', title: localize('commit', "Commit") };
this._sourceControl.quickDiffProvider = this;
this.disposables.push(this._sourceControl);
this._mergeGroup = this._sourceControl.createResourceGroup('merge', localize('merge changes', "Merge Changes"));
this._indexGroup = this._sourceControl.createResourceGroup('index', localize('staged changes', "Staged Changes"));
this._workingTreeGroup = this._sourceControl.createResourceGroup('workingTree', localize('changes', "Changes"));
this.mergeGroup.hideWhenEmpty = true;
this.indexGroup.hideWhenEmpty = true;
this.disposables.push(this.mergeGroup);
this.disposables.push(this.indexGroup);
this.disposables.push(this.workingTreeGroup);
this.updateCommitTemplate();
this.status();
}
// TODO@Joao reorganize this
provideOriginalResource(uri: Uri): Uri | undefined {
if (uri.scheme !== 'file') {
return;
}
return toGitUri(uri, '', true);
}
private async updateCommitTemplate(): Promise<void> {
try {
this._sourceControl.commitTemplate = await this.repository.getCommitTemplate();
} catch (e) {
// noop
}
}
@throttle
async init(): Promise<void> {
if (this.state !== State.NotAGitRepository) {
......@@ -435,7 +442,7 @@ export class Repository implements IRepository, Disposable {
resources.forEach(r => {
const raw = r.toString();
const scmResource = find(this.workingTreeGroup.resources, sr => sr.resourceUri.toString() === raw);
const scmResource = find(this.workingTreeGroup.resourceStates, sr => sr.resourceUri.toString() === raw);
if (!scmResource) {
return;
......@@ -731,37 +738,59 @@ export class Repository implements IRepository, Disposable {
const renameUri = raw.rename ? Uri.file(path.join(this.repository.root, raw.rename)) : undefined;
switch (raw.x + raw.y) {
case '??': return workingTree.push(new Resource(this.workspaceRoot, this.workingTreeGroup, uri, Status.UNTRACKED));
case '!!': return workingTree.push(new Resource(this.workspaceRoot, this.workingTreeGroup, uri, Status.IGNORED));
case 'DD': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.BOTH_DELETED));
case 'AU': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.ADDED_BY_US));
case 'UD': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.DELETED_BY_THEM));
case 'UA': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.ADDED_BY_THEM));
case 'DU': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.DELETED_BY_US));
case 'AA': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.BOTH_ADDED));
case 'UU': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.BOTH_MODIFIED));
case '??': return workingTree.push(new Resource(this.workspaceRoot, ResourceGroupType.WorkingTree, uri, Status.UNTRACKED));
case '!!': return workingTree.push(new Resource(this.workspaceRoot, ResourceGroupType.WorkingTree, uri, Status.IGNORED));
case 'DD': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.BOTH_DELETED));
case 'AU': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.ADDED_BY_US));
case 'UD': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.DELETED_BY_THEM));
case 'UA': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.ADDED_BY_THEM));
case 'DU': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.DELETED_BY_US));
case 'AA': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.BOTH_ADDED));
case 'UU': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.BOTH_MODIFIED));
}
let isModifiedInIndex = false;
switch (raw.x) {
case 'M': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break;
case 'A': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_ADDED)); break;
case 'D': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_DELETED)); break;
case 'R': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_RENAMED, renameUri)); break;
case 'C': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_COPIED, renameUri)); break;
case 'M': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break;
case 'A': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_ADDED)); break;
case 'D': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_DELETED)); break;
case 'R': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_RENAMED, renameUri)); break;
case 'C': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_COPIED, renameUri)); break;
}
switch (raw.y) {
case 'M': workingTree.push(new Resource(this.workspaceRoot, this.workingTreeGroup, uri, Status.MODIFIED, renameUri)); break;
case 'D': workingTree.push(new Resource(this.workspaceRoot, this.workingTreeGroup, uri, Status.DELETED, renameUri)); break;
case 'M': workingTree.push(new Resource(this.workspaceRoot, ResourceGroupType.WorkingTree, uri, Status.MODIFIED, renameUri)); break;
case 'D': workingTree.push(new Resource(this.workspaceRoot, ResourceGroupType.WorkingTree, uri, Status.DELETED, renameUri)); break;
}
});
this._mergeGroup = new MergeGroup(merge);
this._indexGroup = new IndexGroup(index);
this._workingTreeGroup = new WorkingTreeGroup(workingTree);
this._onDidChangeResources.fire();
// set resource groups
this.mergeGroup.resourceStates = merge;
this.indexGroup.resourceStates = index;
this.workingTreeGroup.resourceStates = workingTree;
// set count badge
const countBadge = workspace.getConfiguration('git').get<string>('countBadge');
let count = merge.length + index.length + workingTree.length;
switch (countBadge) {
case 'off': count = 0; break;
case 'tracked': count = count - workingTree.filter(r => r.type === Status.UNTRACKED || r.type === Status.IGNORED).length; break;
}
this._sourceControl.count = count;
// set context key
let stateContextKey = '';
switch (this.state) {
case State.Uninitialized: stateContextKey = 'uninitialized'; break;
case State.Idle: stateContextKey = 'idle'; break;
case State.NotAGitRepository: stateContextKey = 'norepo'; break;
}
commands.executeCommand('setContext', 'gitState', stateContextKey);
}
private onFSChange(uri: Uri): void {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { scm, Uri, Disposable, SourceControl, SourceControlResourceGroup, Event, workspace, commands } from 'vscode';
import { Repository, State, Status } from './repository';
import { StatusBarCommands } from './statusbar';
import { mapEvent } from './util';
import { toGitUri } from './uri';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export class GitSCMProvider {
private disposables: Disposable[] = [];
get contextKey(): string { return 'git'; }
get onDidChange(): Event<this> {
return mapEvent(this.model.onDidChange, () => this);
}
get label(): string { return 'Git'; }
get stateContextKey(): string {
switch (this.model.state) {
case State.Uninitialized: return 'uninitialized';
case State.Idle: return 'idle';
case State.NotAGitRepository: return 'norepo';
default: return '';
}
}
get count(): number {
const countBadge = workspace.getConfiguration('git').get<string>('countBadge');
const total = this.model.mergeGroup.resources.length
+ this.model.indexGroup.resources.length
+ this.model.workingTreeGroup.resources.length;
switch (countBadge) {
case 'off': return 0;
case 'tracked': return total - this.model.workingTreeGroup.resources.filter(r => r.type === Status.UNTRACKED || r.type === Status.IGNORED).length;
default: return total;
}
}
private _sourceControl: SourceControl;
get sourceControl(): SourceControl {
return this._sourceControl;
}
private mergeGroup: SourceControlResourceGroup;
private indexGroup: SourceControlResourceGroup;
private workingTreeGroup: SourceControlResourceGroup;
constructor(
private model: Repository,
private statusBarCommands: StatusBarCommands
) {
this._sourceControl = scm.createSourceControl('git', 'Git');
this.disposables.push(this._sourceControl);
this._sourceControl.acceptInputCommand = { command: 'git.commitWithInput', title: localize('commit', "Commit") };
this._sourceControl.quickDiffProvider = this;
this.statusBarCommands.onDidChange(this.onDidStatusBarCommandsChange, this, this.disposables);
this.onDidStatusBarCommandsChange();
this.mergeGroup = this._sourceControl.createResourceGroup(model.mergeGroup.id, model.mergeGroup.label);
this.indexGroup = this._sourceControl.createResourceGroup(model.indexGroup.id, model.indexGroup.label);
this.workingTreeGroup = this._sourceControl.createResourceGroup(model.workingTreeGroup.id, model.workingTreeGroup.label);
this.mergeGroup.hideWhenEmpty = true;
this.indexGroup.hideWhenEmpty = true;
this.disposables.push(this.mergeGroup);
this.disposables.push(this.indexGroup);
this.disposables.push(this.workingTreeGroup);
model.onDidChange(this.onDidModelChange, this, this.disposables);
this.updateCommitTemplate();
}
private async updateCommitTemplate(): Promise<void> {
try {
this._sourceControl.commitTemplate = await this.model.getCommitTemplate();
} catch (e) {
// noop
}
}
provideOriginalResource(uri: Uri): Uri | undefined {
if (uri.scheme !== 'file') {
return;
}
return toGitUri(uri, '', true);
}
private onDidModelChange(): void {
this.mergeGroup.resourceStates = this.model.mergeGroup.resources;
this.indexGroup.resourceStates = this.model.indexGroup.resources;
this.workingTreeGroup.resourceStates = this.model.workingTreeGroup.resources;
this._sourceControl.count = this.count;
commands.executeCommand('setContext', 'gitState', this.stateContextKey);
}
private onDidStatusBarCommandsChange(): void {
this._sourceControl.statusBarCommands = this.statusBarCommands.commands;
}
dispose(): void {
this.disposables.forEach(d => d.dispose());
this.disposables = [];
}
}
\ No newline at end of file
......@@ -19,25 +19,25 @@ class CheckoutStatusBar {
get onDidChange(): Event<void> { return this._onDidChange.event; }
private disposables: Disposable[] = [];
constructor(private model: Repository) {
model.onDidChange(this._onDidChange.fire, this._onDidChange, this.disposables);
constructor(private repository: Repository) {
repository.onDidChange(this._onDidChange.fire, this._onDidChange, this.disposables);
}
get command(): Command | undefined {
const HEAD = this.model.HEAD;
const HEAD = this.repository.HEAD;
if (!HEAD) {
return undefined;
}
const tag = this.model.refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0];
const tag = this.repository.refs.filter(iref => iref.type === RefType.Tag && iref.commit === HEAD.commit)[0];
const tagName = tag && tag.name;
const head = HEAD.name || tagName || (HEAD.commit || '').substr(0, 8);
const title = '$(git-branch) '
+ head
+ (this.model.workingTreeGroup.resources.length > 0 ? '*' : '')
+ (this.model.indexGroup.resources.length > 0 ? '+' : '')
+ (this.model.mergeGroup.resources.length > 0 ? '!' : '');
+ (this.repository.workingTreeGroup.resourceStates.length > 0 ? '*' : '')
+ (this.repository.indexGroup.resourceStates.length > 0 ? '+' : '')
+ (this.repository.mergeGroup.resourceStates.length > 0 ? '!' : '');
return {
command: 'git.checkout',
......@@ -76,24 +76,24 @@ class SyncStatusBar {
this._onDidChange.fire();
}
constructor(private model: Repository) {
model.onDidChange(this.onModelChange, this, this.disposables);
model.onDidChangeOperations(this.onOperationsChange, this, this.disposables);
constructor(private repository: Repository) {
repository.onDidChange(this.onModelChange, this, this.disposables);
repository.onDidChangeOperations(this.onOperationsChange, this, this.disposables);
this._onDidChange.fire();
}
private onOperationsChange(): void {
this.state = {
...this.state,
isSyncRunning: this.model.operations.isRunning(Operation.Sync)
isSyncRunning: this.repository.operations.isRunning(Operation.Sync)
};
}
private onModelChange(): void {
this.state = {
...this.state,
hasRemotes: this.model.remotes.length > 0,
HEAD: this.model.HEAD
hasRemotes: this.repository.remotes.length > 0,
HEAD: this.repository.HEAD
};
}
......@@ -149,9 +149,9 @@ export class StatusBarCommands {
private checkoutStatusBar: CheckoutStatusBar;
private disposables: Disposable[] = [];
constructor(model: Repository) {
this.syncStatusBar = new SyncStatusBar(model);
this.checkoutStatusBar = new CheckoutStatusBar(model);
constructor(repository: Repository) {
this.syncStatusBar = new SyncStatusBar(repository);
this.checkoutStatusBar = new CheckoutStatusBar(repository);
}
get onDidChange(): Event<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册