A Sumor Cloud Tool.
More Documentation
A git version library, easily packaging version and generate specific package with env.
npm i @sumor/git --save
Require Node.JS version 18.x or above
As this package is written in ES module,
please change the following code in your package.json
file:
{
"type": "module"
}
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 commit2 = await repository.checkout('<target commit>') // can be a branch or a tag or a commit
// if you installed Github Desktop, you can use below command to open it in Github Desktop
await repository.github()
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)