nichegit

package module
v0.0.0-...-1302caa Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 24 Imported by: 0

README

niche-git

niche-git is a niche git utility.

Motivation

Git protocol has been evolved to support more advanced operations. However, in order to harness that capability, C-git client is not enough in some cases. This project provides a utility for such niche use cases.

How to use it

Getting modified files
go run cmd/niche-git/main.go get-modified-files \
    --repo-url https://github.com/git/git \
    --commit-hash1 3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0 \
    --commit-hash2 efb050becb6bc703f76382e1f1b6273100e6ace3

With authn:

go run cmd/niche-git/main.go get-modified-files \
    --repo-url https://github.com/draftcode/some-private-repo \
    --commit-hash1 998122b45e63b2999d57a1af9e74761c0524e932 \
    --commit-hash2 f27a58920f7319cc7b62e55cf3095d1ee2ab1dde \
    --basic-authz-user x-access-token \
    --basic-authz-password "$(gh auth token)"
Get commits
go run cmd/niche-git/main.go get-commits \
    --repo-url https://github.com/git/git \
    --want-commit-hashes 3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0 \
    --have-commit-hashes efb050becb6bc703f76382e1f1b6273100e6ace3
List refs
go run cmd/niche-git/main.go ls-refs \
    --repo-url https://github.com/git/git \
    --ref-prefixes refs/heads/

Adding a license header

addlicense -c "Aviator Technologies, Inc." -l mit -s=only .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackportArgs

type BackportArgs struct {
	RepoURL         string   `json:"repoURL"`
	BaseCommitHash  string   `json:"baseCommitHash"`
	BackportCommits []string `json:"backportCommits"`
	Ref             string   `json:"ref"`
	CurrentRefHash  string   `json:"currentRefHash"`
}

type BackportCommandResult

type BackportCommandResult struct {
	CommitHash              string   `json:"commitHash"`
	ConflictResolvedFiles   []string `json:"conflictResolvedFiles"`
	ConflictUnresolvedFiles []string `json:"conflictUnresolvedFiles"`
}

type BackportOutput

type BackportOutput struct {
	CommandResults  []BackportCommandResult `json:"commandResults"`
	FetchDebugInfos []*debug.FetchDebugInfo `json:"fetchDebugInfos"`
	PushDebugInfo   *debug.PushDebugInfo    `json:"pushDebugInfo"`
	Error           string                  `json:"error,omitempty"`
}

func Backport

func Backport(ctx context.Context, client *http.Client, args BackportArgs) BackportOutput

type CommitInfo

type CommitInfo struct {
	// Hash is the commit hash.
	Hash string `json:"hash"`

	// Author is the author of the commit.
	Author CommitSignature `json:"author"`

	// Committer is the committer of the commit.
	Committer CommitSignature `json:"committer"`

	// Message is the commit message.
	Message string `json:"message"`

	// TreeHash is the hash of the tree object of the commit.
	TreeHash string `json:"treeHash"`

	// ParentHashes are the hashes of the parent commits.
	ParentHashes []string `json:"parentHashes"`
}

func FetchCommits

func FetchCommits(ctx context.Context, repoURL string, client *http.Client, wantCommitHashes, haveCommitHashes []plumbing.Hash) ([]*CommitInfo, debug.FetchDebugInfo, error)

type CommitSignature

type CommitSignature struct {
	Name      string    `json:"name"`
	Email     string    `json:"email"`
	Timestamp time.Time `json:"timestamp"`
}

type FoundMergeBase

type FoundMergeBase struct {
	CommitHash string `json:"commitHash"`
	Generation int    `json:"generation"`
}

type GetCommitsArgs

type GetCommitsArgs struct {
	RepoURL          string   `json:"repoURL"`
	WantCommitHashes []string `json:"wantCommitHashes"`
	HaveCommitHashes []string `json:"haveCommitHashes"`
}

type GetCommitsOutput

