Skip to content

引入

ts
import {
  getAllGitRepo,
  getGitCurBranch,
  getGitCommitMessage,
  getGitCommitInfo,
  getGitLastTag,
  getGitCommitsBeforeTag,
  getGitAuthor,
  reCloneGitRemote
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  getAllGitRepo,
  getGitCurBranch,
  getGitCommitMessage,
  getGitCommitInfo,
  getGitLastTag,
  getGitCommitsBeforeTag,
  getGitAuthor,
  reCloneGitRemote
} from 't-comm/lib/git/index';

// 只支持 ESM 的项目
import {
  getAllGitRepo,
  getGitCurBranch,
  getGitCommitMessage,
  getGitCommitInfo,
  getGitLastTag,
  getGitCommitsBeforeTag,
  getGitAuthor,
  reCloneGitRemote
} from 't-comm/es/git/index';

getAllGitRepo(root)

描述

获取所有 git 仓库

参数

参数名类型描述
rootstring

根路径

返回: array

路径列表

示例

ts
getAllGitRepo('/root/yang');

[
  {
    root: '/root',
    origin: 'git@git.address',
  }
]

getGitCurBranch()

描述

获取当前分支

参数

返回: string

分支名称

示例

typescript
getGitCurBranch()

// => master

getGitCommitMessage(root, mergeCommit, splitMessage)

描述

获取提交信息

参数

参数名类型描述
rootstring

根路径

mergeCommitboolean

是否包含 merge 的提交

splitMessageboolean

是否去掉提交信息的前缀

返回: string

提交信息

示例

ts
getGitCommitMessage()
// '优化一部分文档'

getGitCommitInfo(root, mergeCommit, splitMessage)

描述

获取提交信息

参数

参数名类型描述
rootstring

根路径

mergeCommitboolean

是否包含 merge 的提交

splitMessageboolean

是否去掉提交信息的前缀

返回: Object

提交对象

示例

ts
getGitCommitInfo()
{
  author: 'novlan1',
  message: ' 优化一部分文档',
  hash: '0cb71f9',
  date: '2022-10-02 10:34:31 +0800',
  timeStamp: '1664678071',
  branch: 'master'
}

getGitLastTag()

描述

获取最新tag

参数

返回: string

最新tag

getGitCommitsBeforeTag(tag)

描述

获取tag到head的提交数目

参数

参数名类型描述
tagstring

git标签

返回: string

tag至今的提交数目

getGitAuthor(isPriorGit)

描述

获取当前用户

参数

参数名描述
isPriorGit

是否优先使用git用户信息

返回:

user

reCloneGitRemote(list)

描述

根据配置表,重新 clone 仓库

参数

参数名类型描述
listArray<item>

列表

item.rootstring

路径

item.originstring

origin