README
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
Licence
git-ref
is an MIT licensed open source project. See LICENCE.
© 2021 Max Milton