Skip to content

仓库 files navigation

@planjs/git-utils

一个可编程和命令行的git工具集合, 基于 nodegit 组件包开发。

安装

sudo npm i -g @planjs/git-utils --unsafe-perm=true
# or
npm i -D @planjs/git-utils

cli 方式调用

--check=branch 检测当前分支是否正确
gt --check=test

如果当前分支不是 test 将会报错

--autoMerge=targerBranch 切换目标分支并且合并

gt --autoMerge=develop

将当前分支合并到develop并且将本地分支切换到develop分支,失败条件:合并存在冲突、本地分支存在为commit内容。

--check=branch --entry=/project 指定仓库目录地址

gt --autoMerge=develop --entry=/project

entry参数可以指定所在仓库目录地址

Node Api

使用例子

import GT, { open仓库 } from '@quan/git-utils';
const repo = GT({ autoMerge: 'develop' })
gitUtils(options: { check?: string, autoMerge?: string, entry?: string })

与命令行行为一致

open仓库(path?: string): Promise<Git.仓库>

打开一个git仓库,path 参数为仓库目录路径。

checkNotCommit(repo: Git.仓库): Promise<Git.仓库>

检测本地分支是否存在为保存内容。

function pull(repo: Git.仓库): Promise<Git.仓库>

拉取远程仓库内容

function switchBranch(repo: Git.仓库,name: string): Promise<Git.仓库>

切换到对应分支

mergeBranch(repo: Git.仓库,fromBranch: string): Promise<Git.仓库>

合并对应的分支,如果发生冲突会合并失败。

function push(repo: Git.仓库)

推送到远程仓库中

关于

No description, website, or topics provided.

Resources

Stars

3 stars

关注者

1 watching

复刻s

发布

Used by

贡献者

Languages