diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 0cdffc48a73..b0867be6d09 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -49,16 +49,24 @@ function cleanAll(model: Model, resourceGroup: ResourceGroup): void { } function resolveURI(command: (t: SCMResource | SCMResourceGroup | undefined) => R): (uri: Uri) => R | undefined { - return uri => uri.authority !== 'git' ? undefined : command(scm.getResourceFromURI(uri)); -} + return uri => { + if (uri.authority !== 'git') { + return; + } -function skipUndefined(command: (t: T) => R): (t: T | undefined) => R | undefined { - return t => t === undefined ? undefined : command(t); + const result = scm.getResourceFromURI(uri); + + if (!result) { + return; + } + + return command(result); + }; } // TODO: do more with these errors -function catchErrors(command: (t: T) => Promise): (t: T) => void { - return t => command(t).catch(err => console.error(err)); +function catchErrors(command: (...args: any[]) => Promise): (...args: any[]) => void { + return (...args) => command(...args).catch(err => console.error(err)); } function compose(command: Command, ...args: Function[]): Command { @@ -70,14 +78,14 @@ export function registerCommands(model: Model): Disposable { const disposables = [ commands.registerCommand('git.refresh', compose(refresh, bindModel)), - commands.registerCommand('git.openChange', compose(openChange, bindModel, resolveURI, skipUndefined)), - commands.registerCommand('git.openFile', compose(openFile, bindModel, resolveURI, skipUndefined)), - commands.registerCommand('git.stage', compose(stage, bindModel, resolveURI, skipUndefined, catchErrors)), - commands.registerCommand('git.stageAll', compose(stageAll, bindModel, catchErrors)), - commands.registerCommand('git.unstage', compose(unstage, bindModel, resolveURI, skipUndefined, catchErrors)), - commands.registerCommand('git.unstageAll', compose(unstageAll, bindModel, catchErrors)), - commands.registerCommand('git.clean', compose(clean, bindModel, resolveURI, skipUndefined)), - commands.registerCommand('git.cleanAll', compose(cleanAll, bindModel, resolveURI, skipUndefined)), + commands.registerCommand('git.openChange', compose(openChange, bindModel, resolveURI)), + commands.registerCommand('git.openFile', compose(openFile, bindModel, resolveURI)), + commands.registerCommand('git.stage', compose(stage, catchErrors, bindModel, resolveURI)), + commands.registerCommand('git.stageAll', compose(stageAll, catchErrors, bindModel)), + commands.registerCommand('git.unstage', compose(unstage, catchErrors, bindModel, resolveURI)), + commands.registerCommand('git.unstageAll', compose(unstageAll, catchErrors, bindModel)), + commands.registerCommand('git.clean', compose(clean, bindModel, resolveURI)), + commands.registerCommand('git.cleanAll', compose(cleanAll, bindModel, resolveURI)), ]; return Disposable.from(...disposables); diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index 8edb1ceaf9a..3ec286a7658 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -9,7 +9,6 @@ import { scm, ExtensionContext, workspace, Uri, window, Disposable } from 'vscod import * as path from 'path'; import { findGit, Git } from './git'; import { Model } from './model'; -import { log } from './util'; import { GitSCMProvider } from './scmProvider'; import { registerCommands } from './commands'; import * as nls from 'vscode-nls'; @@ -52,8 +51,6 @@ async function init(disposables: Disposable[]): Promise { const model = new Model(repositoryRoot, repository); const provider = new GitSCMProvider(model); - provider.onDidChange(g => log(g)); - const outputChannel = window.createOutputChannel('git'); outputChannel.appendLine(`Using git ${info.version} from ${info.path}`); git.onOutput(str => outputChannel.append(str), null, disposables);