Skip to content

Commit 7d0e7a1

Browse files
docs(README): docs: update README with push confirmation flow
1 parent 5b2a999 commit 7d0e7a1

2 files changed

Lines changed: 65 additions & 42 deletions

File tree

README.md

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This project is a Rust implementation of the Go based git-cmd project found [her
1717
- 🤖 **AI-powered**: Uses OpenAI models (default: `gpt-4.1-mini`) to analyze code changes
1818
- 📝 **Conventional Commits**: Generates messages in the `type(scope): description` format
1919
- 🎯 **Smart Analysis**: Understands code changes and suggests contextually appropriate messages
20-
-**User Confirmation**: Asks for y/n confirmation before committing
20+
-**Push Confirmation**: Asks for y/n confirmation before pushing to remote
2121
-**Interactive**: Opens your editor for final review and editing before committing
2222
- 📦 **Auto-staging**: Automatically stages all changes with `git add .` before analysis
2323
- 🔍 **Diff-aware**: Analyzes changes to generate contextually appropriate messages
@@ -70,9 +70,10 @@ sudo mv target/release/git-cmt-rs /usr/local/bin/git-cmt-rs
7070
```bash
7171
git-cmt-rs
7272
```
73-
2. Review the generated commit message and confirm (y/n).
74-
3. If confirmed, the editor opens for final review and editing.
75-
4. Save and close the editor to complete the commit.
73+
2. The editor opens for final review and editing of the commit message.
74+
3. Save and close the editor to create the commit.
75+
4. After commit, confirm whether to push to remote (y/n).
76+
5. If confirmed, changes are pushed; if declined, commit stays local.
7677

7778
The tool automatically stages all changes with `git add .` before analyzing and generating a commit message.
7879

@@ -82,9 +83,10 @@ The tool automatically stages all changes with `git add .` before analyzing and
8283
2. **Diff Analysis**: Reads staged changes with `git diff --cached -b` (truncated to 3072 chars if necessary)
8384
3. **AI Processing**: Sends the diff to OpenAI with structured prompts and JSON schema enforcement
8485
4. **Message Generation**: Produces a commit object with `type`, `scope`, and `message`
85-
5. **User Confirmation**: Displays the generated message and asks for confirmation (y/n)
86-
6. **Interactive Commit**: Opens your editor with the message for final review and editing (if confirmed)
87-
7. **Final Commit**: Runs `git commit` with the approved message
86+
5. **Interactive Commit**: Opens your editor with the message for final review and editing
87+
6. **Create Commit**: Runs `git commit` with the approved message
88+
7. **Push Confirmation**: Asks user to confirm push to remote (y/n)
89+
8. **Final Push**: Runs `git push` if confirmed, or exits with commit saved locally if declined
8890

8991
## Commit Message Format
9092

@@ -98,47 +100,49 @@ type(scope): description
98100

99101
## Examples
100102

101-
### Feature Addition
103+
### Feature Addition (Push Confirmed)
102104

103105
```bash
104106
$ git-cmt-rs
105107
Staged all changes with `git add .`
106108
Staged diff found; generating message for changes...
107109
Parsed commit: type='feat', scope='auth', message='add OAuth2 login integration'
108110

109-
Generated commit message:
110-
feat(auth): add OAuth2 login integration
111-
112-
Proceed with commit? (y/n): y
113111
# Opens editor for final review
114-
# Save and close to complete the commit
112+
# Save and close editor to commit
113+
114+
Commit created successfully.
115+
Push commit to remote? (y/n): y
116+
Changes pushed successfully!
115117
```
116118

117-
### Bug Fix
119+
### Bug Fix (Push Declined)
118120

119121
```bash
120122
$ git-cmt-rs
121123
Staged all changes with `git add .`
122124
Staged diff found; generating message for changes...
123125
Parsed commit: type='fix', scope='api', message='resolve null pointer in validation'
124126

125-
Generated commit message:
126-
fix(api): resolve null pointer in validation
127+
# Opens editor for final review
128+
# Save and close editor to commit
127129

128-
Proceed with commit? (y/n): n
129-
Commit cancelled.
130+
Commit created successfully.
131+
Push commit to remote? (y/n): n
132+
Push cancelled. Commit saved locally.
130133
```
131134

132-
### Declining the Commit
135+
### Keeping Commit Local
133136

134-
Users can respond with `n` or `no` to cancel the commit without opening the editor:
137+
Users can respond with `n` or `no` at the push confirmation to keep the commit local without pushing to remote:
135138

136139
```bash
137140
$ git-cmt-rs
138141
Staged all changes with `git add .`
139142
...
140-
Proceed with commit? (y/n): n
141-
Commit cancelled.
143+
Commit created successfully.
144+
Push commit to remote? (y/n): n
145+
Push cancelled. Commit saved locally.
142146
```
143147

144148
## Configuration
@@ -157,8 +161,10 @@ Commit cancelled.
157161
- **Missing API key** → exits with message to set `OPENAI_API_KEY`
158162
- **API failures** → shows HTTP status and response body
159163
- **Invalid JSON** → shows raw model output for debugging
160-
- **User cancellation** → exits gracefully with "Commit cancelled." when user responds with `n` or `no`
161-
- **Invalid confirmation input** → prompts user to answer `y/n` again
164+
- **Commit creation failed** → exits with error message if `git commit` fails
165+
- **Push declined** → exits gracefully with "Push cancelled. Commit saved locally." when user responds with `n` or `no`
166+
- **Push failed** → shows error if `git push` fails (commit is already saved locally)
167+
- **Invalid push confirmation input** → prompts user to answer `y/n` again
162168

163169
## Development
164170

@@ -212,7 +218,14 @@ This project is open source. See the repository for details.
212218
export EDITOR="code --wait"
213219
```
214220

215-
**"Commit cancelled" message**
221+
**"Push cancelled. Commit saved locally." message**
222+
223+
- This is expected behavior. The user can respond `n` or `no` at the push confirmation prompt to keep the commit local.
224+
- The commit is already created and saved; the push is simply skipped.
225+
- You can push manually later with `git push`.
226+
227+
**"Push failed" error**
216228

217-
- This is expected behavior. The user can respond `n` or `no` at the confirmation prompt to cancel the commit without opening the editor.
218-
- The tool exits gracefully without making any changes to the repository.
229+
- The commit was created successfully, but the push to remote failed (network issues, authentication, etc.)
230+
- Your commit is safely saved locally
231+
- You can try pushing again manually or resolve any issues before retrying

src/main.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,9 @@ fn build_commit_line(commit: &Commit) -> String {
209209
out
210210
}
211211

212-
fn confirm_commit(message: &str) -> Result<bool> {
213-
eprintln!("\nGenerated commit message:");
214-
eprintln!(" {}", message);
215-
eprintln!();
216-
212+
fn confirm_push() -> Result<bool> {
217213
loop {
218-
eprint!("Proceed with commit? (y/n): ");
214+
eprint!("Push commit to remote? (y/n): ");
219215
io::stderr().flush()?;
220216

221217
let mut input = String::new();
@@ -267,29 +263,43 @@ async fn main() -> Result<()> {
267263

268264
let line = build_commit_line(&commit);
269265

270-
// Ask for confirmation before committing
271-
let should_commit = match confirm_commit(&line) {
266+
// Run: git commit -e -m "<line>"
267+
let status = Command::new("git")
268+
.args(["commit", "-e", "-m", &line])
269+
.status()
270+
.context("failed to run `git commit`")?;
271+
272+
if !status.success() {
273+
return Err(anyhow!("git commit failed with status: {status}"));
274+
}
275+
276+
eprintln!("Commit created successfully.");
277+
278+
// Ask for confirmation before pushing
279+
let should_push = match confirm_push() {
272280
Ok(confirmed) => confirmed,
273281
Err(e) => {
274-
eprintln!("Error during confirmation: {e}");
282+
eprintln!("Error during push confirmation: {e}");
275283
std::process::exit(1);
276284
}
277285
};
278286

279-
if !should_commit {
280-
eprintln!("Commit cancelled.");
287+
if !should_push {
288+
eprintln!("Push cancelled. Commit saved locally.");
281289
return Ok(());
282290
}
283291

284-
// Run: git commit -e -m "<line>"
292+
// Run: git push
285293
let status = Command::new("git")
286-
.args(["commit", "-e", "-m", &line])
294+
.args(["push"])
287295
.status()
288-
.context("failed to run `git commit`")?;
296+
.context("failed to run `git push`")?;
289297

290298
if !status.success() {
291-
return Err(anyhow!("git commit failed with status: {status}"));
299+
return Err(anyhow!("git push failed with status: {status}"));
292300
}
293301

302+
eprintln!("Changes pushed successfully!");
303+
294304
Ok(())
295305
}

0 commit comments

Comments
 (0)