package
0.0.0-20241107114533-5702851476d2
Repository: https://github.com/open-ch/kaeter.git
Documentation: pkg.go.dev

# README

native git wrapper

Not go-git, not gitshell.

New functionality will be added here, eventually gitshell functionality will be reimplemented here as well.

The goal of this package is to allow:

  1. Making git calls
  2. Keeping the syntax as close to the git syntax as possible
  3. Avoiding hidden information (flags automatically passed, ...)
  4. Adding extra flags to a command easily

Why not go-git?

Historically it was implemented (gitshell) relying on the local git install, perhaps using quirks of git versions at the time, or perhaps relying on lower level feature go-git did not provide at the time of implementation. This might no longer hold true today.

Also by design gitshell did not require instances or objects, functions could be called without needing to first create an instance or pass an instance around, acting more like a singleton. This still holds true, a single line call is more readable than instantiating and object, preparing an action and then executing it over multiple lines.

Why not gitshell?

Gitshell doesn't have state, it's not a singleton, it's only an interface to git. This requires passing the working director (the repository path) everytime. It keeps the functions somewhat more pure but requires repetitive dangling parameters in the front. Using a singleton approach would allow setting the working path once, since kaeter works on a single repository this will make it more DRY.

Gitshell doesn't allow expanding parameters. It's nicely and strongly typed but to pass one more flag to a git command requires updating the library.

# Functions

Add simplifies calls to git add path git.Add("path/to/repo", "README.md").
BranchContains is a shortcut to check git.BranchContains("path/to/repo", "commit_hash", "branch_pattern") git.BranchContains("path/to/repo", "3ae22a91a12", "main").
Checkout simplifies calls to git checkout gitRef git.Checkout("path/to/repo", "d69928b5a74f70f6000db39d63d84e0aa2aa8ec9").
Commit simplifies calls to git commit -m message git.Commit("path/to/repo", "FIX: solves the concurency problem with the turbolift").
DiffNameStatus extracts the map of files and the action that was performed on them: added, modified or delete.
GetCommitMessageFromRef returns the commit message (raw body) from the given commit revision or hash.
LogOneLine is an alias for git log --oneline refrange path git.LogOneLine("path/to/some/change", "somehash..HEAD", "some/path").
ResetHard simplifies calls to git reset --hard gitRef git.ResetHard("path/to/repo", "d69928b5a74f70f6000db39d63d84e0aa2aa8ec9").
ResolveRevision prints the SHA1 hash given a revision specifier see https://git-scm.com/docs/git-rev-parse for more details.
RestoreFile allows restoring a single file or path.
ShowTopLevel finds the root of a git repo given a path see https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---show-toplevel for more details.
ValidateCommitIsOnTrunk can be used to validate that a given hash has a common ancestry with a specific branch.

# Constants

Added signals that the file was modified.
Deleted signals that the file was modified.
Modified signals that the file was modified.

# Type aliases

FileChangeStatus is an enumeration of possible actions perform on files within a commit.