gitutil

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gitutil provides helpers for running git commands and parsing output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommitsAhead

func CommitsAhead(branch, remote string) (int, error)

CommitsAhead returns the number of commits ahead of upstream for the given branch.

func CurrentBranch

func CurrentBranch() (string, error)

CurrentBranch returns the current branch name.

func HeadParents

func HeadParents() ([]string, error)

HeadParents returns abbreviated SHAs of HEAD's parent commits.

func HeadSHA

func HeadSHA() (string, error)

HeadSHA returns the full HEAD SHA.

func HeadSHAShort

func HeadSHAShort() (string, error)

HeadSHAShort returns a 12-char abbreviated HEAD SHA.

func IsGitRepo

func IsGitRepo() bool

IsGitRepo returns true if the current directory is inside a git repo.

func IsShallowRepo

func IsShallowRepo() bool

IsShallowRepo returns true if the repo is shallow.

func ParseProjectSlugFromURL

func ParseProjectSlugFromURL(remoteURL string) (projectKey, repoSlug string)

ParseProjectSlugFromURL extracts Bitbucket DC project key and repo slug. Input: https://bb.example.com/scm/PLAT/api.git Returns: ("PLAT", "api")

func Refspecs

func Refspecs(branch string) []string

Refspecs builds the default push refspec for a branch.

func RemoteURL

func RemoteURL(remote string) (string, error)

RemoteURL returns the URL for the given remote.

func Run

func Run(args ...string) (string, error)

Run executes a git command and returns trimmed stdout.

func StagedFiles

func StagedFiles() ([]string, error)

StagedFiles returns the list of files in the index (staged for commit).

Types

type DiffStat

type DiffStat struct {
	FilesChanged int
	Insertions   int
	Deletions    int
}

DiffStats returns insertions/deletions for staged changes.

func StagedDiffStats

func StagedDiffStats() (DiffStat, error)

StagedDiffStats parses `git diff --cached --numstat` output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL