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

git: repository == scm provider

上级 56d1dadf
...@@ -276,393 +276,393 @@ ...@@ -276,393 +276,393 @@
}, },
{ {
"command": "git.init", "command": "git.init",
"when": "config.git.enabled && scmProvider == git && gitState == norepo" "when": "config.git.enabled"
}, },
{ {
"command": "git.refresh", "command": "git.refresh",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.openFile", "command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.openHEADFile", "command": "git.openHEADFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.openChange", "command": "git.openChange",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.stage", "command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.stageAll", "command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.stageSelectedRanges", "command": "git.stageSelectedRanges",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.revertSelectedRanges", "command": "git.revertSelectedRanges",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.unstage", "command": "git.unstage",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.unstageAll", "command": "git.unstageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.unstageSelectedRanges", "command": "git.unstageSelectedRanges",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.clean", "command": "git.clean",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.cleanAll", "command": "git.cleanAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.commit", "command": "git.commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.commitStaged", "command": "git.commitStaged",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.commitStagedSigned", "command": "git.commitStagedSigned",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.commitStagedAmend", "command": "git.commitStagedAmend",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.commitAll", "command": "git.commitAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.commitAllSigned", "command": "git.commitAllSigned",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.commitAllAmend", "command": "git.commitAllAmend",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.undoCommit", "command": "git.undoCommit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.checkout", "command": "git.checkout",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.branch", "command": "git.branch",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.deleteBranch", "command": "git.deleteBranch",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.pull", "command": "git.pull",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.pullFrom", "command": "git.pullFrom",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.pullRebase", "command": "git.pullRebase",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.pullFrom", "command": "git.pullFrom",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.createTag", "command": "git.createTag",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.push", "command": "git.push",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.pushTo", "command": "git.pushTo",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.pushWithTags", "command": "git.pushWithTags",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.sync", "command": "git.sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.publish", "command": "git.publish",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.showOutput", "command": "git.showOutput",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.stash", "command": "git.stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.stashPop", "command": "git.stashPop",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
}, },
{ {
"command": "git.stashPopLatest", "command": "git.stashPopLatest",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled"
} }
], ],
"scm/title": [ "scm/title": [
{ {
"command": "git.init", "command": "git.init",
"group": "navigation", "group": "navigation",
"when": "config.git.enabled && scmProvider == git && gitState == norepo" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.commit", "command": "git.commit",
"group": "navigation", "group": "navigation",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.refresh", "command": "git.refresh",
"group": "navigation", "group": "navigation",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.sync", "command": "git.sync",
"group": "1_sync", "group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.pull", "command": "git.pull",
"group": "1_sync", "group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.pullRebase", "command": "git.pullRebase",
"group": "1_sync", "group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.pullFrom", "command": "git.pullFrom",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.push", "command": "git.push",
"group": "1_sync", "group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.pushTo", "command": "git.pushTo",
"group": "1_sync", "group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.publish", "command": "git.publish",
"group": "2_publish", "group": "2_publish",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.commitStaged", "command": "git.commitStaged",
"group": "3_commit", "group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.commitStagedSigned", "command": "git.commitStagedSigned",
"group": "3_commit", "group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.commitStagedAmend", "command": "git.commitStagedAmend",
"group": "3_commit", "group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.commitAll", "command": "git.commitAll",
"group": "3_commit", "group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.commitAllSigned", "command": "git.commitAllSigned",
"group": "3_commit", "group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.commitAllAmend", "command": "git.commitAllAmend",
"group": "3_commit", "group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.undoCommit", "command": "git.undoCommit",
"group": "3_commit", "group": "3_commit",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.unstageAll", "command": "git.unstageAll",
"group": "4_stage", "group": "4_stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.cleanAll", "command": "git.cleanAll",
"group": "4_stage", "group": "4_stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.showOutput", "command": "git.showOutput",
"group": "6_output", "group": "6_output",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.stash", "command": "git.stash",
"group": "5_stash", "group": "5_stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.stashPop", "command": "git.stashPop",
"group": "5_stash", "group": "5_stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
}, },
{ {
"command": "git.stashPopLatest", "command": "git.stashPopLatest",
"group": "5_stash", "group": "5_stash",
"when": "config.git.enabled && scmProvider == git && gitState == idle" "when": "config.git.enabled && scmProvider == git"
} }
], ],
"scm/resourceGroup/context": [ "scm/resourceGroup/context": [
{ {
"command": "git.stageAll", "command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.stageAll", "command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "inline" "group": "inline"
}, },
{ {
"command": "git.unstageAll", "command": "git.unstageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.unstageAll", "command": "git.unstageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "inline" "group": "inline"
}, },
{ {
"command": "git.cleanAll", "command": "git.cleanAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.stageAll", "command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.cleanAll", "command": "git.cleanAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline" "group": "inline"
}, },
{ {
"command": "git.stageAll", "command": "git.stageAll",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline" "group": "inline"
} }
], ],
"scm/resourceState/context": [ "scm/resourceState/context": [
{ {
"command": "git.stage", "command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.stage", "command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == merge", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == merge",
"group": "inline" "group": "inline"
}, },
{ {
"command": "git.openChange", "command": "git.openChange",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "navigation" "group": "navigation"
}, },
{ {
"command": "git.openFile", "command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "navigation" "group": "navigation"
}, },
{ {
"command": "git.openHEADFile", "command": "git.openHEADFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "navigation" "group": "navigation"
}, },
{ {
"command": "git.unstage", "command": "git.unstage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.unstage", "command": "git.unstage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == index",
"group": "inline" "group": "inline"
}, },
{ {
"command": "git.openChange", "command": "git.openChange",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "navigation" "group": "navigation"
}, },
{ {
"command": "git.openHEADFile", "command": "git.openHEADFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "navigation" "group": "navigation"
}, },
{ {
"command": "git.openFile", "command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "navigation" "group": "navigation"
}, },
{ {
"command": "git.stage", "command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.clean", "command": "git.clean",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification" "group": "1_modification"
}, },
{ {
"command": "git.clean", "command": "git.clean",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline" "group": "inline"
}, },
{ {
"command": "git.stage", "command": "git.stage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree", "when": "config.git.enabled && scmProvider == git && scmResourceGroup == workingTree",
"group": "inline" "group": "inline"
}, },
{ {
"command": "git.ignore", "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" "group": "1_modification@3"
} }
], ],
......
...@@ -16,7 +16,7 @@ export class AutoFetcher { ...@@ -16,7 +16,7 @@ export class AutoFetcher {
private disposables: Disposable[] = []; private disposables: Disposable[] = [];
private timer: NodeJS.Timer; private timer: NodeJS.Timer;
constructor(private model: Repository) { constructor(private repository: Repository) {
workspace.onDidChangeConfiguration(this.onConfiguration, this, this.disposables); workspace.onDidChangeConfiguration(this.onConfiguration, this, this.disposables);
this.onConfiguration(); this.onConfiguration();
} }
...@@ -47,7 +47,7 @@ export class AutoFetcher { ...@@ -47,7 +47,7 @@ export class AutoFetcher {
@throttle @throttle
private async fetch(): Promise<void> { private async fetch(): Promise<void> {
try { try {
await this.model.fetch(); await this.repository.fetch();
} catch (err) { } catch (err) {
if (err.gitErrorCode === GitErrorCodes.AuthenticationFailed) { if (err.gitErrorCode === GitErrorCodes.AuthenticationFailed) {
this.disable(); this.disable();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceState, TextDocumentShowOptions, ViewColumn } from 'vscode'; import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceState, TextDocumentShowOptions, ViewColumn } from 'vscode';
import { Ref, RefType, Git, GitErrorCodes, Branch } from './git'; import { Ref, RefType, Git, GitErrorCodes, Branch } from './git';
import { Repository, Resource, Status, CommitOptions, WorkingTreeGroup, IndexGroup, MergeGroup } from './repository'; import { Repository, Resource, Status, CommitOptions, ResourceGroupType } from './repository';
import { Model } from './model'; import { Model } from './model';
import { toGitUri, fromGitUri } from './uri'; import { toGitUri, fromGitUri } from './uri';
import { applyLineChanges, intersectDiffWithRange, toLineRanges, invertLineChange } from './staging'; import { applyLineChanges, intersectDiffWithRange, toLineRanges, invertLineChange } from './staging';
...@@ -27,14 +27,14 @@ class CheckoutItem implements QuickPickItem { ...@@ -27,14 +27,14 @@ class CheckoutItem implements QuickPickItem {
constructor(protected ref: Ref) { } constructor(protected ref: Ref) { }
async run(model: Repository): Promise<void> { async run(repository: Repository): Promise<void> {
const ref = this.treeish; const ref = this.treeish;
if (!ref) { if (!ref) {
return; return;
} }
await model.checkout(ref); await repository.checkout(ref);
} }
} }
...@@ -70,11 +70,11 @@ class BranchDeleteItem implements QuickPickItem { ...@@ -70,11 +70,11 @@ class BranchDeleteItem implements QuickPickItem {
constructor(private ref: Ref) { } constructor(private ref: Ref) { }
async run(model: Repository, force?: boolean): Promise<void> { async run(repository: Repository, force?: boolean): Promise<void> {
if (!this.branchName) { if (!this.branchName) {
return; return;
} }
await model.deleteBranch(this.branchName, force); await repository.deleteBranch(this.branchName, force);
} }
} }
...@@ -85,8 +85,8 @@ class MergeItem implements QuickPickItem { ...@@ -85,8 +85,8 @@ class MergeItem implements QuickPickItem {
constructor(protected ref: Ref) { } constructor(protected ref: Ref) { }
async run(model: Repository): Promise<void> { async run(repository: Repository): Promise<void> {
await model.merge(this.ref.name! || this.ref.commit!); await repository.merge(this.ref.name! || this.ref.commit!);
} }
} }
...@@ -95,7 +95,7 @@ class CreateBranchItem implements QuickPickItem { ...@@ -95,7 +95,7 @@ class CreateBranchItem implements QuickPickItem {
get label(): string { return localize('create branch', '$(plus) Create new branch'); } get label(): string { return localize('create branch', '$(plus) Create new branch'); }
get description(): string { return ''; } get description(): string { return ''; }
async run(model: Repository): Promise<void> { async run(repository: Repository): Promise<void> {
await commands.executeCommand('git.branch'); await commands.executeCommand('git.branch');
} }
} }
...@@ -146,18 +146,18 @@ export class CommandCenter { ...@@ -146,18 +146,18 @@ export class CommandCenter {
} }
@command('git.refresh', { model: true }) @command('git.refresh', { model: true })
async refresh(model: Repository): Promise<void> { async refresh(repository: Repository): Promise<void> {
await model.status(); await repository.status();
} }
@command('git.openResource', { model: true }) @command('git.openResource', { model: true })
async openResource(model: Repository, resource: Resource): Promise<void> { async openResource(repository: Repository, resource: Resource): Promise<void> {
await this._openResource(model, resource); await this._openResource(repository, resource);
} }
private async _openResource(model: Repository, resource: Resource, preview?: boolean): Promise<void> { private async _openResource(repository: Repository, resource: Resource, preview?: boolean): Promise<void> {
const left = this.getLeftResource(resource); const left = this.getLeftResource(resource);
const right = this.getRightResource(model, resource); const right = this.getRightResource(repository, resource);
const title = this.getTitle(resource); const title = this.getTitle(resource);
if (!right) { if (!right) {
...@@ -201,7 +201,7 @@ export class CommandCenter { ...@@ -201,7 +201,7 @@ export class CommandCenter {
} }
} }
private getRightResource(model: Repository, resource: Resource): Uri | undefined { private getRightResource(repository: Repository, resource: Resource): Uri | undefined {
switch (resource.type) { switch (resource.type) {
case Status.INDEX_MODIFIED: case Status.INDEX_MODIFIED:
case Status.INDEX_ADDED: case Status.INDEX_ADDED:
...@@ -218,7 +218,7 @@ export class CommandCenter { ...@@ -218,7 +218,7 @@ export class CommandCenter {
case Status.UNTRACKED: case Status.UNTRACKED:
case Status.IGNORED: case Status.IGNORED:
const uriString = resource.resourceUri.toString(); const uriString = resource.resourceUri.toString();
const [indexStatus] = model.indexGroup.resources.filter(r => r.resourceUri.toString() === uriString); const [indexStatus] = repository.indexGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString);
if (indexStatus && indexStatus.renameResourceUri) { if (indexStatus && indexStatus.renameResourceUri) {
return indexStatus.renameResourceUri; return indexStatus.renameResourceUri;
...@@ -307,7 +307,7 @@ export class CommandCenter { ...@@ -307,7 +307,7 @@ export class CommandCenter {
} }
@command('git.openFile', { model: true }) @command('git.openFile', { model: true })
async openFile(model: Repository, arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> { async openFile(repository: Repository, arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> {
let uris: Uri[] | undefined; let uris: Uri[] | undefined;
if (arg instanceof Uri) { if (arg instanceof Uri) {
...@@ -357,7 +357,7 @@ export class CommandCenter { ...@@ -357,7 +357,7 @@ export class CommandCenter {
} }
@command('git.openHEADFile', { model: true }) @command('git.openHEADFile', { model: true })
async openHEADFile(model: Repository, arg?: Resource | Uri): Promise<void> { async openHEADFile(repository: Repository, arg?: Resource | Uri): Promise<void> {
let resource: Resource | undefined = undefined; let resource: Resource | undefined = undefined;
if (arg instanceof Resource) { if (arg instanceof Resource) {
...@@ -383,7 +383,7 @@ export class CommandCenter { ...@@ -383,7 +383,7 @@ export class CommandCenter {
} }
@command('git.openChange', { model: true }) @command('git.openChange', { model: true })
async openChange(model: Repository, arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> { async openChange(repository: Repository, arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> {
let resources: Resource[] | undefined = undefined; let resources: Resource[] | undefined = undefined;
if (arg instanceof Uri) { if (arg instanceof Uri) {
...@@ -411,7 +411,7 @@ export class CommandCenter { ...@@ -411,7 +411,7 @@ export class CommandCenter {
const preview = resources.length === 1 ? undefined : false; const preview = resources.length === 1 ? undefined : false;
for (const resource of resources) { for (const resource of resources) {
await this._openResource(model, resource, preview); await this._openResource(repository, resource, preview);
} }
} }
...@@ -428,7 +428,7 @@ export class CommandCenter { ...@@ -428,7 +428,7 @@ export class CommandCenter {
} }
const scmResources = resourceStates const scmResources = resourceStates
.filter(s => s instanceof Resource && (s.resourceGroup instanceof WorkingTreeGroup || s.resourceGroup instanceof MergeGroup)) as Resource[]; .filter(s => s instanceof Resource && (s.resourceGroupType === ResourceGroupType.WorkingTree || s.resourceGroupType === ResourceGroupType.Merge)) as Resource[];
if (!scmResources.length) { if (!scmResources.length) {
return; return;
...@@ -439,13 +439,13 @@ export class CommandCenter { ...@@ -439,13 +439,13 @@ export class CommandCenter {
} }
@command('git.stageAll', { model: true }) @command('git.stageAll', { model: true })
async stageAll(model: Repository): Promise<void> { async stageAll(repository: Repository): Promise<void> {
await model.add([]); await repository.add([]);
} }
// TODO@Joao does this command really receive a model? // TODO@Joao does this command really receive a model?
@command('git.stageSelectedRanges', { model: true, diff: true }) @command('git.stageSelectedRanges', { model: true, diff: true })
async stageSelectedRanges(model: Repository, diffs: LineChange[]): Promise<void> { async stageSelectedRanges(repository: Repository, diffs: LineChange[]): Promise<void> {
const textEditor = window.activeTextEditor; const textEditor = window.activeTextEditor;
if (!textEditor) { if (!textEditor) {
...@@ -472,12 +472,12 @@ export class CommandCenter { ...@@ -472,12 +472,12 @@ export class CommandCenter {
const result = applyLineChanges(originalDocument, modifiedDocument, selectedDiffs); const result = applyLineChanges(originalDocument, modifiedDocument, selectedDiffs);
await model.stage(modifiedUri, result); await repository.stage(modifiedUri, result);
} }
// TODO@Joao does this command really receive a model? // TODO@Joao does this command really receive a model?
@command('git.revertSelectedRanges', { model: true, diff: true }) @command('git.revertSelectedRanges', { model: true, diff: true })
async revertSelectedRanges(model: Repository, diffs: LineChange[]): Promise<void> { async revertSelectedRanges(repository: Repository, diffs: LineChange[]): Promise<void> {
const textEditor = window.activeTextEditor; const textEditor = window.activeTextEditor;
if (!textEditor) { if (!textEditor) {
...@@ -522,7 +522,7 @@ export class CommandCenter { ...@@ -522,7 +522,7 @@ export class CommandCenter {
} }
@command('git.unstage', { model: true }) @command('git.unstage', { model: true })
async unstage(model: Repository, ...resourceStates: SourceControlResourceState[]): Promise<void> { async unstage(repository: Repository, ...resourceStates: SourceControlResourceState[]): Promise<void> {
if (resourceStates.length === 0 || !(resourceStates[0].resourceUri instanceof Uri)) { if (resourceStates.length === 0 || !(resourceStates[0].resourceUri instanceof Uri)) {
const resource = this.getSCMResource(); const resource = this.getSCMResource();
...@@ -534,7 +534,7 @@ export class CommandCenter { ...@@ -534,7 +534,7 @@ export class CommandCenter {
} }
const scmResources = resourceStates const scmResources = resourceStates
.filter(s => s instanceof Resource && s.resourceGroup instanceof IndexGroup) as Resource[]; .filter(s => s instanceof Resource && s.resourceGroupType === ResourceGroupType.Index) as Resource[];
if (!scmResources.length) { if (!scmResources.length) {
return; return;
...@@ -542,17 +542,17 @@ export class CommandCenter { ...@@ -542,17 +542,17 @@ export class CommandCenter {
const resources = scmResources.map(r => r.resourceUri); const resources = scmResources.map(r => r.resourceUri);
return await model.revert(resources); return await repository.revert(resources);
} }
@command('git.unstageAll', { model: true }) @command('git.unstageAll', { model: true })
async unstageAll(model: Repository): Promise<void> { async unstageAll(repository: Repository): Promise<void> {
return await model.revert([]); return await repository.revert([]);
} }
// TODO@Joao does this command really receive a model? // TODO@Joao does this command really receive a model?
@command('git.unstageSelectedRanges', { model: true, diff: true }) @command('git.unstageSelectedRanges', { model: true, diff: true })
async unstageSelectedRanges(model: Repository, diffs: LineChange[]): Promise<void> { async unstageSelectedRanges(repository: Repository, diffs: LineChange[]): Promise<void> {
const textEditor = window.activeTextEditor; const textEditor = window.activeTextEditor;
if (!textEditor) { if (!textEditor) {
...@@ -586,11 +586,11 @@ export class CommandCenter { ...@@ -586,11 +586,11 @@ export class CommandCenter {
const invertedDiffs = selectedDiffs.map(invertLineChange); const invertedDiffs = selectedDiffs.map(invertLineChange);
const result = applyLineChanges(modifiedDocument, originalDocument, invertedDiffs); const result = applyLineChanges(modifiedDocument, originalDocument, invertedDiffs);
await model.stage(modifiedUri, result); await repository.stage(modifiedUri, result);
} }
@command('git.clean', { model: true }) @command('git.clean', { model: true })
async clean(model: Repository, ...resourceStates: SourceControlResourceState[]): Promise<void> { async clean(repository: Repository, ...resourceStates: SourceControlResourceState[]): Promise<void> {
if (resourceStates.length === 0 || !(resourceStates[0].resourceUri instanceof Uri)) { if (resourceStates.length === 0 || !(resourceStates[0].resourceUri instanceof Uri)) {
const resource = this.getSCMResource(); const resource = this.getSCMResource();
...@@ -602,7 +602,7 @@ export class CommandCenter { ...@@ -602,7 +602,7 @@ export class CommandCenter {
} }
const resources = resourceStates const resources = resourceStates
.filter(s => s instanceof Resource && s.resourceGroup instanceof WorkingTreeGroup) as Resource[]; .filter(s => s instanceof Resource && s.resourceGroupType === ResourceGroupType.WorkingTree) as Resource[];
if (!resources.length) { if (!resources.length) {
return; return;
...@@ -633,14 +633,14 @@ export class CommandCenter { ...@@ -633,14 +633,14 @@ export class CommandCenter {
return; return;
} }
await model.clean(resources.map(r => r.resourceUri)); await repository.clean(resources.map(r => r.resourceUri));
} }
@command('git.cleanAll', { model: true }) @command('git.cleanAll', { model: true })
async cleanAll(model: Repository): Promise<void> { async cleanAll(repository: Repository): Promise<void> {
const config = workspace.getConfiguration('git'); const config = workspace.getConfiguration('git');
let scope = config.get<string>('discardAllScope') || 'prompt'; let scope = config.get<string>('discardAllScope') || 'prompt';
let resources = model.workingTreeGroup.resources; let resources = repository.workingTreeGroup.resourceStates;
if (resources.length === 0) { if (resources.length === 0) {
return; return;
...@@ -685,19 +685,19 @@ export class CommandCenter { ...@@ -685,19 +685,19 @@ export class CommandCenter {
return; return;
} }
await model.clean(resources.map(r => r.resourceUri)); await repository.clean(resources.map(r => r.resourceUri));
} }
private async smartCommit( private async smartCommit(
model: Repository, repository: Repository,
getCommitMessage: () => Promise<string | undefined>, getCommitMessage: () => Promise<string | undefined>,
opts?: CommitOptions opts?: CommitOptions
): Promise<boolean> { ): Promise<boolean> {
const config = workspace.getConfiguration('git'); const config = workspace.getConfiguration('git');
const enableSmartCommit = config.get<boolean>('enableSmartCommit') === true; const enableSmartCommit = config.get<boolean>('enableSmartCommit') === true;
const enableCommitSigning = config.get<boolean>('enableCommitSigning') === true; const enableCommitSigning = config.get<boolean>('enableCommitSigning') === true;
const noStagedChanges = model.indexGroup.resources.length === 0; const noStagedChanges = repository.indexGroup.resourceStates.length === 0;
const noUnstagedChanges = model.workingTreeGroup.resources.length === 0; const noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0;
// no changes, and the user has not configured to commit all in this case // no changes, and the user has not configured to commit all in this case
if (!noUnstagedChanges && noStagedChanges && !enableSmartCommit) { if (!noUnstagedChanges && noStagedChanges && !enableSmartCommit) {
...@@ -739,12 +739,12 @@ export class CommandCenter { ...@@ -739,12 +739,12 @@ export class CommandCenter {
return false; return false;
} }
await model.commit(message, opts); await repository.commit(message, opts);
return true; return true;
} }
private async commitWithAnyInput(model: Repository, opts?: CommitOptions): Promise<void> { private async commitWithAnyInput(repository: Repository, opts?: CommitOptions): Promise<void> {
const message = scm.inputBox.value; const message = scm.inputBox.value;
const getCommitMessage = async () => { const getCommitMessage = async () => {
if (message) { if (message) {
...@@ -758,78 +758,78 @@ export class CommandCenter { ...@@ -758,78 +758,78 @@ export class CommandCenter {
}); });
}; };
const didCommit = await this.smartCommit(model, getCommitMessage, opts); const didCommit = await this.smartCommit(repository, getCommitMessage, opts);
if (message && didCommit) { if (message && didCommit) {
scm.inputBox.value = await model.getCommitTemplate(); scm.inputBox.value = await repository.getCommitTemplate();
} }
} }
@command('git.commit', { model: true }) @command('git.commit', { model: true })
async commit(model: Repository): Promise<void> { async commit(repository: Repository): Promise<void> {
await this.commitWithAnyInput(model); await this.commitWithAnyInput(repository);
} }
@command('git.commitWithInput', { model: true }) @command('git.commitWithInput', { model: true })
async commitWithInput(model: Repository): Promise<void> { async commitWithInput(repository: Repository): Promise<void> {
if (!scm.inputBox.value) { if (!scm.inputBox.value) {
return; return;
} }
const didCommit = await this.smartCommit(model, async () => scm.inputBox.value); const didCommit = await this.smartCommit(repository, async () => scm.inputBox.value);
if (didCommit) { if (didCommit) {
scm.inputBox.value = await model.getCommitTemplate(); scm.inputBox.value = await repository.getCommitTemplate();
} }
} }
@command('git.commitStaged', { model: true }) @command('git.commitStaged', { model: true })
async commitStaged(model: Repository): Promise<void> { async commitStaged(repository: Repository): Promise<void> {
await this.commitWithAnyInput(model, { all: false }); await this.commitWithAnyInput(repository, { all: false });
} }
@command('git.commitStagedSigned', { model: true }) @command('git.commitStagedSigned', { model: true })
async commitStagedSigned(model: Repository): Promise<void> { async commitStagedSigned(repository: Repository): Promise<void> {
await this.commitWithAnyInput(model, { all: false, signoff: true }); await this.commitWithAnyInput(repository, { all: false, signoff: true });
} }
@command('git.commitStagedAmend', { model: true }) @command('git.commitStagedAmend', { model: true })
async commitStagedAmend(model: Repository): Promise<void> { async commitStagedAmend(repository: Repository): Promise<void> {
await this.commitWithAnyInput(model, { all: false, amend: true }); await this.commitWithAnyInput(repository, { all: false, amend: true });
} }
@command('git.commitAll', { model: true }) @command('git.commitAll', { model: true })
async commitAll(model: Repository): Promise<void> { async commitAll(repository: Repository): Promise<void> {
await this.commitWithAnyInput(model, { all: true }); await this.commitWithAnyInput(repository, { all: true });
} }
@command('git.commitAllSigned', { model: true }) @command('git.commitAllSigned', { model: true })
async commitAllSigned(model: Repository): Promise<void> { async commitAllSigned(repository: Repository): Promise<void> {
await this.commitWithAnyInput(model, { all: true, signoff: true }); await this.commitWithAnyInput(repository, { all: true, signoff: true });
} }
@command('git.commitAllAmend', { model: true }) @command('git.commitAllAmend', { model: true })
async commitAllAmend(model: Repository): Promise<void> { async commitAllAmend(repository: Repository): Promise<void> {
await this.commitWithAnyInput(model, { all: true, amend: true }); await this.commitWithAnyInput(repository, { all: true, amend: true });
} }
@command('git.undoCommit', { model: true }) @command('git.undoCommit', { model: true })
async undoCommit(model: Repository): Promise<void> { async undoCommit(repository: Repository): Promise<void> {
const HEAD = model.HEAD; const HEAD = repository.HEAD;
if (!HEAD || !HEAD.commit) { if (!HEAD || !HEAD.commit) {
return; return;
} }
const commit = await model.getCommit('HEAD'); const commit = await repository.getCommit('HEAD');
await model.reset('HEAD~'); await repository.reset('HEAD~');
scm.inputBox.value = commit.message; scm.inputBox.value = commit.message;
} }
@command('git.checkout', { model: true }) @command('git.checkout', { model: true })
async checkout(model: Repository, treeish: string): Promise<void> { async checkout(repository: Repository, treeish: string): Promise<void> {
if (typeof treeish === 'string') { if (typeof treeish === 'string') {
return await model.checkout(treeish); return await repository.checkout(treeish);
} }
const config = workspace.getConfiguration('git'); const config = workspace.getConfiguration('git');
...@@ -839,13 +839,13 @@ export class CommandCenter { ...@@ -839,13 +839,13 @@ export class CommandCenter {
const createBranch = new CreateBranchItem(); const createBranch = new CreateBranchItem();
const heads = model.refs.filter(ref => ref.type === RefType.Head) const heads = repository.refs.filter(ref => ref.type === RefType.Head)
.map(ref => new CheckoutItem(ref)); .map(ref => new CheckoutItem(ref));
const tags = (includeTags ? model.refs.filter(ref => ref.type === RefType.Tag) : []) const tags = (includeTags ? repository.refs.filter(ref => ref.type === RefType.Tag) : [])
.map(ref => new CheckoutTagItem(ref)); .map(ref => new CheckoutTagItem(ref));
const remoteHeads = (includeRemotes ? model.refs.filter(ref => ref.type === RefType.RemoteHead) : []) const remoteHeads = (includeRemotes ? repository.refs.filter(ref => ref.type === RefType.RemoteHead) : [])
.map(ref => new CheckoutRemoteHeadItem(ref)); .map(ref => new CheckoutRemoteHeadItem(ref));
const picks = [createBranch, ...heads, ...tags, ...remoteHeads]; const picks = [createBranch, ...heads, ...tags, ...remoteHeads];
...@@ -856,11 +856,11 @@ export class CommandCenter { ...@@ -856,11 +856,11 @@ export class CommandCenter {
return; return;
} }
await choice.run(model); await choice.run(repository);
} }
@command('git.branch', { model: true }) @command('git.branch', { model: true })
async branch(model: Repository): Promise<void> { async branch(repository: Repository): Promise<void> {
const result = await window.showInputBox({ const result = await window.showInputBox({
placeHolder: localize('branch name', "Branch name"), placeHolder: localize('branch name', "Branch name"),
prompt: localize('provide branch name', "Please provide a branch name"), prompt: localize('provide branch name', "Please provide a branch name"),
...@@ -872,17 +872,17 @@ export class CommandCenter { ...@@ -872,17 +872,17 @@ export class CommandCenter {
} }
const name = result.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-'); const name = result.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-');
await model.branch(name); await repository.branch(name);
} }
@command('git.deleteBranch', { model: true }) @command('git.deleteBranch', { model: true })
async deleteBranch(model: Repository, name: string, force?: boolean): Promise<void> { async deleteBranch(repository: Repository, name: string, force?: boolean): Promise<void> {
let run: (force?: boolean) => Promise<void>; let run: (force?: boolean) => Promise<void>;
if (typeof name === 'string') { if (typeof name === 'string') {
run = force => model.deleteBranch(name, force); run = force => repository.deleteBranch(name, force);
} else { } else {
const currentHead = model.HEAD && model.HEAD.name; const currentHead = repository.HEAD && repository.HEAD.name;
const heads = model.refs.filter(ref => ref.type === RefType.Head && ref.name !== currentHead) const heads = repository.refs.filter(ref => ref.type === RefType.Head && ref.name !== currentHead)
.map(ref => new BranchDeleteItem(ref)); .map(ref => new BranchDeleteItem(ref));
const placeHolder = localize('select branch to delete', 'Select a branch to delete'); const placeHolder = localize('select branch to delete', 'Select a branch to delete');
...@@ -892,7 +892,7 @@ export class CommandCenter { ...@@ -892,7 +892,7 @@ export class CommandCenter {
return; return;
} }
name = choice.branchName; name = choice.branchName;
run = force => choice.run(model, force); run = force => choice.run(repository, force);
} }
try { try {
...@@ -913,16 +913,16 @@ export class CommandCenter { ...@@ -913,16 +913,16 @@ export class CommandCenter {
} }
@command('git.merge', { model: true }) @command('git.merge', { model: true })
async merge(model: Repository): Promise<void> { async merge(repository: Repository): Promise<void> {
const config = workspace.getConfiguration('git'); const config = workspace.getConfiguration('git');
const checkoutType = config.get<string>('checkoutType') || 'all'; const checkoutType = config.get<string>('checkoutType') || 'all';
const includeRemotes = checkoutType === 'all' || checkoutType === 'remote'; const includeRemotes = checkoutType === 'all' || checkoutType === 'remote';
const heads = model.refs.filter(ref => ref.type === RefType.Head) const heads = repository.refs.filter(ref => ref.type === RefType.Head)
.filter(ref => ref.name || ref.commit) .filter(ref => ref.name || ref.commit)
.map(ref => new MergeItem(ref as Branch)); .map(ref => new MergeItem(ref as Branch));
const remoteHeads = (includeRemotes ? model.refs.filter(ref => ref.type === RefType.RemoteHead) : []) const remoteHeads = (includeRemotes ? repository.refs.filter(ref => ref.type === RefType.RemoteHead) : [])
.filter(ref => ref.name || ref.commit) .filter(ref => ref.name || ref.commit)
.map(ref => new MergeItem(ref as Branch)); .map(ref => new MergeItem(ref as Branch));
...@@ -935,7 +935,7 @@ export class CommandCenter { ...@@ -935,7 +935,7 @@ export class CommandCenter {
} }
try { try {
await choice.run(model); await choice.run(repository);
} catch (err) { } catch (err) {
if (err.gitErrorCode !== GitErrorCodes.Conflict) { if (err.gitErrorCode !== GitErrorCodes.Conflict) {
throw err; throw err;
...@@ -947,7 +947,7 @@ export class CommandCenter { ...@@ -947,7 +947,7 @@ export class CommandCenter {
} }
@command('git.createTag', { model: true }) @command('git.createTag', { model: true })
async createTag(model: Repository): Promise<void> { async createTag(repository: Repository): Promise<void> {
const inputTagName = await window.showInputBox({ const inputTagName = await window.showInputBox({
placeHolder: localize('tag name', "Tag name"), placeHolder: localize('tag name', "Tag name"),
prompt: localize('provide tag name', "Please provide a tag name"), prompt: localize('provide tag name', "Please provide a tag name"),
...@@ -966,12 +966,12 @@ export class CommandCenter { ...@@ -966,12 +966,12 @@ export class CommandCenter {
const name = inputTagName.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-'); const name = inputTagName.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-');
const message = inputMessage || name; const message = inputMessage || name;
await model.tag(name, message); await repository.tag(name, message);
} }
@command('git.pullFrom', { model: true }) @command('git.pullFrom', { model: true })
async pullFrom(model: Repository): Promise<void> { async pullFrom(repository: Repository): Promise<void> {
const remotes = model.remotes; const remotes = repository.remotes;
if (remotes.length === 0) { if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from.")); window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from."));
...@@ -996,74 +996,74 @@ export class CommandCenter { ...@@ -996,74 +996,74 @@ export class CommandCenter {
return; return;
} }
model.pull(false, pick.label, branchName); repository.pull(false, pick.label, branchName);
} }
@command('git.pull', { model: true }) @command('git.pull', { model: true })
async pull(model: Repository): Promise<void> { async pull(repository: Repository): Promise<void> {
const remotes = model.remotes; const remotes = repository.remotes;
if (remotes.length === 0) { if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from.")); window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from."));
return; return;
} }
await model.pull(); await repository.pull();
} }
@command('git.pullRebase', { model: true }) @command('git.pullRebase', { model: true })
async pullRebase(model: Repository): Promise<void> { async pullRebase(repository: Repository): Promise<void> {
const remotes = model.remotes; const remotes = repository.remotes;
if (remotes.length === 0) { if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from.")); window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from."));
return; return;
} }
await model.pullWithRebase(); await repository.pullWithRebase();
} }
@command('git.push', { model: true }) @command('git.push', { model: true })
async push(model: Repository): Promise<void> { async push(repository: Repository): Promise<void> {
const remotes = model.remotes; const remotes = repository.remotes;
if (remotes.length === 0) { if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to.")); window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to."));
return; return;
} }
await model.push(); await repository.push();
} }
@command('git.pushWithTags', { model: true }) @command('git.pushWithTags', { model: true })
async pushWithTags(model: Repository): Promise<void> { async pushWithTags(repository: Repository): Promise<void> {
const remotes = model.remotes; const remotes = repository.remotes;
if (remotes.length === 0) { if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to.")); window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to."));
return; return;
} }
await model.pushTags(); await repository.pushTags();
window.showInformationMessage(localize('push with tags success', "Successfully pushed with tags.")); window.showInformationMessage(localize('push with tags success', "Successfully pushed with tags."));
} }
@command('git.pushTo', { model: true }) @command('git.pushTo', { model: true })
async pushTo(model: Repository): Promise<void> { async pushTo(repository: Repository): Promise<void> {
const remotes = model.remotes; const remotes = repository.remotes;
if (remotes.length === 0) { if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to.")); window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to."));
return; return;
} }
if (!model.HEAD || !model.HEAD.name) { if (!repository.HEAD || !repository.HEAD.name) {
window.showWarningMessage(localize('nobranch', "Please check out a branch to push to a remote.")); window.showWarningMessage(localize('nobranch', "Please check out a branch to push to a remote."));
return; return;
} }
const branchName = model.HEAD.name; const branchName = repository.HEAD.name;
const picks = remotes.map(r => ({ label: r.name, description: r.url })); const picks = remotes.map(r => ({ label: r.name, description: r.url }));
const placeHolder = localize('pick remote', "Pick a remote to publish the branch '{0}' to:", branchName); const placeHolder = localize('pick remote', "Pick a remote to publish the branch '{0}' to:", branchName);
const pick = await window.showQuickPick(picks, { placeHolder }); const pick = await window.showQuickPick(picks, { placeHolder });
...@@ -1072,12 +1072,12 @@ export class CommandCenter { ...@@ -1072,12 +1072,12 @@ export class CommandCenter {
return; return;
} }
model.pushTo(pick.label, branchName); repository.pushTo(pick.label, branchName);
} }
@command('git.sync', { model: true }) @command('git.sync', { model: true })
async sync(model: Repository): Promise<void> { async sync(repository: Repository): Promise<void> {
const HEAD = model.HEAD; const HEAD = repository.HEAD;
if (!HEAD || !HEAD.upstream) { if (!HEAD || !HEAD.upstream) {
return; return;
...@@ -1099,20 +1099,20 @@ export class CommandCenter { ...@@ -1099,20 +1099,20 @@ export class CommandCenter {
} }
} }
await model.sync(); await repository.sync();
} }
@command('git.publish', { model: true }) @command('git.publish', { model: true })
async publish(model: Repository): Promise<void> { async publish(repository: Repository): Promise<void> {
const remotes = model.remotes; const remotes = repository.remotes;
if (remotes.length === 0) { if (remotes.length === 0) {
window.showWarningMessage(localize('no remotes to publish', "Your repository has no remotes configured to publish to.")); window.showWarningMessage(localize('no remotes to publish', "Your repository has no remotes configured to publish to."));
return; return;
} }
const branchName = model.HEAD && model.HEAD.name || ''; const branchName = repository.HEAD && repository.HEAD.name || '';
const picks = model.remotes.map(r => r.name); const picks = repository.remotes.map(r => r.name);
const placeHolder = localize('pick remote', "Pick a remote to publish the branch '{0}' to:", branchName); const placeHolder = localize('pick remote', "Pick a remote to publish the branch '{0}' to:", branchName);
const choice = await window.showQuickPick(picks, { placeHolder }); const choice = await window.showQuickPick(picks, { placeHolder });
...@@ -1120,7 +1120,7 @@ export class CommandCenter { ...@@ -1120,7 +1120,7 @@ export class CommandCenter {
return; return;
} }
await model.pushTo(choice, branchName, true); await repository.pushTo(choice, branchName, true);
} }
@command('git.showOutput') @command('git.showOutput')
...@@ -1129,7 +1129,7 @@ export class CommandCenter { ...@@ -1129,7 +1129,7 @@ export class CommandCenter {
} }
@command('git.ignore', { model: true }) @command('git.ignore', { model: true })
async ignore(model: Repository, ...resourceStates: SourceControlResourceState[]): Promise<void> { async ignore(repository: Repository, ...resourceStates: SourceControlResourceState[]): Promise<void> {
if (resourceStates.length === 0 || !(resourceStates[0].resourceUri instanceof Uri)) { if (resourceStates.length === 0 || !(resourceStates[0].resourceUri instanceof Uri)) {
const uri = window.activeTextEditor && window.activeTextEditor.document.uri; const uri = window.activeTextEditor && window.activeTextEditor.document.uri;
...@@ -1137,7 +1137,7 @@ export class CommandCenter { ...@@ -1137,7 +1137,7 @@ export class CommandCenter {
return; return;
} }
return await model.ignore([uri]); return await repository.ignore([uri]);
} }
const uris = resourceStates const uris = resourceStates
...@@ -1148,12 +1148,12 @@ export class CommandCenter { ...@@ -1148,12 +1148,12 @@ export class CommandCenter {
return; return;
} }
await model.ignore(uris); await repository.ignore(uris);
} }
@command('git.stash', { model: true }) @command('git.stash', { model: true })
async stash(model: Repository): Promise<void> { async stash(repository: Repository): Promise<void> {
if (model.workingTreeGroup.resources.length === 0) { if (repository.workingTreeGroup.resourceStates.length === 0) {
window.showInformationMessage(localize('no changes stash', "There are no changes to stash.")); window.showInformationMessage(localize('no changes stash', "There are no changes to stash."));
return; return;
} }
...@@ -1167,12 +1167,12 @@ export class CommandCenter { ...@@ -1167,12 +1167,12 @@ export class CommandCenter {
return; return;
} }
await model.createStash(message); await repository.createStash(message);
} }
@command('git.stashPop', { model: true }) @command('git.stashPop', { model: true })
async stashPop(model: Repository): Promise<void> { async stashPop(repository: Repository): Promise<void> {
const stashes = await model.getStashes(); const stashes = await repository.getStashes();
if (stashes.length === 0) { if (stashes.length === 0) {
window.showInformationMessage(localize('no stashes', "There are no stashes to restore.")); window.showInformationMessage(localize('no stashes', "There are no stashes to restore."));
...@@ -1187,19 +1187,19 @@ export class CommandCenter { ...@@ -1187,19 +1187,19 @@ export class CommandCenter {
return; return;
} }
await model.popStash(choice.id); await repository.popStash(choice.id);
} }
@command('git.stashPopLatest', { model: true }) @command('git.stashPopLatest', { model: true })
async stashPopLatest(model: Repository): Promise<void> { async stashPopLatest(repository: Repository): Promise<void> {
const stashes = await model.getStashes(); const stashes = await repository.getStashes();
if (stashes.length === 0) { if (stashes.length === 0) {
window.showInformationMessage(localize('no stashes', "There are no stashes to restore.")); window.showInformationMessage(localize('no stashes', "There are no stashes to restore."));
return; return;
} }
await model.popStash(); await repository.popStash();
} }
private createCommand(id: string, key: string, method: Function, options: CommandOptions): (...args: any[]) => any { private createCommand(id: string, key: string, method: Function, options: CommandOptions): (...args: any[]) => any {
...@@ -1292,8 +1292,8 @@ export class CommandCenter { ...@@ -1292,8 +1292,8 @@ export class CommandCenter {
return undefined; return undefined;
} }
return repository.workingTreeGroup.resources.filter(r => r.resourceUri.toString() === uriString)[0] return repository.workingTreeGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString)[0]
|| repository.indexGroup.resources.filter(r => r.resourceUri.toString() === uriString)[0]; || repository.indexGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString)[0];
} }
} }
......
...@@ -30,9 +30,9 @@ export class GitContentProvider { ...@@ -30,9 +30,9 @@ export class GitContentProvider {
private cache: Cache = Object.create(null); private cache: Cache = Object.create(null);
private disposables: Disposable[] = []; private disposables: Disposable[] = [];
constructor(private model: Repository) { constructor(private repository: Repository) {
this.disposables.push( this.disposables.push(
model.onDidChangeRepository(this.eventuallyFireChangeEvents, this), repository.onDidChangeRepository(this.eventuallyFireChangeEvents, this),
workspace.registerTextDocumentContentProvider('git', this) workspace.registerTextDocumentContentProvider('git', this)
); );
...@@ -61,12 +61,12 @@ export class GitContentProvider { ...@@ -61,12 +61,12 @@ export class GitContentProvider {
if (ref === '~') { if (ref === '~') {
const fileUri = Uri.file(path); const fileUri = Uri.file(path);
const uriString = fileUri.toString(); 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'; ref = indexStatus ? '' : 'HEAD';
} }
try { try {
return await this.model.show(ref, path); return await this.repository.show(ref, path);
} catch (err) { } catch (err) {
return ''; return '';
} }
......
...@@ -11,9 +11,7 @@ import { ExtensionContext, workspace, window, Disposable, commands, Uri } from ' ...@@ -11,9 +11,7 @@ import { ExtensionContext, workspace, window, Disposable, commands, Uri } from '
import { findGit, Git, IGit } from './git'; import { findGit, Git, IGit } from './git';
import { Repository } from './repository'; import { Repository } from './repository';
import { Model } from './model'; import { Model } from './model';
import { GitSCMProvider } from './scmProvider';
import { CommandCenter } from './commands'; import { CommandCenter } from './commands';
import { StatusBarCommands } from './statusbar';
import { GitContentProvider } from './contentProvider'; import { GitContentProvider } from './contentProvider';
import { AutoFetcher } from './autofetch'; import { AutoFetcher } from './autofetch';
import { Askpass } from './askpass'; import { Askpass } from './askpass';
...@@ -56,14 +54,11 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi ...@@ -56,14 +54,11 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
disposables.push(toDisposable(() => git.onOutput.removeListener('log', onOutput))); disposables.push(toDisposable(() => git.onOutput.removeListener('log', onOutput)));
const commandCenter = new CommandCenter(git, model, outputChannel, telemetryReporter); 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 contentProvider = new GitContentProvider(repository);
const autoFetcher = new AutoFetcher(repository); const autoFetcher = new AutoFetcher(repository);
disposables.push( disposables.push(
commandCenter, commandCenter,
provider,
contentProvider, contentProvider,
autoFetcher, autoFetcher,
repository repository
......
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
'use strict'; '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 { Git, Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash } from './git';
import { anyEvent, eventToPromise, filterEvent, EmptyDisposable, combinedDisposable, dispose, find } from './util'; import { anyEvent, eventToPromise, filterEvent, EmptyDisposable, combinedDisposable, dispose, find } from './util';
import { memoize, throttle, debounce } from './decorators'; import { memoize, throttle, debounce } from './decorators';
import { toGitUri } from './uri';
import * as path from 'path'; import * as path from 'path';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import * as fs from 'fs'; import * as fs from 'fs';
...@@ -49,6 +50,12 @@ export enum Status { ...@@ -49,6 +50,12 @@ export enum Status {
BOTH_MODIFIED BOTH_MODIFIED
} }
export enum ResourceGroupType {
Merge,
Index,
WorkingTree
}
export class Resource implements SourceControlResourceState { export class Resource implements SourceControlResourceState {
@memoize @memoize
...@@ -69,7 +76,7 @@ export class Resource implements SourceControlResourceState { ...@@ -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 type(): Status { return this._type; }
get original(): Uri { return this._resourceUri; } get original(): Uri { return this._resourceUri; }
get renameResourceUri(): Uri | undefined { return this._renameResourceUri; } get renameResourceUri(): Uri | undefined { return this._renameResourceUri; }
...@@ -149,52 +156,13 @@ export class Resource implements SourceControlResourceState { ...@@ -149,52 +156,13 @@ export class Resource implements SourceControlResourceState {
constructor( constructor(
private workspaceRoot: Uri, private workspaceRoot: Uri,
private _resourceGroup: ResourceGroup, private _resourceGroupType: ResourceGroupType,
private _resourceUri: Uri, private _resourceUri: Uri,
private _type: Status, private _type: Status,
private _renameResourceUri?: Uri 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 { export enum Operation {
Status = 1 << 0, Status = 1 << 0,
Add = 1 << 1, Add = 1 << 1,
...@@ -302,6 +270,10 @@ export interface IRepository { ...@@ -302,6 +270,10 @@ export interface IRepository {
clean(resources: Uri[]): Promise<void>; clean(resources: Uri[]): Promise<void>;
} }
export interface GitResourceGroup extends SourceControlResourceGroup {
resourceStates: Resource[];
}
export class Repository implements IRepository, Disposable { export class Repository implements IRepository, Disposable {
private _onDidChangeRepository = new EventEmitter<Uri>(); private _onDidChangeRepository = new EventEmitter<Uri>();
...@@ -310,12 +282,9 @@ export class Repository implements IRepository, Disposable { ...@@ -310,12 +282,9 @@ export class Repository implements IRepository, Disposable {
private _onDidChangeState = new EventEmitter<State>(); private _onDidChangeState = new EventEmitter<State>();
readonly onDidChangeState: Event<State> = this._onDidChangeState.event; readonly onDidChangeState: Event<State> = this._onDidChangeState.event;
private _onDidChangeResources = new EventEmitter<void>();
readonly onDidChangeResources: Event<void> = this._onDidChangeResources.event;
@memoize @memoize
get onDidChange(): Event<void> { get onDidChange(): Event<void> {
return anyEvent<any>(this.onDidChangeState, this.onDidChangeResources); return anyEvent<any>(this.onDidChangeState);
} }
private _onRunOperation = new EventEmitter<Operation>(); private _onRunOperation = new EventEmitter<Operation>();
...@@ -329,14 +298,17 @@ export class Repository implements IRepository, Disposable { ...@@ -329,14 +298,17 @@ export class Repository implements IRepository, Disposable {
return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>); return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>);
} }
private _mergeGroup = new MergeGroup([]); private _sourceControl: SourceControl;
get mergeGroup(): MergeGroup { return this._mergeGroup; } get sourceControl(): SourceControl { return this._sourceControl; }
private _mergeGroup: SourceControlResourceGroup;
get mergeGroup(): GitResourceGroup { return this._mergeGroup as GitResourceGroup; }
private _indexGroup = new IndexGroup([]); private _indexGroup: SourceControlResourceGroup;
get indexGroup(): IndexGroup { return this._indexGroup; } get indexGroup(): GitResourceGroup { return this._indexGroup as GitResourceGroup; }
private _workingTreeGroup = new WorkingTreeGroup([]); private _workingTreeGroup: SourceControlResourceGroup;
get workingTreeGroup(): WorkingTreeGroup { return this._workingTreeGroup; } get workingTreeGroup(): GitResourceGroup { return this._workingTreeGroup as GitResourceGroup; }
private _HEAD: Branch | undefined; private _HEAD: Branch | undefined;
get HEAD(): Branch | undefined { get HEAD(): Branch | undefined {
...@@ -367,10 +339,11 @@ export class Repository implements IRepository, Disposable { ...@@ -367,10 +339,11 @@ export class Repository implements IRepository, Disposable {
this._HEAD = undefined; this._HEAD = undefined;
this._refs = []; this._refs = [];
this._remotes = []; this._remotes = [];
this._mergeGroup = new MergeGroup(); this.mergeGroup.resourceStates = [];
this._indexGroup = new IndexGroup(); this.indexGroup.resourceStates = [];
this._workingTreeGroup = new WorkingTreeGroup(); this.workingTreeGroup.resourceStates = [];
this._onDidChangeResources.fire(); this._sourceControl.count = 0;
commands.executeCommand('setContext', 'gitState', '');
} }
private onWorkspaceChange: Event<Uri>; private onWorkspaceChange: Event<Uri>;
...@@ -387,9 +360,43 @@ export class Repository implements IRepository, Disposable { ...@@ -387,9 +360,43 @@ export class Repository implements IRepository, Disposable {
this.onWorkspaceChange = anyEvent(fsWatcher.onDidChange, fsWatcher.onDidCreate, fsWatcher.onDidDelete); this.onWorkspaceChange = anyEvent(fsWatcher.onDidChange, fsWatcher.onDidCreate, fsWatcher.onDidDelete);
this.disposables.push(fsWatcher); 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(); 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 @throttle
async init(): Promise<void> { async init(): Promise<void> {
if (this.state !== State.NotAGitRepository) { if (this.state !== State.NotAGitRepository) {
...@@ -435,7 +442,7 @@ export class Repository implements IRepository, Disposable { ...@@ -435,7 +442,7 @@ export class Repository implements IRepository, Disposable {
resources.forEach(r => { resources.forEach(r => {
const raw = r.toString(); 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) { if (!scmResource) {
return; return;
...@@ -731,37 +738,59 @@ export class Repository implements IRepository, Disposable { ...@@ -731,37 +738,59 @@ export class Repository implements IRepository, Disposable {
const renameUri = raw.rename ? Uri.file(path.join(this.repository.root, raw.rename)) : undefined; const renameUri = raw.rename ? Uri.file(path.join(this.repository.root, raw.rename)) : undefined;
switch (raw.x + raw.y) { 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, ResourceGroupType.WorkingTree, uri, Status.UNTRACKED));
case '!!': return workingTree.push(new Resource(this.workspaceRoot, this.workingTreeGroup, uri, Status.IGNORED)); case '!!': return workingTree.push(new Resource(this.workspaceRoot, ResourceGroupType.WorkingTree, uri, Status.IGNORED));
case 'DD': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.BOTH_DELETED)); case 'DD': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.BOTH_DELETED));
case 'AU': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.ADDED_BY_US)); 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, this.mergeGroup, uri, Status.DELETED_BY_THEM)); 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, this.mergeGroup, uri, Status.ADDED_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, this.mergeGroup, uri, Status.DELETED_BY_US)); 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, this.mergeGroup, uri, Status.BOTH_ADDED)); case 'AA': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.BOTH_ADDED));
case 'UU': return merge.push(new Resource(this.workspaceRoot, this.mergeGroup, uri, Status.BOTH_MODIFIED)); case 'UU': return merge.push(new Resource(this.workspaceRoot, ResourceGroupType.Merge, uri, Status.BOTH_MODIFIED));
} }
let isModifiedInIndex = false; let isModifiedInIndex = false;
switch (raw.x) { switch (raw.x) {
case 'M': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; 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, this.indexGroup, uri, Status.INDEX_ADDED)); break; case 'A': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_ADDED)); break;
case 'D': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_DELETED)); break; case 'D': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_DELETED)); break;
case 'R': index.push(new Resource(this.workspaceRoot, this.indexGroup, uri, Status.INDEX_RENAMED, renameUri)); 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, this.indexGroup, uri, Status.INDEX_COPIED, renameUri)); break; case 'C': index.push(new Resource(this.workspaceRoot, ResourceGroupType.Index, uri, Status.INDEX_COPIED, renameUri)); break;
} }
switch (raw.y) { switch (raw.y) {
case 'M': workingTree.push(new Resource(this.workspaceRoot, this.workingTreeGroup, uri, Status.MODIFIED, 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, this.workingTreeGroup, uri, Status.DELETED, renameUri)); break; case 'D': workingTree.push(new Resource(this.workspaceRoot, ResourceGroupType.WorkingTree, uri, Status.DELETED, renameUri)); break;
} }
}); });
this._mergeGroup = new MergeGroup(merge); // set resource groups
this._indexGroup = new IndexGroup(index); this.mergeGroup.resourceStates = merge;
this._workingTreeGroup = new WorkingTreeGroup(workingTree); this.indexGroup.resourceStates = index;
this._onDidChangeResources.fire(); 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 { 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 { ...@@ -19,25 +19,25 @@ class CheckoutStatusBar {
get onDidChange(): Event<void> { return this._onDidChange.event; } get onDidChange(): Event<void> { return this._onDidChange.event; }
private disposables: Disposable[] = []; private disposables: Disposable[] = [];
constructor(private model: Repository) { constructor(private repository: Repository) {
model.onDidChange(this._onDidChange.fire, this._onDidChange, this.disposables); repository.onDidChange(this._onDidChange.fire, this._onDidChange, this.disposables);
} }
get command(): Command | undefined { get command(): Command | undefined {
const HEAD = this.model.HEAD; const HEAD = this.repository.HEAD;
if (!HEAD) { if (!HEAD) {
return undefined; 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 tagName = tag && tag.name;
const head = HEAD.name || tagName || (HEAD.commit || '').substr(0, 8); const head = HEAD.name || tagName || (HEAD.commit || '').substr(0, 8);
const title = '$(git-branch) ' const title = '$(git-branch) '
+ head + head
+ (this.model.workingTreeGroup.resources.length > 0 ? '*' : '') + (this.repository.workingTreeGroup.resourceStates.length > 0 ? '*' : '')
+ (this.model.indexGroup.resources.length > 0 ? '+' : '') + (this.repository.indexGroup.resourceStates.length > 0 ? '+' : '')
+ (this.model.mergeGroup.resources.length > 0 ? '!' : ''); + (this.repository.mergeGroup.resourceStates.length > 0 ? '!' : '');
return { return {
command: 'git.checkout', command: 'git.checkout',
...@@ -76,24 +76,24 @@ class SyncStatusBar { ...@@ -76,24 +76,24 @@ class SyncStatusBar {
this._onDidChange.fire(); this._onDidChange.fire();
} }
constructor(private model: Repository) { constructor(private repository: Repository) {
model.onDidChange(this.onModelChange, this, this.disposables); repository.onDidChange(this.onModelChange, this, this.disposables);
model.onDidChangeOperations(this.onOperationsChange, this, this.disposables); repository.onDidChangeOperations(this.onOperationsChange, this, this.disposables);
this._onDidChange.fire(); this._onDidChange.fire();
} }
private onOperationsChange(): void { private onOperationsChange(): void {
this.state = { this.state = {
...this.state, ...this.state,
isSyncRunning: this.model.operations.isRunning(Operation.Sync) isSyncRunning: this.repository.operations.isRunning(Operation.Sync)
}; };
} }
private onModelChange(): void { private onModelChange(): void {
this.state = { this.state = {
...this.state, ...this.state,
hasRemotes: this.model.remotes.length > 0, hasRemotes: this.repository.remotes.length > 0,
HEAD: this.model.HEAD HEAD: this.repository.HEAD
}; };
} }
...@@ -149,9 +149,9 @@ export class StatusBarCommands { ...@@ -149,9 +149,9 @@ export class StatusBarCommands {
private checkoutStatusBar: CheckoutStatusBar; private checkoutStatusBar: CheckoutStatusBar;
private disposables: Disposable[] = []; private disposables: Disposable[] = [];
constructor(model: Repository) { constructor(repository: Repository) {
this.syncStatusBar = new SyncStatusBar(model); this.syncStatusBar = new SyncStatusBar(repository);
this.checkoutStatusBar = new CheckoutStatusBar(model); this.checkoutStatusBar = new CheckoutStatusBar(repository);
} }
get onDidChange(): Event<void> { get onDidChange(): Event<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册