@sumor/git

git

Sumor Cloud 工具。
更多文档

一个git版本库,可以轻松打包版本并生成具有特定环境的包。

NPM 版本 NPM 下载量 GitHub CI GitHub 测试 GitHub 覆盖率 GitHub 审计

安装

npm i @sumor/git --save

先决条件

Node.JS 版本

要求 Node.JS 版本为 18.x 或更高

需要 Node.JS ES 模块

由于此包是用 ES 模块编写的,请更改您的 package.json 文件中的以下代码:

{
  "type": "module"
}

用法

import git from '@sumor/git'
const config = {
  // git url 和凭证
  url: '<git url>', // 必填
  token: '<git token>', // 如果未提供用户名和密码,则为必填
  username: '<git username>', // 如果未提供令牌,则为必填
  password: '<git password>' // 如果未提供令牌,则为必填
}
const repository = await git(config, path)

const commit1 = await repository.currentCommit() // 获取当前提交

const commit2 = await repository.checkout('<target commit>') // 可以是分支、标签或提交

// 如果已安装 Github Desktop,可以使用下面的命令在 Github Desktop 中打开它
await repository.github()

创建新的本地存储库

当将配置参数设为 null 时,将在本地路径中创建一个新存储库。

await git(null, path1)

// 本地存储库用法
const repository = await git({ url: path1 }, path2)