Skip to content

Commit

Permalink
✨ feat(scm): 添加获取提交信息输入框内容功能
Browse files Browse the repository at this point in the history
- 在 SCMProvider 接口中新增 getCommitInput 方法
- 在 GitProvider 中实现获取 Git 仓库提交信息功能
- 在 SvnProvider 中实现获取 SVN 仓库提交信息功能
- 优化了 SvnProvider 中的代码格式和错误处理
  • Loading branch information
littleCareless committed Dec 11, 2024
1 parent 79eda9d commit e670326
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/scm/GitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,17 @@ export class GitProvider implements ISCMProvider {

repository.inputBox.value = message;
}

async getCommitInput(): Promise<string> {
const api = this.gitExtension.getAPI(1);
const repository = api.repositories[0];

if (!repository) {
throw new Error(
LocalizationManager.getInstance().getMessage("git.repository.not.found")
);
}

return repository.inputBox.value;
}
}
1 change: 1 addition & 0 deletions src/scm/SCMProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ISCMProvider {
getDiff(files?: string[]): Promise<string | undefined>;
commit(message: string, files?: string[]): Promise<void>;
setCommitInput(message: string): Promise<void>;
getCommitInput(): Promise<string>;
}

export class SCMFactory {
Expand Down
30 changes: 26 additions & 4 deletions src/scm/SvnProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class SvnProvider implements ISCMProvider {
}
return false;
} catch (error) {
console.error("SVN availability check failed:", error instanceof Error ? error.message : error);
console.error(
"SVN availability check failed:",
error instanceof Error ? error.message : error
);
return false;
}
}
Expand Down Expand Up @@ -93,7 +96,10 @@ export class SvnProvider implements ISCMProvider {
// 如果未启用简化,直接返回原始diff
return stdout;
} catch (error) {
console.error("SVN diff failed:", error instanceof Error ? error.message : error);
console.error(
"SVN diff failed:",
error instanceof Error ? error.message : error
);
if (error instanceof Error) {
vscode.window.showErrorMessage(
LocalizationManager.getInstance().format(
Expand All @@ -116,11 +122,16 @@ export class SvnProvider implements ISCMProvider {

try {
if (!files?.length) {
throw new Error(LocalizationManager.getInstance().getMessage("svn.no.files.selected"));
throw new Error(
LocalizationManager.getInstance().getMessage("svn.no.files.selected")
);
}
await repository.commitFiles(files, message);
} catch (error) {
console.error("SVN commit failed:", error instanceof Error ? error.message : error);
console.error(
"SVN commit failed:",
error instanceof Error ? error.message : error
);
throw new Error(
LocalizationManager.getInstance().format("svn.commit.failed", error)
);
Expand All @@ -137,4 +148,15 @@ export class SvnProvider implements ISCMProvider {

repository.inputBox.value = message;
}

async getCommitInput(): Promise<string> {
const repository = this.api?.repositories?.[0];
if (!repository) {
throw new Error(
LocalizationManager.getInstance().getMessage("git.repository.not.found")
);
}

return repository.inputBox.value;
}
}

0 comments on commit e670326

Please sign in to comment.