Skip to content

Commit e2f2ebd

Browse files
committed
fix: add git availability check with download link
1 parent 2452f32 commit e2f2ebd

File tree

5 files changed

+89
-64
lines changed

5 files changed

+89
-64
lines changed

src/i18n/messages/en.rs

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
use phf::phf_map;
22

33
pub static MESSAGES: phf::Map<&'static str, &'static str> = phf_map! {
4-
// Configuration file I/O
5-
"config_loaded" => "Configuration loaded successfully",
6-
"failed_print_config" => "Failed to print configuration: {}",
7-
"failed_parse_config" => "Failed to parse config: {}",
8-
"global_config_not_initialized" => "Global configuration not initialized",
4+
// Git
5+
"err_git_not_found" => "Git is not installed or not in system PATH. Please install Git first.\nVisit https://git-scm.com/downloads to download.",
6+
"err_git_not_working" => "Git is installed but not working properly. Please check your Git installation.\nTo reinstall, visit https://git-scm.com/downloads .",
97

10-
// Configuration file details
11-
"config_details" => "---- Configuration Details -----",
12-
"language" => "Language",
13-
"authors" => "Authors",
14-
"date_range" => "Date Range",
15-
"repos" => "Repositories",
16-
"includes" => "Includes",
17-
"excludes" => "Excludes",
18-
"format" => "Format",
8+
// Configuration file I/O
9+
"config_loaded" => "Configuration loaded successfully",
10+
"failed_print_config" => "Failed to print configuration: {}",
11+
"failed_parse_config" => "Failed to parse config: {}",
12+
"global_config_not_initialized" => "Global configuration not initialized",
1913

20-
// Keypress
21-
"wait_for_key" => "Press any key to continue...",
22-
"press_to_exit" => "Press any key to exit...",
14+
// Configuration file details
15+
"config_details" => "---- Configuration Details -----",
16+
"language" => "Language",
17+
"authors" => "Authors",
18+
"date_range" => "Date Range",
19+
"repos" => "Repositories",
20+
"includes" => "Includes",
21+
"excludes" => "Excludes",
22+
"format" => "Format",
2323

24-
// Commit categories
25-
"commit_category_features" => "Features",
26-
"commit_category_bug_fixes" => "Bug Fixes",
27-
"commit_category_docs" => "Documentation",
28-
"commit_category_style" => "Optimized Style",
29-
"commit_category_refactor" => "Refactored",
30-
"commit_category_test" => "Test Cases",
31-
"commit_category_chores" => "Chores",
24+
// Keypress
25+
"wait_for_key" => "Press any key to continue...",
26+
"press_to_exit" => "Press any key to exit...",
3227

33-
// Git repository error messages
34-
"err_repo_not_found" => "Repo path does not exist or is not a directory: {}",
35-
"err_git_log_failed" => "git log failed in directory: {}\nstderr: {}",
28+
// Commit categories
29+
"commit_category_features" => "Features",
30+
"commit_category_bug_fixes" => "Bug Fixes",
31+
"commit_category_docs" => "Documentation",
32+
"commit_category_style" => "Optimized Style",
33+
"commit_category_refactor" => "Refactored",
34+
"commit_category_test" => "Test Cases",
35+
"commit_category_chores" => "Chores",
3636

37-
// Save report
38-
"no_report_generated" => "No report generated",
39-
"err_save_report_failed" => "Failed to save report: {}",
40-
"report_saved" => "Report saved to {}",
37+
// Git repository error messages
38+
"err_repo_not_found" => "Repo path does not exist or is not a directory: {}",
39+
"err_git_log_failed" => "git log failed in directory: {}\nstderr: {}",
40+
41+
// Save report
42+
"no_report_generated" => "No report generated",
43+
"err_save_report_failed" => "Failed to save report: {}",
44+
"report_saved" => "Report saved to {}",
4145
};

src/i18n/messages/zh.rs

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
use phf::phf_map;
22

