Skip to content

Commit 5e1ceed

Browse files
committed
refactor: refine signoff logic and docs
- update README with AIGITCOMMIT_SIGNOFF env var details - refine should_signoff comments in repository and utils - update env var list in utils to remove GIT_AUTO_SIGNOFF Signed-off-by: mingcheng <[email protected]>
1 parent 0088e19 commit 5e1ceed

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ It inspects your diffs, summarizes the intent of your changes, and produces clea
2626
- Easy-to-use command-line interface with sensible defaults and confirm prompts (can be skipped with `--yes`).
2727
- Uses libgit2 via the `git2` crate, avoiding external git commands for improved security and performance.
2828
- Supports multiple OpenAI-compatible models and configurable API base, token, and proxy settings.
29-
- Optional auto sign-off of commits when `GIT_AUTO_SIGNOFF=true`.
29+
- Optional auto sign-off of commits when `AIGITCOMMIT_SIGNOFF=true` or `git config --bool aigitcommit.signoff true`.
3030
- Proxy support: HTTP and SOCKS5 (set via `OPENAI_API_PROXY`).
3131

3232

@@ -128,7 +128,16 @@ Before using AIGitCommit, export the following environment variables (for exampl
128128
- `OPENAI_API_BASE`: The API base URL (useful for alternative providers or local proxies).
129129
- `OPENAI_MODEL_NAME`: The model name to query (e.g., a GPT-compatible model).
130130
- `OPENAI_API_PROXY`: Optional. Proxy address for network access (e.g., `http://127.0.0.1:1080` or `socks://127.0.0.1:1086`).
131-
- `GIT_AUTO_SIGNOFF`: Optional. Set to `true` to append a Signed-off-by line to commits.
131+
- `AIGITCOMMIT_SIGNOFF`: Optional. Set to `true` (or any truthy value) to append a Signed-off-by line to commits.
132+
133+
You can also enable sign-off via Git configuration:
134+
135+
```bash
136+
git config aigitcommit.signoff true # repository only
137+
git config --global aigitcommit.signoff true
138+
```
139+
140+
The Git configuration takes precedence over the environment variable.
132141

133142
### Check the configuration
134143

hooks/prepare-commit-msg

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ log() {
66
printf '%s\n' "$1" >&2
77
}
88

9+
is_truthy() {
10+
case "$1" in
11+
1 | true | TRUE | yes | YES | on | ON)
12+
return 0
13+
;;
14+
*)
15+
return 1
16+
;;
17+
esac
18+
}
19+
20+
should_signoff() {
21+
if is_truthy "${AIGITCOMMIT_SIGNOFF:-}"; then
22+
return 0
23+
fi
24+
25+
config=$(git config --bool aigitcommit.signoff 2>/dev/null || true)
26+
case "$config" in
27+
true)
28+
return 0
29+
;;
30+
false)
31+
return 1
32+
;;
33+
esac
34+
35+
return 0
36+
}
37+
938
COMMIT_MSG_FILE=${1:-}
1039
COMMIT_MSG_TYPE=${2:-}
1140

@@ -44,7 +73,12 @@ trap cleanup EXIT INT TERM
4473

4574
log "Generating commit message with aigitcommit..."
4675

47-
if ! aigitcommit "$REPO_ROOT" --save "$TEMP_FILE" >/dev/null 2>&1; then
76+
SIGNOFF_FLAG=""
77+
if should_signoff; then
78+
SIGNOFF_FLAG="--signoff"
79+
fi
80+
81+
if ! aigitcommit "$REPO_ROOT" ${SIGNOFF_FLAG:+$SIGNOFF_FLAG} --save "$TEMP_FILE" >/dev/null 2>&1; then
4882
log "Error: aigitcommit failed to generate commit message."
4983
exit 1
5084
fi

src/git/repository.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ impl Repository {
243243
}
244244

245245
/// Check if commit should be signed off
246-
/// Returns true if either CLI flag is set or AIGITCOMMIT_SIGNOFF environment variable is true
246+
/// Returns true when git config `aigitcommit.signoff` is enabled or the
247+
/// `AIGITCOMMIT_SIGNOFF` environment variable evaluates to true
247248
pub fn should_signoff(&self) -> bool {
248249
// Define the config key for signoff
249250
const SIGNOFF_KEY: &str = "aigitcommit.signoff";

src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn get_env_bool(key: &str) -> bool {
3838
}
3939

4040
/// Check if commit should be signed off
41-
/// Returns true if either CLI flag is set or AIGITCOMMIT_SIGNOFF environment variable is true
41+
/// Returns true if either CLI flag is set or repository/git config/env enable sign-off
4242
pub fn should_signoff(repository: &Repository, cli_signoff: bool) -> bool {
4343
cli_signoff || repository.should_signoff()
4444
}
@@ -116,7 +116,7 @@ pub fn check_env_variables() {
116116
"OPENAI_API_PROXY",
117117
"OPENAI_API_TIMEOUT",
118118
"OPENAI_API_MAX_TOKENS",
119-
"GIT_AUTO_SIGNOFF",
119+
"AIGITCOMMIT_SIGNOFF",
120120
]
121121
.iter()
122122
.for_each(|v| check_and_print_env(v));

0 commit comments

Comments
 (0)