type GetCommitsOutput struct {
	Commits   []*CommitInfo        `json:"commits"`
	DebugInfo debug.FetchDebugInfo `json:"debugInfo"`
	Error     string               `json:"error,omitempty"`
}

func GetCommits

func GetCommits(ctx context.Context, client *http.Client, args GetCommitsArgs) GetCommitsOutput

type GetFilesArgs

type GetFilesArgs struct {
	RepoURL    string   `json:"repoURL"`
	CommitHash string   `json:"commitHash"`
	FilePaths  []string `json:"filePaths"`
}

type GetFilesOutput

type GetFilesOutput struct {
	Files              map[string]string     `json:"files"`
	FetchDebugInfo     *debug.FetchDebugInfo `json:"fetchDebugInfo"`
	BlobFetchDebugInfo *debug.FetchDebugInfo `json:"blobFetchDebugInfo"`
	Error              string                `json:"error,omitempty"`
}

func GetFiles

func GetFiles(ctx context.Context, client *http.Client, args GetFilesArgs) GetFilesOutput

type GetMergeBaseArgs

type GetMergeBaseArgs struct {
	RepoURL      string   `json:"repoURL"`
	CommitHashes []string `json:"commitHashes"`
}

type GetMergeBaseOutput

type GetMergeBaseOutput struct {
	MergeBases      []FoundMergeBase        `json:"mergeBases"`
	FetchDebugInfos []*debug.FetchDebugInfo `json:"fetchDebugInfos"`
	Error           string                  `json:"error,omitempty"`
}

func GetMergeBase

func GetMergeBase(ctx context.Context, client *http.Client, args GetMergeBaseArgs) GetMergeBaseOutput

type GetModifiedFilesArgs

type GetModifiedFilesArgs struct {
	RepoURL     string `json:"repoURL"`
	CommitHash1 string `json:"commitHash1"`
	CommitHash2 string `json:"commitHash2"`
}

type GetModifiedFilesOutput

type GetModifiedFilesOutput struct {
	Files     []string             `json:"files"`
	DebugInfo debug.FetchDebugInfo `json:"debugInfo"`
	Error     string               `json:"error,omitempty"`
}

func GetModifiedFiles

func GetModifiedFiles(ctx context.Context, client *http.Client, args GetModifiedFilesArgs) GetModifiedFilesOutput

type GetModifiedFilesPattern

type GetModifiedFilesPattern struct {
	FilePathPatterns   []string `json:"filePathPatterns"`
	FileContentPattern string   `json:"fileContentPattern,omitempty"`
}

type GetModifiedFilesRegexpMatchesArgs

type GetModifiedFilesRegexpMatchesArgs struct {
	RepoURL     string                             `json:"repoURL"`
	CommitHash1 string                             `json:"commitHash1"`
	CommitHash2 string                             `json:"commitHash2"`
	Patterns    map[string]GetModifiedFilesPattern `json:"patterns"`
}

type GetModifiedFilesRegexpMatchesOutput

type GetModifiedFilesRegexpMatchesOutput struct {
	Files              []*ModifiedFile       `json:"files"`
	FetchDebugInfo     *debug.FetchDebugInfo `json:"fetchDebugInfo"`
	BlobFetchDebugInfo *debug.FetchDebugInfo `json:"blobFetchDebugInfo"`
	Error              string                `json:"error,omitempty"`
}

type LinearRebaseArgs

type LinearRebaseArgs struct {
	RepoURL string `json:"repoURL"`

	BaseCommit        string `json:"mergeBase"`
	DestinationCommit string `json:"destinationCommit"`

	// Refs is a list of references to rebase. The first element is the first ref to rebase.
	Refs []string `json:"refs"`
}

type LinearRebaseOutput

type LinearRebaseOutput struct {
	LinearRebaseResults []*LinearRebaseResult   `json:"linearRebaseResults"`
	LsRefsDebugInfo     *debug.LsRefsDebugInfo  `json:"lsRefsDebugInfo"`
	FetchDebugInfos     []*debug.FetchDebugInfo `json:"fetchDebugInfos"`
	PushDebugInfos      *debug.PushDebugInfo    `json:"pushDebugInfo"`
	Error               string                  `json:"error,omitempty"`
}

