0.4.0 • Published 11 months ago

git-ref v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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

0.4.0

11 months ago

0.3.1

2 years ago

0.3.0

3 years ago

0.1.0

3 years ago

0.2.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago