Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloving",
"version": "0.3.19",
"version": "0.3.20",
"packageManager": "yarn@1.22.22",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ program
'-m, --model <model>',
'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)',
)
.option('-a, --autoAccept', 'Automatically accept the generated commit message without editing')
.action(commit)

// Generate commands
Expand Down Expand Up @@ -143,6 +144,7 @@ generate
'-m, --model <model>',
'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)',
)
.option('-a, --autoAccept', 'Automatically accept the generated commit message without editing')
.action(commit)

generate
Expand Down
43 changes: 28 additions & 15 deletions src/managers/CommitManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import type { AxiosError } from 'axios'

class CommitManager {
private gpt: ClovingGPT
private autoAccept: boolean

constructor(options: ClovingGPTOptions) {
options.silent = getConfig(options).globalSilent || false
this.autoAccept = options.autoAccept || false
this.gpt = new ClovingGPT(options)
}

Expand Down Expand Up @@ -43,24 +45,35 @@ class CommitManager {
// Clean the commit message using extractMarkdown and remove code blocks
const commitMessage = this.cleanCommitMessage(extractMarkdown(rawCommitMessage))

// Write the commit message to a temporary file
const tempCommitFilePath = path.join('.git', 'SUGGESTED_COMMIT_EDITMSG')
fs.writeFileSync(tempCommitFilePath, commitMessage)
if (this.autoAccept) {
// Directly commit with the generated message without opening an editor
try {
execFileSync('git', ['commit', '-a', '-m', commitMessage], {
stdio: 'inherit',
})
} catch (commitError) {
console.log('Commit failed:', (commitError as Error).message)
}
} else {
// Write the commit message to a temporary file
const tempCommitFilePath = path.join('.git', 'SUGGESTED_COMMIT_EDITMSG')
fs.writeFileSync(tempCommitFilePath, commitMessage)

// Commit the changes using the generated commit message
try {
execFileSync('git', ['commit', '-a', '--edit', '--file', tempCommitFilePath], {
stdio: 'inherit',
// Commit the changes using the generated commit message
try {
execFileSync('git', ['commit', '-a', '--edit', '--file', tempCommitFilePath], {
stdio: 'inherit',
})
} catch (commitError) {
// If commit is canceled (non-zero exit), handle it here
console.log('Commit was canceled or failed.')
}

// Remove the temporary file using fs
fs.unlink(tempCommitFilePath, (err) => {
if (err) throw err
})
} catch (commitError) {
// If commit is canceled (non-zero exit), handle it here
console.log('Commit was canceled or failed.')
}

// Remove the temporary file using fs
fs.unlink(tempCommitFilePath, (err) => {
if (err) throw err
})
} catch (err) {
const error = err as AxiosError
console.error('Could not generate commit message:', error.message)
Expand Down
1 change: 1 addition & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface ClovingGPTOptions {
port?: number
stream?: boolean
timeout?: number
autoAccept?: boolean
}

export interface ClovingModelConfig {
Expand Down