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

🐛 fix git clone command

fixes #22620
上级 3930741b
......@@ -27,6 +27,11 @@
"title": "%command.clone%",
"category": "Git"
},
{
"command": "git.cloneSilent",
"title": "%command.clone%",
"category": "Git"
},
{
"command": "git.init",
"title": "%command.init%",
......@@ -214,295 +219,315 @@
],
"menus": {
"commandPalette": [
{
"command": "git.clone",
"when": "false"
},
{
"command": "git.cloneSilent",
"when": "config.git.enabled"
},
{
"command": "git.init",
"when": "scmProvider == git && scmProviderState == norepo"
"when": "config.git.enabled && scmProvider == git && scmProviderState == norepo"
},
{
"command": "git.refresh",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.openChange",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.openFile",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.stage",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.stageAll",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.stageSelectedRanges",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.revertSelectedRanges",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.unstage",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.unstageAll",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.unstageSelectedRanges",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.clean",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.cleanAll",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commit",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitStaged",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitStagedSigned",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitAll",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitAllSigned",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.undoCommit",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.checkout",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.branch",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.pull",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.pullRebase",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.push",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.pushTo",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.sync",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.publish",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.showOutput",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
}
],
"scm/title": [
{
"command": "git.init",
"group": "navigation",
"when": "scmProvider == git && scmProviderState == norepo"
"when": "config.git.enabled && scmProvider == git && scmProviderState == norepo"
},
{
"command": "git.commit",
"group": "navigation",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.refresh",
"group": "navigation",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.sync",
"group": "1_sync",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.pull",
"group": "1_sync",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.pullRebase",
"group": "1_sync",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.push",
"group": "1_sync",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.pushTo",
"group": "1_sync",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.publish",
"group": "2_publish",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitStaged",
"group": "3_commit",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitStagedSigned",
"group": "3_commit",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitAll",
"group": "3_commit",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.commitAllSigned",
"group": "3_commit",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.undoCommit",
"group": "3_commit",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.unstageAll",
"group": "4_stage",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.cleanAll",
"group": "4_stage",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
},
{
"command": "git.showOutput",
"group": "5_output",
"when": "scmProvider == git && scmProviderState == idle"
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle"
}
],
"scm/resourceGroup/context": [
{
"command": "git.stageAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"group": "1_modification"
},
{
"command": "git.stageAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"group": "inline"
},
{
"command": "git.unstageAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"group": "1_modification"
},
{
"command": "git.unstageAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"group": "inline"
},
{
"command": "git.cleanAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.stageAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.cleanAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "inline"
},
{
"command": "git.stageAll",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "inline"
}
],
"scm/resource/context": [
{
"command": "git.stage",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"group": "1_modification"
},
{
"command": "git.stage",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == merge",
"group": "inline"
},
{
"command": "git.openChange",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"group": "navigation"
},
{
"command": "git.openFile",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"group": "navigation"
},
{
"command": "git.unstage",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"group": "1_modification"
},
{
"command": "git.unstage",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == index",
"group": "inline"
},
{
"command": "git.openChange",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.openFile",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.stage",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.clean",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "1_modification"
},
{
"command": "git.clean",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "inline"
},
{
"command": "git.stage",
"when": "scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"when": "config.git.enabled && scmProvider == git && scmProviderState == idle && scmResourceGroup == workingTree",
"group": "inline"
}
],
......@@ -510,12 +535,12 @@
{
"command": "git.openFile",
"group": "navigation",
"when": "isInDiffEditor && resourceScheme != extension"
"when": "config.git.enabled && scmProvider == git && isInDiffEditor && resourceScheme != extension"
},
{
"command": "git.openChange",
"group": "navigation",
"when": "!isInDiffEditor && resourceScheme != extension"
"when": "config.git.enabled && scmProvider == git && !isInDiffEditor && resourceScheme != extension"
}
]
},
......
......@@ -6,7 +6,7 @@
'use strict';
import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, computeDiff, Range, WorkspaceEdit, Position } from 'vscode';
import { Ref, RefType } from './git';
import { Ref, RefType, Git } from './git';
import { Model, Resource, Status, CommitOptions } from './model';
import * as staging from './staging';
import * as path from 'path';
......@@ -59,15 +59,15 @@ class CheckoutRemoteHeadItem extends CheckoutItem {
}
}
const Commands: { commandId: string; key: string; method: Function; }[] = [];
const Commands: { commandId: string; key: string; method: Function; skipModelCheck: boolean; }[] = [];
function command(commandId: string): Function {
function command(commandId: string, skipModelCheck = false): Function {
return (target: any, key: string, descriptor: any) => {
if (!(typeof descriptor.value === 'function')) {
throw new Error('not supported');
}
Commands.push({ commandId, key, method: descriptor.value });
Commands.push({ commandId, key, method: descriptor.value, skipModelCheck });
};
}
......@@ -77,6 +77,7 @@ export class CommandCenter {
private disposables: Disposable[];
constructor(
private git: Git,
model: Model | undefined,
private outputChannel: OutputChannel,
private telemetryReporter: TelemetryReporter
......@@ -86,7 +87,7 @@ export class CommandCenter {
}
this.disposables = Commands
.map(({ commandId, key, method }) => commands.registerCommand(commandId, this.createCommand(commandId, key, method)));
.map(({ commandId, key, method, skipModelCheck }) => commands.registerCommand(commandId, this.createCommand(commandId, key, method, skipModelCheck)));
}
@command('git.refresh')
......@@ -169,19 +170,7 @@ export class CommandCenter {
return '';
}
/**
* Attempts to clone a git repository. Throws descriptive errors
* for usual error cases. Returns whether the user chose to open
* the resulting folder or otherwise.
*
* This only exists for the walkthrough contribution to have good
* telemetry.
*
* TODO@Christof: when all the telemetry questions are answered,
* please clean this up into a single clone method.
*/
@command('_git.clone')
async _clone(): Promise<boolean> {
private async _clone(): Promise<boolean> {
const url = await window.showInputBox({
prompt: localize('repourl', "Repository URL"),
ignoreFocusOut: true
......@@ -201,7 +190,7 @@ export class CommandCenter {
throw new Error('no_directory');
}
const clonePromise = this.model.git.clone(url, parentPath);
const clonePromise = this.git.clone(url, parentPath);
window.setStatusBarMessage(localize('cloning', "Cloning git repository..."), clonePromise);
let repositoryPath: string;
......@@ -226,8 +215,24 @@ export class CommandCenter {
return openFolder;
}
@command('git.clone')
async clone(): Promise<void> {
/**
* Attempts to clone a git repository. Throws descriptive errors
* for usual error cases. Returns whether the user chose to open
* the resulting folder or otherwise.
*
* This only exists for the walkthrough contribution to have good
* telemetry.
*
* TODO@Christof: when all the telemetry questions are answered,
* please clean this up into a single clone method.
*/
@command('git.clone', true)
async clone(): Promise<boolean> {
return await this._clone();
}
@command('git.cloneSilent', true)
async cloneSilent(): Promise<void> {
try {
await this._clone();
} catch (err) {
......@@ -710,9 +715,9 @@ export class CommandCenter {
this.outputChannel.show();
}
private createCommand(id: string, key: string, method: Function): (...args: any[]) => any {
private createCommand(id: string, key: string, method: Function, skipModelCheck: boolean): (...args: any[]) => any {
const result = (...args) => {
if (!this.model) {
if (!skipModelCheck && !this.model) {
window.showInformationMessage(localize('disabled', "Git is either disabled or not supported in this workspace"));
return;
}
......
......@@ -32,22 +32,23 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
const enabled = config.get<boolean>('enabled') === true;
const workspaceRootPath = workspace.rootPath;
const pathHint = workspace.getConfiguration('git').get<string>('path');
const info = await findGit(pathHint);
const git = new Git({ gitPath: info.path, version: info.version });
if (!workspaceRootPath || !enabled) {
const commandCenter = new CommandCenter(undefined, outputChannel, telemetryReporter);
const commandCenter = new CommandCenter(git, undefined, outputChannel, telemetryReporter);
disposables.push(commandCenter);
return;
}
const pathHint = workspace.getConfiguration('git').get<string>('path');
const info = await findGit(pathHint);
const git = new Git({ gitPath: info.path, version: info.version });
const askpass = new Askpass();
const model = new Model(git, workspaceRootPath, askpass);
outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path));
git.onOutput(str => outputChannel.append(str), null, disposables);
const commandCenter = new CommandCenter(model, outputChannel, telemetryReporter);
const commandCenter = new CommandCenter(git, model, outputChannel, telemetryReporter);
const provider = new GitSCMProvider(model, commandCenter);
const contentProvider = new GitContentProvider(model);
const checkoutStatusBar = new CheckoutStatusBar(model);
......@@ -79,10 +80,6 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
}
export function activate(context: ExtensionContext): any {
if (!workspace.rootPath) {
return;
}
const disposables: Disposable[] = [];
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));
......
......@@ -285,10 +285,6 @@ export class Model implements Disposable {
return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>);
}
get git(): Git {
return this._git;
}
private _mergeGroup = new MergeGroup([]);
get mergeGroup(): MergeGroup { return this._mergeGroup; }
......@@ -392,7 +388,7 @@ export class Model implements Disposable {
return;
}
await this.git.init(this.workspaceRootPath);
await this._git.init(this.workspaceRootPath);
await this.status();
}
......@@ -579,9 +575,9 @@ export class Model implements Disposable {
this.repositoryDisposable.dispose();
const disposables: Disposable[] = [];
const repositoryRoot = await this.git.getRepositoryRoot(this.workspaceRootPath);
const repositoryRoot = await this._git.getRepositoryRoot(this.workspaceRootPath);
const askpassEnv = await this.askpass.getEnv();
this.repository = this.git.open(repositoryRoot, askpassEnv);
this.repository = this._git.open(repositoryRoot, askpassEnv);
const dotGitPath = path.join(repositoryRoot, '.git');
const { event: onRawGitChange, disposable: watcher } = watch(dotGitPath);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册