Skip to content

Commit

Permalink
perf: 优化创建worktree流程
Browse files Browse the repository at this point in the history
  • Loading branch information
jackiotyu committed Jun 17, 2024
1 parent dbdc72f commit 7658782
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Binary file modified images/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion l10n/bundle.l10n.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@
"Open worktree list": "打开 worktree 列表",
"Input worktree directory": "输入 worktree 文件夹",
"Please select a different directory": "请选择其他文件夹",
"The folder already exists": "文件夹已存在"
"The folder is not empty": "所选文件夹中有文件"
}
6 changes: 3 additions & 3 deletions src/core/ui/inputWorktreeDir.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import path from 'path';
import { checkExist } from '@/core/util/file';
import { checkExist, isDirEmpty } from '@/core/util/file';
import { comparePath } from '@/core/util/folder';
import { Alert } from '@/core/ui/message';

Expand Down Expand Up @@ -92,8 +92,8 @@ export const inputWorktreeDir = async ({ baseDir, baseWorktreeDir, step, totalSt
const input = inputBox.value;
if (!input) return;
if (verifySameDir(input, workTreeDir)) return;
if (await checkExist(input)) {
return Alert.showErrorMessage(vscode.l10n.t('The folder already exists'));
if (!(await isDirEmpty(input))) {
return Alert.showErrorMessage(vscode.l10n.t('The folder is not empty'));
}
resolve(input);
inputBox.hide();
Expand Down
9 changes: 8 additions & 1 deletion src/core/util/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ export const verifyDirExistence = async (path: string) => {
return false;
}
return true;
};
};

export function isDirEmpty(path: string) {
return fs
.readdir(path)
.then((res) => res.length === 0)
.catch(() => true);
}

0 comments on commit 7658782

Please sign in to comment.