Get git information using your system git executable.
MIT License
Get git strings like a git describe reference or git commit hash.
Requirements:
PATH
.npm install git-ref
or
yarn add git-ref
Note: If run in a script which is not a git tree, or with no commits, an empty string is returned.
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"
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"
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
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
Get the current HEAD
branch name.
import { branchName } from 'git-ref';
const branch = branchName();
console.log(branch); // "master"
See releases on GitHub.
git-ref
is an MIT licensed open source project. See LICENCE.
© 2024 Max Milton