func LinearRebase

func LinearRebase(ctx context.Context, client *http.Client, args LinearRebaseArgs) LinearRebaseOutput

type LinearRebaseResult

type LinearRebaseResult struct {
	Ref                   string   `json:"ref"`
	CommitHash            string   `json:"commitHash"`
	ConflictOpenFiles     []string `json:"conflictOpenFiles"`
	ConflictResolvedFiles []string `json:"conflictResolvedFiles"`
	BinaryConflictFiles   []string `json:"binaryConflictFiles"`
	NonFileConflictFiles  []string `json:"nonFileConflictFiles"`
}

type LsRefsArgs

type LsRefsArgs struct {
	RepoURL     string   `json:"repoURL"`
	RefPrefixes []string `json:"refPrefixes"`
}

type LsRefsOutput

type LsRefsOutput struct {
	Refs      []*RefInfo            `json:"refs"`
	DebugInfo debug.LsRefsDebugInfo `json:"debugInfo"`
	Error     string                `json:"error,omitempty"`
}

func LsRefs

func LsRefs(ctx context.Context, client *http.Client, args LsRefsArgs) LsRefsOutput

type ModificationStatus

type ModificationStatus string
const (
	ModificationStatusAdded    ModificationStatus = "ADDED"
	ModificationStatusDeleted  ModificationStatus = "DELETED"
	ModificationStatusModified ModificationStatus = "MODIFIED"
)

type ModifiedFile

type ModifiedFile struct {
	Path    string                               `json:"path"`
	Status  ModificationStatus                   `json:"status"`
	Matches map[string]*ModifiedFilePatternMatch `json:"matches,omitempty"`
}

type ModifiedFilePattern

type ModifiedFilePattern struct {
	// FilePathPattern is a list of doublestar matching patterns for the file paths.
	FilePathPattern []string
	// FileContentPattern is an optional regular expression pattern for the file content.
	FileContentPattern *regexp.Regexp
}

type ModifiedFilePatternMatch

type ModifiedFilePatternMatch struct {
	Before int `json:"before"`
	After  int `json:"after"`
}

type PushSquashCherryPickResult

type PushSquashCherryPickResult struct {
	CommitHash            plumbing.Hash
	CherryPickedFiles     []string
	ConflictOpenFiles     []string
	ConflictResolvedFiles []string
	BinaryConflictFiles   []string
	NonFileConflictFiles  []string
}

type RefInfo

type RefInfo struct {
	// Name is the name of the ref.
	Name string `json:"name"`

	// Hash is the hash of the object that the ref points to.
	//
	// This can be "unborn" if the ref is not created. See man 5 gitprotocol-v2.
	Hash string `json:"hash"`

	// PeeledHash is the hash of the object that the ref points to, if the ref is a tag.
	PeeledHash string `json:"peeledHash,omitempty"`

	// SymbolicTarget is the target of the symbolic ref, if the ref is symbolic.
	SymbolicTarget string `json:"symbolicTarget,omitempty"`
}

type RefUpdateCommand

type RefUpdateCommand struct {
	// RefName is a reference name to update (e.g. "refs/heads/main").
	RefName string `json:"refName"`
	// OldHash is a hash of the reference before the update.
	//
	// There is a difference between zero hash and empty string:
	//
	// * If this is a zero hash, it means that the reference should be newly created (it should
	//   not exist.
	// * If this is an empty string, it means that the reference is updated unconditionally
	//   (force update).
	//
	// Note that, at the git-transport level, everything is a force update. The client should
	// check if the reference being updated is fast-forwardable if they want such behavior.
	OldHash string `json:"oldHash"`
	// NewHash is a hash of the reference after the update.
	NewHash string `json:"newHash"`
}

type SquashCherryPickArgs

type SquashCherryPickArgs struct {
	RepoURL         string `json:"repoURL"`
	CherryPickFrom  string `json:"cherryPickFrom"`
	CherryPickTo    string `json:"cherryPickTo"`
	CherryPickBase  string `json:"cherryPickBase"`
	CommitMessage   string `json:"commitMessage"`
	Author          string `json:"author"`
	AuthorEmail     string `json:"authorEmail"`
	AuthorTime      string `json:"authorTime"`
	Committer       string `json:"committer"`
	CommitterEmail  string `json:"committerEmail"`
	CommitterTime   string `json:"committerTime"`
	Ref             string `json:"ref"`
	ConflictRef     string `json:"conflictRef"`
	CurrentRefHash  string `json:"currentRefHash"`
	AbortOnConflict bool   `json:"abortOnConflict"`
}

type SquashCherryPickOutput

type SquashCherryPickOutput struct {
	CommitHash            string                `json:"commitHash"`
	CherryPickedFiles     []string              `json:"cherryPickedFiles"`
	ConflictOpenFiles     []string              `json:"conflictOpenFiles"`
	ConflictResolvedFiles []string              `json:"conflictResolvedFiles"`
	BinaryConflictFiles   []string              `json:"binaryConflictFiles"`
	NonFileConflictFiles  []string              `json:"nonFileConflictFiles"`
	FetchDebugInfo        debug.FetchDebugInfo  `json:"fetchDebugInfo"`
	BlobFetchDebugInfo    *debug.FetchDebugInfo `json:"blobFetchDebugInfo"`
	PushDebugInfo         *debug.PushDebugInfo  `json:"pushDebugInfo"`
	Error                 string                `json:"error,omitempty"`
}

func SquashCherryPick

func SquashCherryPick(ctx context.Context, client *http.Client, args SquashCherryPickArgs) SquashCherryPickOutput

type SquashCommand

type SquashCommand struct {
	CommitHashStart string `json:"commitHashStart"`
	CommitHashEnd   string `json:"commitHashEnd"`
	CommitMessage   string `json:"commitMessage"`
	Committer       string `json:"committer"`
	CommitterEmail  string `json:"committerEmail"`
	CommitterTime   string `json:"committerTime"`
	Author          string `json:"author"`
	AuthorEmail     string `json:"authorEmail"`
	AuthorTime      string `json:"authorTime"`
}

type SquashCommandResult

type SquashCommandResult struct {
	CommitHash              string   `json:"commitHash"`
	ConflictResolvedFiles   []string `json:"conflictResolvedFiles"`
	ConflictUnresolvedFiles []string `json:"conflictUnresolvedFiles"`
}

type SquashPushArgs

type SquashPushArgs struct {
	RepoURL        string          `json:"repoURL"`
	BaseCommitHash string          `json:"baseCommitHash"`
	SquashCommands []SquashCommand `json:"squashCommands"`
	Ref            string          `json:"ref"`
	CurrentRefHash string          `json:"currentRefHash"`
}

type SquashPushOutput

type SquashPushOutput struct {
	CommandResults  []SquashCommandResult   `json:"commandResults"`
	FetchDebugInfos []*debug.FetchDebugInfo `json:"fetchDebugInfos"`
	PushDebugInfo   *debug.PushDebugInfo    `json:"pushDebugInfo"`
	Error           string                  `json:"error,omitempty"`
}

func SquashPush

func SquashPush(ctx context.Context, client *http.Client, args SquashPushArgs) SquashPushOutput

type UpdateRefsArgs

type UpdateRefsArgs struct {
	RepoURL           string             `json:"repoURL"`
	RefUpdateCommands []RefUpdateCommand `json:"refUpdateCommands"`
}

type UpdateRefsOutput

type UpdateRefsOutput struct {
	PushDebugInfo *debug.PushDebugInfo `json:"pushDebugInfo"`
	Error         string               `json:"error,omitempty"`
}

func UpdateRefs

func UpdateRefs(ctx context.Context, client *http.Client, args UpdateRefsArgs) UpdateRefsOutput

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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