提交 532ffbbb 编写于 作者: J Joao Moreno

be more careful with git init

fixes #35902
上级 41389ef1
......@@ -339,21 +339,35 @@ export class CommandCenter {
@command('git.init')
async init(): Promise<void> {
const value = workspace.workspaceFolders && workspace.workspaceFolders.length > 0
? workspace.workspaceFolders[0].uri.fsPath
: os.homedir();
const path = await window.showInputBox({
placeHolder: localize('path to init', "Folder path"),
prompt: localize('provide path', "Please provide a folder path to initialize a Git repository"),
value,
ignoreFocusOut: true
const homeUri = Uri.file(os.homedir());
const defaultUri = workspace.workspaceFolders && workspace.workspaceFolders.length > 0
? Uri.file(workspace.workspaceFolders[0].uri.fsPath)
: homeUri;
const result = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri,
openLabel: localize('init repo', "Initialize Repository")
});
if (!path) {
if (!result || result.length === 0) {
return;
}
const uri = result[0];
if (homeUri.toString().startsWith(uri.toString())) {
const yes = localize('create repo', "Initialize Repository");
const answer = await window.showWarningMessage(localize('are you sure', "This will create a Git repository in '{0}'. Are you sure you want to continue?", uri.fsPath), yes);
if (answer !== yes) {
return;
}
}
const path = uri.fsPath;
await this.git.init(path);
await this.model.tryOpenRepository(path);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册