修复了拉取出现的bug,完善了改名功能
This commit is contained in:
@@ -83,7 +83,7 @@ class GitService {
|
||||
static async cloneRepository(url, localPath, branch = 'main', onProgress, username, token) {
|
||||
const parentDir = path.dirname(localPath);
|
||||
await fs.promises.mkdir(parentDir, { recursive: true });
|
||||
// 检查目录是否已存在且非空(不变)
|
||||
// 检查目录是否已存在且非空
|
||||
let dirExists = false;
|
||||
try {
|
||||
await fs.promises.access(localPath);
|
||||
@@ -94,7 +94,10 @@ class GitService {
|
||||
}
|
||||
if (dirExists) {
|
||||
const dirContents = await fs.promises.readdir(localPath);
|
||||
if (dirContents.length > 0 && dirContents.some(item => item !== '.git')) {
|
||||
// 修正后的逻辑:过滤掉所有以 "." 开头的隐藏文件/目录。
|
||||
// 只有当存在非 "." 开头的文件或目录时,才阻止克隆。
|
||||
const nonBenignFiles = dirContents.filter(item => !item.startsWith('.'));
|
||||
if (nonBenignFiles.length > 0) {
|
||||
throw new Error('目标目录不为空,请清空目录或选择其他路径');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user