Skip to content

Commit f3c3b28

Browse files
authored
fix(fastcommit): 修复提交信息换行处理问题 (#19)
* fix(fastcommit): 修复提交信息换行处理问题 - 重构代码结构,提取重复逻辑 - 创建专用的提交消息包装器 - 确保提交信息正确保留换行格式 Signed-off-by: longjin <longjin@DragonOS.org> * chore(version): 更新版本号至 0.5.1 Signed-off-by: longjin <longjin@DragonOS.org> --------- Signed-off-by: longjin <longjin@DragonOS.org>
1 parent 64d4ec5 commit f3c3b28

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fastcommit"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
description = "AI-based command line tool to quickly generate standardized commit messages."
55
edition = "2021"
66
authors = ["longjin <fslongjin@vip.qq.com>"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can install `fastcommit` using the following method:
1010

1111
```bash
1212
# Install using cargo
13-
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.5.0
13+
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.5.1
1414
```
1515

1616

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
```bash
1010
# 使用 cargo 安装
11-
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.5.0
11+
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.5.1
1212
```
1313

1414
## 使用

src/main.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,32 @@ async fn main() -> anyhow::Result<()> {
5252

5353
run_update_checker().await;
5454

55-
// 根据参数决定生成内容:
56-
// 1. --gb --m 同时:生成分支名 + 提交信息
57-
// 2. 仅 --gb:只生成分支名
58-
// 3. 默认(无 --gb 或仅 --m):生成提交信息
55+
// 创建提交消息专用的包装器(启用段落保留)
56+
let commit_wrapper = if enable_wrapping {
57+
let wrap_config =
58+
WrapConfig::from_config_and_args(&config.text_wrap, args.wrap_width, true);
59+
Some(TextWrapper::new(wrap_config))
60+
} else {
61+
None
62+
};
5963

64+
// 根据参数决定生成内容
6065
if args.generate_branch && args.generate_message {
66+
// 生成分支名 + 提交信息
6167
let (branch_name, msg) = generate::generate_both(&args, &config).await?;
62-
// 停止spinner动画
6368
spinner.finish();
64-
6569
print_wrapped_content(&wrapper, &branch_name, Some("Generated branch name:"));
66-
print_wrapped_content(&wrapper, &msg, None);
70+
print_wrapped_content(&commit_wrapper, &msg, None);
6771
} else if args.generate_branch {
72+
// 仅生成分支名
6873
let branch_name = generate::generate_branch(&args, &config).await?;
69-
// 停止spinner动画
7074
spinner.finish();
71-
7275
print_wrapped_content(&wrapper, &branch_name, Some("Generated branch name:"));
7376
} else {
74-
// 包括:无参数 或 仅 --m
77+
// 仅生成提交信息(默认行为)
7578
let msg = generate::generate(&args, &config).await?;
76-
// 停止spinner动画
7779
spinner.finish();
78-
79-
// 对于提交消息,需要启用段落保留
80-
let final_wrapper = if enable_wrapping {
81-
let wrap_config =
82-
WrapConfig::from_config_and_args(&config.text_wrap, args.wrap_width, true);
83-
Some(TextWrapper::new(wrap_config))
84-
} else {
85-
None
86-
};
87-
88-
print_wrapped_content(&final_wrapper, &msg, None);
80+
print_wrapped_content(&commit_wrapper, &msg, None);
8981
}
9082
Ok(())
9183
}

0 commit comments

Comments
 (0)