@sumor/git

git

Sumor Cloud Tool. More Documentation

A git version library, easily packaging version and generate specific package with env.

NPM Version NPM Downloads GitHub CI GitHub Test GitHub Coverage GitHub Audit

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 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()

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)