All files / scripts/git-utils commit.ts

0% Statements 0/19
0% Branches 0/1
0% Functions 0/1
0% Lines 0/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 29                                                         
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)
  }
}