Skip to content

Commit 4d587e2

Browse files
committed
Merge branch 'main' into develop
2 parents 2a2988f + 4c97303 commit 4d587e2

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
1919

2020
[[package]]
2121
name = "aigitcommit"
22+
<<<<<<< HEAD
2223
version = "1.1.0"
24+
=======
25+
version = "1.2.0"
26+
>>>>>>> release/1.2.0
2327
dependencies = [
2428
"arboard",
2529
"askama",

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[package]
22
name = "aigitcommit"
3+
<<<<<<< HEAD
34
version = "1.1.0"
5+
=======
6+
version = "1.2.0"
7+
>>>>>>> release/1.2.0
48
edition = "2021"
59
description = "A simple git commit message generator by OpenAI compaction model."
610
license = "MIT"

hooks/prepare-commit-msg

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# It is triggered before the commit message editor is opened.
55
# Usage: Place this script in the `.git/hooks/` directory of your repository and make it executable.
66
COMMIT_MSG_FILE=$1
7+
<<<<<<< HEAD
78
REPO_ROOT=$(git rev-parse --show-toplevel)
89

910
if [ -f $COMMIT_MSG_FILE ]; then
@@ -15,6 +16,11 @@ if [ -f $COMMIT_MSG_FILE ]; then
1516
fi
1617
fi
1718

19+
=======
20+
COMMIT_MSG_TYPE=$2
21+
REPO_ROOT=$(git rev-parse --show-toplevel)
22+
23+
>>>>>>> main
1824
# Check the repository root directory is valid
1925
# The `git rev-parse --show-toplevel` command returns the absolute path to the root of the repository
2026
# If the command fails, it means we are not in a Git repository
@@ -23,6 +29,7 @@ if [ ! -d "$REPO_ROOT" ]; then
2329
exit 1
2430
fi
2531

32+
<<<<<<< HEAD
2633
# Get only the diff of what has already been staged
2734
GIT_DIFF_OUTPUT=$(git diff --cached)
2835

@@ -34,10 +41,15 @@ fi
3441

3542
# Check if aigitcommit is installed
3643
if ! command -v aigitcommit &> /dev/null; then
44+
=======
45+
# Check if aigitcommit is installed
46+
if ! type aigitcommit >/dev/null 2>&1; then
47+
>>>>>>> main
3748
echo "Error: aigitcommit is not installed. Please install it first."
3849
exit 1
3950
fi
4051

52+
<<<<<<< HEAD
4153
# Execute aigitcommit to generate the commit message
4254
# Redirecting output to the commit message file
4355
# and suppressing any error messages
@@ -46,4 +58,38 @@ aigitcommit $REPO_ROOT --save $COMMIT_MSG_FILE > /dev/null 2>&1
4658
if [ $? -ne 0 ]; then
4759
echo "Error: aigitcommit failed to generate commit message."
4860
exit 1
61+
=======
62+
# Only proceed if this is a regular commit (message type is empty or "message")
63+
if [ "$COMMIT_MSG_TYPE" = "message" ] || [ -z "$COMMIT_MSG_TYPE" ]; then
64+
# Get only the diff of what has already been staged
65+
GIT_DIFF_OUTPUT=$(git diff --cached)
66+
67+
# Check if there are any staged changes to commit
68+
if [ -z "$GIT_DIFF_OUTPUT" ]; then
69+
echo "No staged changes detected. Aborting."
70+
exit 1
71+
fi
72+
73+
# Generate a temporary file for the commit message
74+
TEMP_FILE=$(mktemp)
75+
76+
# Execute aigitcommit to generate the commit message
77+
# Redirecting output to the commit message file
78+
# and suppressing any error messages
79+
# The --save option is used to save the generated commit message to the file
80+
echo "Generating commit message by using AIGitCommit..."
81+
echo "This may take a few seconds..."
82+
aigitcommit $REPO_ROOT --save $TEMP_FILE >/dev/null 2>&1
83+
if [ $? -ne 0 ]; then
84+
echo "Error: aigitcommit failed to generate commit message."
85+
rm -f $TEMP_FILE
86+
exit 1
87+
fi
88+
89+
# Append the generated commit message to the temporary file
90+
cat $COMMIT_MSG_FILE >>$TEMP_FILE && mv -f $TEMP_FILE $COMMIT_MSG_FILE
91+
else
92+
# For other commit types (merge, template, etc.), exit without doing anything
93+
exit 0
94+
>>>>>>> main
4995
fi

src/cli.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
* File Created: 2025-03-03 19:31:27
1010
*
1111
* Modified By: mingcheng ([email protected])
12+
<<<<<<< HEAD
1213
* Last Modified: 2025-03-04 13:13:16
14+
=======
15+
<<<<<<< HEAD
16+
* Last Modified: 2025-03-04 11:38:55
17+
=======
18+
* Last Modified: 2025-03-04 13:13:16
19+
>>>>>>> release/1.2.0
20+
>>>>>>> main
1321
*/
1422

1523
use clap::Parser;
@@ -48,6 +56,11 @@ If not specified, the current directory will be used"#,
4856

4957
#[arg(
5058
long,
59+
<<<<<<< HEAD
60+
=======
61+
<<<<<<< HEAD
62+
=======
63+
>>>>>>> main
5164
short,
5265
help = "Accept the commit message without prompting",
5366
default_value_t = false,
@@ -57,11 +70,20 @@ If not specified, the current directory will be used"#,
5770

5871
#[arg(
5972
long,
73+
<<<<<<< HEAD
74+
=======
75+
>>>>>>> release/1.2.0
76+
>>>>>>> main
6077
help = "Copy the commit message to clipboard",
6178
default_value_t = false,
6279
required = false
6380
)]
6481
pub copy: bool,
82+
<<<<<<< HEAD
83+
=======
84+
<<<<<<< HEAD
85+
=======
86+
>>>>>>> main
6587