33
pub static MESSAGES: phf::Map<&'static str, &'static str> = phf_map! {
4-
// Configuration file I/O
5-
"config_loaded" => "配置加载成功",
6-
"failed_print_config" => "打印配置失败:{}",
7-
"failed_parse_config" => "解析配置失败:{}",
8-
"global_config_not_initialized" => "全局配置未初始化",
4+
// Git
5+
"err_git_not_found" => "Git 未安装或未添加到系统 PATH 中,请先安装 Git。\n访问 https://git-scm.com/downloads 下载安装。",
6+
"err_git_not_working" => "Git 已安装但无法正常工作,请检查 Git 安装状态。\n如需重新安装,请访问 https://git-scm.com/downloads 。",
97

10-
// Configuration file details
11-
"config_details" => "----------- 配置详情 -----------",
12-
"language" => "语言",
13-
"authors" => "作者",
14-
"date_range" => "日期范围",
15-
"repos" => "仓库",
16-
"includes" => "包含",
17-
"excludes" => "排除",
18-
"format" => "格式",
8+
// Configuration file I/O
9+
"config_loaded" => "配置加载成功",
10+
"failed_print_config" => "打印配置失败:{}",
11+
"failed_parse_config" => "解析配置失败:{}",
12+
"global_config_not_initialized" => "全局配置未初始化",
1913

20-
// Keypress
21-
"wait_for_key" => "按任意键继续...",
22-
"press_to_exit" => "按任意键退出...",
14+
// Configuration file details
15+
"config_details" => "----------- 配置详情 -----------",
16+
"language" => "语言",
17+
"authors" => "作者",
18+
"date_range" => "日期范围",
19+
"repos" => "仓库",
20+
"includes" => "包含",
21+
"excludes" => "排除",
22+
"format" => "格式",
2323

24-
// Commit categories
25-
"commit_category_features" => "功能开发",
26-
"commit_category_bug_fixes" => "BUG修复",
27-
"commit_category_docs" => "完善文档",
28-
"commit_category_style" => "优化样式",
29-
"commit_category_refactor" => "代码重构",
30-
"commit_category_test" => "测试用例",
31-
"commit_category_chores" => "其他优化",
24+
// Keypress
25+
"wait_for_key" => "按任意键继续...",
26+
"press_to_exit" => "按任意键退出...",
3227

33-
// Git repository error messages
34-
"err_repo_not_found" => "仓库路径不存在或不是目录:{}",
35-
"err_git_log_failed" => "git log 执行失败,目录:{}\n错误信息:{}",
28+
// Commit categories
29+
"commit_category_features" => "功能开发",
30+
"commit_category_bug_fixes" => "BUG修复",
31+
"commit_category_docs" => "完善文档",
32+
"commit_category_style" => "优化样式",
33+
"commit_category_refactor" => "代码重构",
34+
"commit_category_test" => "测试用例",
35+
"commit_category_chores" => "其他优化",
3636

37-
// Save report
38-
"no_report_generated" => "未生成报告",
39-
"err_save_report_failed" => "保存报告失败:{}",
40-
"report_saved" => "报告已保存到:{}",
37+
// Git repository error messages
38+
"err_repo_not_found" => "仓库路径不存在或不是目录:{}",
39+
"err_git_log_failed" => "git log 执行失败,目录:{}\n错误信息:{}",
40+
41+
// Save report
42+
"no_report_generated" => "未生成报告",
43+
"err_save_report_failed" => "保存报告失败:{}",
44+
"report_saved" => "报告已保存到:{}",
4145
};

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::{
1010
use config::{init_config, print_config};
1111
use i18n::t;
1212
use utils::{
13+
check_git::check_git_available,
1314
filter_logs::filter_logs,
1415
format_log::{format_log, LogInfo},
1516
get_repo_logs::get_repo_logs,
@@ -25,6 +26,9 @@ fn run(root_path: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
2526
// such as in the i18n module.
2627
let config = init_config(&root_path)?;
2728

29+
// Check if git is available
30+
check_git_available()?;
31+
2832
print_config();
2933

3034
let mut result: HashMap<String, HashMap<String, Vec<LogInfo>>> = HashMap::new();

src/utils/check_git.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::i18n::t;
2+
use std::process::Command;
3+
4+
pub fn check_git_available() -> anyhow::Result<()> {
5+
let output = Command::new("git").arg("--version").output();
6+
7+
match output {
8+
Ok(output) if output.status.success() => Ok(()),
9+
Ok(_) => anyhow::bail!("\n{}\n", t("err_git_not_working")),
10+
Err(_) => anyhow::bail!("\n{}\n", t("err_git_not_found")),
11+
}
12+
}

src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod check_git;
12
pub mod filter_logs;
23
pub mod format_commit;
34
pub mod format_log;

0 commit comments

Comments
 (0)