git-ref
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

Build status Coverage status NPM version NPM bundle size (minified + gzip) Licence

git-ref

Get git strings like a git describe reference or git commit hash.

Requirements:

  • git must be installed on your system and resolvable in your shell PATH.

Installation

npm install git-ref

or

yarn add git-ref

Usage

Note: If run in a script which is not a git tree, or with no commits, an empty string is returned.

Git reference

Get the current HEAD git reference via git describe.

import { gitRef } from 'git-ref';

const ref = gitRef();

console.log(ref); // "v0.0.3-16-g93d0f1d-dev"

Git hash

Get the current HEAD commit hash.

import { gitHash } from 'git-ref';

const hash = gitHash();
const hashLong = gitHash(true);

console.log(hash); // "93d0f1d"
console.log(hashLong); // "93d0f1dc4de720863e4b5f74970cf8f2012f3d88"

Detect dirty tree state

Find out if the git working tree is dirty (e.g., contains uncommitted changes).

import { isDirty } from 'git-ref';

const state = isDirty();

console.log(state); // false

Commits away from closest tag

Get the number of commits from the closest tagged commit to the current HEAD commit.

import { fromClosestTag } from 'git-ref';

const count = fromClosestTag();

console.log(count); // 0

Branch name

Get the current HEAD branch name.

import { branchName } from 'git-ref';

const branch = branchName();

console.log(branch); // "master"

Changelog

See releases on GitHub.

Licence

git-ref is an MIT licensed open source project. See LICENCE.


© 2023 Max Milton

Readme

Keywords

none

Package Sidebar

Install

npm i git-ref

Weekly Downloads

8

Version

0.4.0

License

MIT

Unpacked Size

7.98 kB

Total Files

5

Last publish

Collaborators

  • maxmilton