6688
#[arg(
6789
long,
@@ -71,4 +93,8 @@ If not specified, the current directory will be used"#,
7193
required = false
7294
)]
7395
pub save: String,
96+
<<<<<<< HEAD
97+
=======
98+
>>>>>>> release/1.2.0
99+
>>>>>>> main
74100
}

src/main.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
* File Created: 2025-03-01 17:17:30
1010
*
1111
* Modified By: mingcheng ([email protected])
12+
<<<<<<< HEAD
1213
* Last Modified: 2025-03-04 14:46:51
14+
=======
15+
<<<<<<< HEAD
16+
* Last Modified: 2025-03-04 11:39:25
17+
=======
18+
* Last Modified: 2025-03-04 14:46:51
19+
>>>>>>> release/1.2.0
20+
>>>>>>> main
1321
*/
1422

1523
use aigitcommit::cli::Cli;
@@ -111,6 +119,7 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
111119
trace!("write to stdout, and finish the process");
112120
writeln!(std::io::stdout(), "{}", result)?;
113121

122+
<<<<<<< HEAD
114123
// Copy the commit message to clipboard if the --copy option is enabled
115124
if cli.copy {
116125
let mut clipboard = Clipboard::new()?;
@@ -124,13 +133,42 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
124133
// directly commit the changes to the repository if the --commit option is enabled
125134
if cli.commit {
126135
trace!("Commit option is enabled, will commit the changes to the repository");
136+
=======
137+
<<<<<<< HEAD
138+
// directly commit the changes to the repository if the --commit option is enabled
139+
if cli.commit {
140+
trace!("Commit option is enabled, will commit the changes to the repository");
141+
if Confirm::new()
142+
.with_prompt("\nDo you want to commit the changes with the generated commit message?")
143+
.default(false)
144+
.interact()?
145+
{
146+
=======
147+
// Copy the commit message to clipboard if the --copy option is enabled
148+
if cli.copy {
149+
let mut clipboard = Clipboard::new()?;
150+
clipboard.set_text(&result)?;
151+
writeln!(
152+
std::io::stdout(),
153+
"The commit message has been copied to clipboard."
154+
)?;
155+
}
156+
157+
// directly commit the changes to the repository if the --commit option is enabled
158+
if cli.commit {
159+
trace!("Commit option is enabled, will commit the changes to the repository");
160+
>>>>>>> main
127161
let mut confirm = Confirm::new();
128162
confirm
129163
.with_prompt("Do you want to commit the changes with the generated commit message?")
130164
.default(false);
131165

132166
// Prompt the user for confirmation if --yes option is not enabled
133167
if cli.yes || confirm.interact()? {
168+
<<<<<<< HEAD
169+
=======
170+
>>>>>>> release/1.2.0
171+
>>>>>>> main
134172
match repository.commit(&result) {
135173
Ok(_) => {
136174
writeln!(std::io::stdout(), "Commit successful!")?;
@@ -140,7 +178,21 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
140178
}
141179
}
142180
}
181+
<<<<<<< HEAD
182+
}
183+
=======
184+
<<<<<<< HEAD
185+
} else if cli.copy {
186+
let mut clipboard = Clipboard::new()?;
187+
clipboard.set_text(&result)?;
188+
write!(
189+
std::io::stdout(),
190+
"\n The commit message has been copied to clipboard."
191+
)?;
192+
}
193+
=======
143194
}
195+
>>>>>>> main
144196

145197
// If the --save option is enabled, save the commit message to a file
146198
if !cli.save.is_empty() {
@@ -155,5 +207,9 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
155207
writeln!(std::io::stdout(), "Commit message saved to {}", &save_path)?;
156208
}
157209

210+
<<<<<<< HEAD
211+
=======
212+
>>>>>>> release/1.2.0
213+
>>>>>>> main
158214
Ok(())
159215
}

0 commit comments

Comments
 (0)