-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.ts
More file actions
28 lines (24 loc) · 733 Bytes
/
commit.ts
File metadata and controls
28 lines (24 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { x } from 'tinyexec'
const execOptions = { throwOnError: true }
// 提交函数
export async function gitCommit(files: string[] = [], commitMsg: string) {
try {
// 1. 添加文件到暂存区
if (files.length > 0) {
console.log('Staging files...')
await x('git', ['add', ...files], execOptions)
}
else {
// console.log('No files specified. Staging all changes...')
// await x('git', ['add', '.'], execOptions)
return
}
// 2. 提交
console.log(`Committing with message: ${commitMsg}`)
await x('git', ['commit', '-m', commitMsg], execOptions)
console.log('Commit successful!')
}
catch (error) {
console.error(`Error during commit:`, error)
}
}