@sumor/git
v1.0.4
Published
A git version library, easily packaging version and generate specific package with env.
Downloads
4,728
Readme
git
A Sumor Cloud Tool.
More Documentation
A git version library, easily packaging version and generate specific package with env.
Installation
npm i @sumor/git --save
Prerequisites
Node.JS version
Require Node.JS version 18.x or above
require Node.JS ES module
As this package is written in ES module,
please change the following code in your package.json
file:
{
"type": "module"
}
Usage
import git from '@sumor/git'
const config = {
// git url and credentials
url: '<git url>', // mandatory
token: '<git token>', // mandatory, if username and password are not provided
username: '<git username>', // mandatory, if token is not provided
password: '<git password>' // mandatory, if token is not provided
}
const repository = await git(config, path)
const commit1 = await repository.currentCommit() // get current commit
const commitTime1 = await repository.currentCommitTime() // get current commit time, in milliseconds
await repository.checkout('<target commit>') // can be a branch or a tag or a commit
const commit2 = await repository.currentCommit() // get current commit
// if you installed Github Desktop, you can use below command to open it in Github Desktop
await repository.github()
Create new local repository
When you pass null as config, it will create a new repository in local path.
await git(null, path1)
// usage for local repository
const repository = await git({ url: path1 }, path2)