@hyperfrontend/versioning/git/modelsmodels
Plain-data git models for commits, tags, and refs, with factories and small predicates.
GitCommit, GitRef, and GitTag are the structured shapes consumed by every other git module. Factories (createGitCommit, createGitRef, createLightweightTag, createAnnotatedTag) produce instances from raw fields. Predicates (isSameCommit, isMergeCommit, isRootCommit, isBranchRef, isTagRef, isRemoteRef, isHeadRef) and accessors (getShortHash, extractScope, extractType) cover the common questions consumers ask of these models without having to re-derive the answers from the raw git output.
API Reference
ƒ Functions
Parameters
Returns
stringExample
Build full reference names from type and name
buildRefName('branch', 'main') // 'refs/heads/main'
buildRefName('tag', 'v1.0.0') // 'refs/tags/v1.0.0'
buildRefName('remote', 'main', 'origin') // 'refs/remotes/origin/main'Parameters
Returns
stringExample
Build tag names with different formats
buildTagName('@scope/pkg', '1.2.3') // '@scope/pkg@1.2.3'
buildTagName('utils', '1.0.0', 'v${version}') // 'v1.0.0'
buildTagName('pkg', '2.0.0', '${package}-v${version}') // 'pkg-v2.0.0'Returns
numberExample
Sort references alphabetically by name
const refs = [refB, refA, refC]
refs.sort(compareRefsByName) // => [refA, refB, refC]Returns
numberExample
Sort tags by version (newest first)
const tags = [tagV1, tagV2, tagV3]
tags.sort(compareTagsByVersion) // => [tagV3, tagV2, tagV1]Parameters
| Name | Type | Description |
|---|---|---|
§options | CreateAnnotatedTagOptions | Tag creation options |
Returns
GitTagExample
Create an annotated git tag with metadata
const tag = createAnnotatedTag({
name: 'v1.0.0',
commitHash: 'abc123...',
message: 'Release v1.0.0',
taggerName: 'John Doe',
taggerEmail: 'john@example.com',
tagDate: '2026-03-12T10:00:00Z',
})Parameters
| Name | Type | Description |
|---|---|---|
§options | CreateGitCommitOptions | Commit creation options |
Returns
GitCommitExample
Create a git commit model
const commit = createGitCommit({
hash: 'abc123...',
authorName: 'John Doe',
authorEmail: 'john@example.com',
authorDate: '2026-03-12T10:00:00Z',
subject: 'feat: add new feature',
})Parameters
| Name | Type | Description |
|---|---|---|
§options | CreateGitRefOptions | Reference creation options |
Returns
GitRefExample
Create a git reference from full name
const ref = createGitRef({
fullName: 'refs/heads/main',
commitHash: 'abc123...',
})Parameters
| Name | Type | Description |
|---|---|---|
§options | CreateLightweightTagOptions | Tag creation options |
Returns
GitTagExample
Create a lightweight git tag
const tag = createLightweightTag({
name: 'v1.0.0',
commitHash: 'abc123...',
})@scope/package@1.2.3, package@1.2.3, package-v1.2.3 Uses character-by-character parsing (no regex).Parameters
| Name | Type | Description |
|---|---|---|
§tagName | string | Tag name to parse |
Returns
stringExample
Extract package name from tag
extractPackageFromTag('@scope/pkg@1.2.3') // '@scope/pkg'
extractPackageFromTag('lib-utils@1.2.3') // 'lib-utils'
extractPackageFromTag('v1.2.3') // undefinedParameters
| Name | Type | Description |
|---|---|---|
§subject | string | Commit subject line |
Returns
stringExample
Extract scope from conventional commit
extractScope('feat(lib-versioning): add git support') // 'lib-versioning'
extractScope('fix: resolve issue') // undefinedParameters
| Name | Type | Description |
|---|---|---|
§subject | string | Commit subject line |
Returns
stringExample
Extract type from conventional commit
extractType('feat(lib-versioning): add git support') // 'feat'
extractType('fix: resolve issue') // 'fix'
extractType('random message') // undefined@scope/package@1.2.3, package@1.2.3 Uses character-by-character parsing (no regex).Parameters
| Name | Type | Description |
|---|---|---|
§tagName | string | Tag name to parse |
Returns
stringExample
Extract version from various tag formats
extractVersionFromTag('v1.2.3') // '1.2.3'
extractVersionFromTag('@scope/pkg@1.2.3') // '1.2.3'
extractVersionFromTag('release-1.2.3') // '1.2.3'Returns
unknownExample
Filter references by remote
const originRefs = filterRefsByRemote(remoteRefs, 'origin')
const upstreamRefs = filterRefsByRemote(remoteRefs, 'upstream')Returns
unknownExample
Filter references by type
const branches = filterRefsByType(allRefs, 'branch')
const tags = filterRefsByType(allRefs, 'tag')Parameters
| Name | Type | Description |
|---|---|---|
§ref | GitRef | Reference to check |
Returns
stringExample
Get the remote for a reference
getRemote({ type: 'remote', name: 'main', remote: 'origin' }) // => 'origin'
getRemote({ type: 'branch', name: 'main' }) // => undefinedParameters
| Name | Type | Description |
|---|---|---|
§hash | string | Full commit hash |
Returns
stringExample
Get short hash from full commit hash
getShortHash('abc123def456789') // => 'abc123d'Parameters
| Name | Type | Description |
|---|---|---|
§tag | GitTag | Tag to check |
Returns
booleanExample
Check if a tag is annotated
const tag = createAnnotatedTag({ name: 'v1.0.0', commitHash: 'abc123', message: 'Release' })
isAnnotatedTag(tag) // => trueParameters
| Name | Type | Description |
|---|---|---|
§ref | GitRef | Reference to check |
Returns
booleanExample
Check if reference is a branch
isBranchRef({ type: 'branch', name: 'main' }) // => trueParameters
| Name | Type | Description |
|---|---|---|
§ref | GitRef | Reference to check |
Returns
booleanExample
Check if reference points to HEAD
isHeadRef({ type: 'head', name: 'HEAD' }) // => true
isHeadRef({ type: 'branch', name: 'main', isHead: true }) // => trueParameters
| Name | Type | Description |
|---|---|---|
§tag | GitTag | Tag to check |
Returns
booleanExample
Check if a tag is lightweight
const tag = createLightweightTag({ name: 'v1.0.0', commitHash: 'abc123' })
isLightweightTag(tag) // => trueParameters
| Name | Type | Description |
|---|---|---|
§commit | GitCommit | Commit to check |
Returns
booleanExample
Check if commit is a merge commit
if (isMergeCommit(commit)) {
console.log('Commit has parents:', commit.parents)
}Parameters
| Name | Type | Description |
|---|---|---|
§ref | GitRef | Reference to check |
Returns
booleanExample
Check if reference is a remote tracking branch
isRemoteRef({ type: 'remote', name: 'main', remote: 'origin' }) // => trueParameters
| Name | Type | Description |
|---|---|---|
§commit | GitCommit | Commit to check |
Returns
booleanExample
Check if commit is the initial commit
if (isRootCommit(commit)) {
console.log('This is the initial commit')
}Returns
booleanExample
Compare two commits by hash
isSameCommit(commitA, commitB) // => true if commitA.hash === commitB.hash