Skip to content

Commit b413151

Browse files
🎨 style(git): 优化代码格式和错误处理逻辑
- 改进了 GitRepository 接口的方法参数格式 - 优化了 getFileStatus 方法的代码结构和可读性 - 调整了错误信息本地化键名为更明确的 "git.diff.failed" - 优化了错误处理和条件判断的代码格式
1 parent 2bd795a commit b413151

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/scm/GitProvider.ts

+26-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ interface GitRepository {
1616
inputBox: {
1717
value: string;
1818
};
19-
commit(message: string, options: { all: boolean; files?: string[] }): Promise<void>;
19+
commit(
20+
message: string,
21+
options: { all: boolean; files?: string[] }
22+
): Promise<void>;
2023
}
2124

2225
export class GitProvider implements ISCMProvider {
@@ -44,17 +47,29 @@ export class GitProvider implements ISCMProvider {
4447
// 优化 getFileStatus 方法
4548
private async getFileStatus(file: string): Promise<string> {
4649
try {
47-
const { stdout: status } = await exec(`git status --porcelain "${file}"`, {
48-
cwd: this.workspaceRoot,
49-
});
50-
51-
if (!status) return "Unknown";
52-
53-
if (status.startsWith("??")) return "New File";
54-
if (status.startsWith(" D") || status.startsWith("D ")) return "Deleted File";
50+
const { stdout: status } = await exec(
51+
`git status --porcelain "${file}"`,
52+
{
53+
cwd: this.workspaceRoot,
54+
}
55+
);
56+
57+
if (!status) {
58+
return "Unknown";
59+
}
60+
61+
if (status.startsWith("??")) {
62+
return "New File";
63+
}
64+
if (status.startsWith(" D") || status.startsWith("D ")) {
65+
return "Deleted File";
66+
}
5567
return "Modified File";
5668
} catch (error) {
57-
console.error("Failed to get file status:", error instanceof Error ? error.message : error);
69+
console.error(
70+
"Failed to get file status:",
71+
error instanceof Error ? error.message : error
72+
);
5873
return "Unknown";
5974
}
6075
}
@@ -128,7 +143,7 @@ export class GitProvider implements ISCMProvider {
128143
);
129144
}
130145
throw new Error(
131-
LocalizationManager.getInstance().getMessage("diff.failed")
146+
LocalizationManager.getInstance().getMessage("git.diff.failed")
132147
);
133148
}
134149
}

0 commit comments

Comments
 (0)