class GitOperations

Provides a comprehensive interface for git operations needed during the release process. Handles commit parsing, tag management, and repository state validation.

Common Git Issues and Solutions

"No commits found since last release"

  • Ensure you have commits: git log --oneline -n 10
  • Check last tag: git describe --tags --abbrev=0
  • Verify tag format matches your config (default: "v" prefix)

"Uncommitted changes detected"

  • Check status: git status
  • Stash changes: git stash
  • Or commit: git add . && git commit -m "chore: prepare for release"

"Not a git repository"

  • Initialize: git init
  • Add remote: git remote add origin <url>

Examples

Direct usage for custom workflows

const git = new GitOperations(config);

// Check repository state
if (!await git.isGitRepository()) {
  throw new Error("Not in a git repository");
}

// Get commits for analysis
const commits = await git.getCommitsSinceLastRelease();
console.log(`Found ${commits.length} commits`);

// Parse a specific commit
const parsed = git.parseConventionalCommit("feat(api): add user auth");
console.log(`Type: ${parsed.type}, Scope: ${parsed.scope}`);

Tag management

const git = new GitOperations(config);

// Create and push a new tag
await git.commitAndTag("1.2.0", ["CHANGELOG.md", "version.ts"]);
await git.pushToRemote("v1.2.0");

// Check if tag exists on remote
const exists = await git.remoteTagExists("v1.2.0");

Constructors

GitOperations(config: NagareConfig)

Methods

commitAndTag(version: string): Promise<void>

Create commit and tag for release

deleteLocalTag(tag: string): Promise<void>

Delete a local tag

deleteRemoteTag(tag: string): Promise<void>

Delete a remote tag

extractPRNumber(message: string): number | null

Extract PR number from a merge commit message Supports various GitHub merge formats

getCommitsInPR(mergeCommit: string): Promise<ConventionalCommit[]>

Get commits that were part of a PR Returns commits between merge base and the second parent of merge commit

Get commits since last release

getCurrentBranch(): Promise<string>

Get current branch name.

getCurrentCommitHash(): Promise<string>

Get current commit hash (short format).

getGitUser(): Promise<{ name: string; email: string; }>

Get git user configuration.

getLastCommitMessage(): Promise<string>

Get the last commit message

getLastReleaseTag(): Promise<string>

Get the last release tag.

getLocalTags(): Promise<string[]>

Get list of local tags

getMergeCommits(since: string): Promise<Array<{ sha: string; message: string; date: string; }>>

Get merge commits since a specific tag or commit Used for PR detection in changelog generation

hasUncommittedChanges(): Promise<boolean>

Check for uncommitted changes in the working directory.

isGitRepository(): Promise<boolean>

Check if current directory is a git repository.

pushToRemote(): Promise<void>

Push changes and tags to remote

remoteTagExists(tag: string): Promise<boolean>

Check if a remote tag exists

resetToCommit(
commitish: string,
hard?: boolean
): Promise<void>

Reset to a previous commit (for rollback)