git

package
v0.1.23-oss Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sha1Len              = 20 // Length in bytes
	CacheTreeFillerBytes = 3  // 1 for NUL, 1 for space, and 1 for newline
	ExtensionHeaderSize  = 8
)

Variables

View Source
var (
	IndexDircHeader = [4]byte{'D', 'I', 'R', 'C'}
	IndexTreeHeader = [4]byte{'T', 'R', 'E', 'E'}
)

Functions

This section is empty.

Types

type CacheTreeEntry

type CacheTreeEntry struct {
	// Path relative to parent directory.
	Path string `json:"path"`

	// ASCII decimal number of index entries recursively present beneath this node.
	EntryCount string `json:"entry_count"`

	// ASCII decimal number of trees directly beneath this node.
	SubtreeCount string `json:"subtree_count"`

	Sha1 IndexSha1 `json:"sha1"`
}

func (*CacheTreeEntry) Entries

func (e *CacheTreeEntry) Entries() int

func (*CacheTreeEntry) Read

func (c *CacheTreeEntry) Read(r io.Reader) error

func (*CacheTreeEntry) Subtrees

func (e *CacheTreeEntry) Subtrees() int

func (*CacheTreeEntry) Write

func (e *CacheTreeEntry) Write(w io.Writer) error

type ExtensionHeader

type ExtensionHeader struct {
	Signature IndexSignature
	// Size of the entries data in bytes.
	Size uint32
}

type FetchedRef

type FetchedRef struct {
	// we can parse the flag into a type if we need to use it
	StatusFlag     string
	OldObjectId    plumbing.Hash
	NewObjectId    plumbing.Hash
	LocalReference string
}

type Index

type Index struct {
	Header           IndexHeader       `json:"header"`
	IndexEntries     []IndexEntry      `json:"entries"`
	CacheTreeEntries []*CacheTreeEntry `json:"trees"`
	CacheTreeSize    uint32
}

func NewIndex

func NewIndex(version uint32) *Index

func (*Index) AddEntry

func (index *Index) AddEntry(name string, data IndexEntryData)

func (*Index) CreateCacheTreeEntry

func (index *Index) CreateCacheTreeEntry(path string, sha1 [Sha1Len]byte) *CacheTreeEntry

Create a cache tree entry and add to the index

func (*Index) NumEntries

func (index *Index) NumEntries() int

func (*Index) Read

func (index *Index) Read(r io.Reader, totalSize int64) error

func (*Index) UpdateTree

func (index *Index) UpdateTree(cacheTreeEntry *CacheTreeEntry, numEntries, numSubtrees int)

func (*Index) Write

func (index *Index) Write(w io.Writer) error

type IndexEntry

type IndexEntry struct {
	IndexEntryData
	Name    string `json:"name"`
	Padding int
}

func (*IndexEntry) Write

func (e *IndexEntry) Write(w io.Writer) error

type IndexEntryData

type IndexEntryData struct {
	CtimeSeconds uint32    `json:"ctime_secs"`
	CtimeMillis  uint32    `json:"ctime_ms"`
	MtimeSeconds uint32    `json:"mtime_secs"`
	MtimeMillis  uint32    `json:"mtime_ms"`
	Dev          uint32    `json:"dev"`
	Ino          uint32    `json:"ino"`
	Mode         uint32    `json:"mode"`
	Uid          uint32    `json:"uid"`
	Gid          uint32    `json:"gid"`
	FileSize     uint32    `json:"filesize"`
	SHA1         IndexSha1 `json:"sha1"`
	Flags        uint16    `json:"flags"`
}

type IndexHeader

type IndexHeader struct {
	Signature    IndexSignature `json:"signature"`
	Version      uint32         `json:"version"`
	EntriesCount uint32         `json:"entry_count"`
}

type IndexSha1

type IndexSha1 [Sha1Len]byte

func (*IndexSha1) MarshalJSON

func (i *IndexSha1) MarshalJSON() ([]byte, error)

func (*IndexSha1) String

func (i *IndexSha1) String() string

type IndexSignature

type IndexSignature [4]byte

func (*IndexSignature) MarshalJSON

func (i *IndexSignature) MarshalJSON() ([]byte, error)

func (*IndexSignature) String

func (i *IndexSignature) String() string

type ObjectTypeName

type ObjectTypeName struct {
	ObjType plumbing.ObjectType
	Name    entities.Hash
}

type ObjectTypeNameStreamItem

type ObjectTypeNameStreamItem struct {
	*ObjectTypeName
	Err error
}

type RevListObjects

type RevListObjects struct {
	Blobs   []entities.Hash
	Objects []entities.Hash
}

RevListObjects just clarifies blobs vs. objects slices

type ShellGit

type ShellGit struct {
	BinPath string
}

func NewShellGit

func NewShellGit(binPath string) *ShellGit

func (*ShellGit) AddConfig

func (s *ShellGit) AddConfig(repoPath string, key, value string) error

func (*ShellGit) AddFetchRefSpec

func (s *ShellGit) AddFetchRefSpec(repoPath, remoteName, refSpec string) error

AddFetchRefSpec is useful to use with negative refspecs since go-git doesn't support them. https://github.com/go-git/go-git/issues/538.

func (*ShellGit) AddRemote

func (s *ShellGit) AddRemote(repoPath, remoteName, url string) error

AddRemote is here because go-git doesn't support negative refspecs and will fail to add a remote if the config already contains them.

func (*ShellGit) AllCommitsDates

func (s *ShellGit) AllCommitsDates(repoPath string) (hashes []entities.Hash, dates []time.Time, returnErr error)

func (*ShellGit) AllObjects

func (s *ShellGit) AllObjects(repoPath string) (objects []entities.Hash, returnErr error)

func (*ShellGit) Checkout

func (s *ShellGit) Checkout(repoPath string, ref string) error

func (*ShellGit) CheckoutNewBranch

func (s *ShellGit) CheckoutNewBranch(repoPath, branch, tracking string) error

func (*ShellGit) CommitTreeHashes

func (s *ShellGit) CommitTreeHashes(repoPath string, commits []entities.Hash) ([]entities.Hash, error)

func (*ShellGit) CommitsFileObjects

func (s *ShellGit) CommitsFileObjects(repoPath string, commits []entities.Hash) (hashes []entities.Hash, returnErr error)

func (*ShellGit) CurrentBranch

func (s *ShellGit) CurrentBranch(repoPath string) (branch, remote string, err error)

func (*ShellGit) Fetch

func (s *ShellGit) Fetch(repoPath string) error

Fetch shells out to `git fetch` because it can be significantly faster than go-git's Fetch for large network downloads.

func (*ShellGit) FetchAndGetUpdatedRefs

func (s *ShellGit) FetchAndGetUpdatedRefs(repoPath string) ([]*FetchedRef, error)

FetchAndGetUpdatedRefs returns the refs that were updated by parsing `git fetch --porcelain` output

func (*ShellGit) FetchRef

func (s *ShellGit) FetchRef(repoPath string, remote string, ref string) error

func (*ShellGit) GetAllConfigs

func (s *ShellGit) GetAllConfigs(repoPath, key string) ([]string, error)

func (*ShellGit) GetConfig

func (s *ShellGit) GetConfig(repoPath string, key, defValue string) (string, error)

func (*ShellGit) GetObjCount

func (s *ShellGit) GetObjCount(repoPath, rev string, excludes []entities.Hash) (int64, error)

GetObjCount returns the number of objects reachable from rev but unreachable from the exclude set.

func (*ShellGit) GetRemotes

func (s *ShellGit) GetRemotes(repoPath string) ([]string, error)

GetRemotes is useful when a negative refspec is used in a remote. go-git doesn't support negative refspecs so it fails to parse remotes using them.

func (*ShellGit) GitCloneBareWithWorktree

func (s *ShellGit) GitCloneBareWithWorktree(ctx context.Context, gitDir, workTree, targetURL, remoteName, ref string) error

GitCloneBareWithWorktree initializes a bare git repository at gitDir configured for workTree, fetches the specified ref from targetURL, and checks out a detached HEAD into workTree.

func (*ShellGit) GitCloneBranchAt

func (s *ShellGit) GitCloneBranchAt(ctx context.Context, repoPath, targetURL, branch string) error

func (*ShellGit) GitCloneCommitAt

func (s *ShellGit) GitCloneCommitAt(repoPath, targetURL, remoteName, ref string) error

GitCloneCommitAt clones a specific commit/tag/branch from a remote repository into the given path.

func (*ShellGit) HasUncommitedChanges

func (s *ShellGit) HasUncommitedChanges(repoPath string) (bool, error)

func (*ShellGit) InstallLFSHooks

func (s *ShellGit) InstallLFSHooks(repoPath string) error

func (*ShellGit) LFSEnabled

func (s *ShellGit) LFSEnabled() bool

func (*ShellGit) LFSFetch

func (s *ShellGit) LFSFetch(repoPath string) error

func (*ShellGit) LFSFiles

func (s *ShellGit) LFSFiles(repoPath string) (map[string][]string, error)

LFS files at HEAD.

func (*ShellGit) LFSFilesAll

func (s *ShellGit) LFSFilesAll(repoPath string) (map[string][]string, error)

LFS files for the entire history.

func (*ShellGit) ListSymRefs

func (s *ShellGit) ListSymRefs(remote string) ([]string, []string, error)

func (*ShellGit) ListTreeRec

func (s *ShellGit) ListTreeRec(repoPath, ref string) ([]entities.DeepEntry, error)

func (*ShellGit) ObjectTypes

func (s *ShellGit) ObjectTypes(repoPath string, objects []entities.Hash) (types []string, returnErr error)

func (*ShellGit) ObjectsInTree

func (s *ShellGit) ObjectsInTree(repoPath, ref string) ([]*ObjectTypeName, error)

func (*ShellGit) PackObjects

func (s *ShellGit) PackObjects(repoPath string, prefix string, objects []entities.Hash) (string, error)

func (*ShellGit) Rebase

func (s *ShellGit) Rebase(repoPath string, onto string) error

func (*ShellGit) RebaseOnto

func (s *ShellGit) RebaseOnto(repoPath string, newbase, oldbase, tip string) error

func (*ShellGit) RemoveRemote

func (s *ShellGit) RemoveRemote(repoPath, remoteName string) error

func (*ShellGit) RenameRemote

func (s *ShellGit) RenameRemote(repoPath, old, new string) error

func (*ShellGit) ResetSoft

func (s *ShellGit) ResetSoft(repoPath string, target string) error

func (*ShellGit) RevListAll

func (s *ShellGit) RevListAll(repoPath string) ([]entities.Hash, error)

func (*ShellGit) RevListObjects

func (s *ShellGit) RevListObjects(repoPath string, includedCommits, excludedCommits []entities.Hash) (*RevListObjects, error)

RevListObjects utilizes `git rev-list --objects` to find all objects that are descendants of the provided `includedCommits`, but are not descendants of the provided `excludedCommits`. This effectively provides all new objects between commits.

func (*ShellGit) RevListObjectsTopoOrder

func (s *ShellGit) RevListObjectsTopoOrder(repoPath, rev string, excludes []entities.Hash) (<-chan ObjectTypeNameStreamItem, error)

RevListObjectsTopoOrder traverses the object tree from `rev` and provides output with the following characteristics:

  • commit objects are output in reverse topological order. Parent commits will be before children commits.
  • tree and blob objects immediately following a commit are output in DFS order.
  • The output is a partial tree. Tree and blob objects that are present in multiple trees are only shown once, which is at first node traversal in DFS. They will not be shown if they are reachable from an excluded commit.
  • It is not guaranteed that observed objects from `cat-file` or `ls-tree` will appear at all expected nodes in the tree.

func (*ShellGit) RevListReverse

func (s *ShellGit) RevListReverse(repoPath, from, to string) ([]string, error)

func (*ShellGit) RevParse

func (s *ShellGit) RevParse(repoPath string, ref string) (string, error)

func (*ShellGit) SetSymbolicRef

func (s *ShellGit) SetSymbolicRef(repoPath, name, ref string) error

func (*ShellGit) ShowRefs

func (s *ShellGit) ShowRefs(repoPath string) (map[string]entities.Hash, error)

func (*ShellGit) StashPop

func (s *ShellGit) StashPop(repoPath string) error

func (*ShellGit) StashPush

func (s *ShellGit) StashPush(repoPath string) error

func (*ShellGit) SymRef

func (s *ShellGit) SymRef(repoPath string, ref string) (string, error)

func (*ShellGit) SymbolicRef

func (s *ShellGit) SymbolicRef(repoPath string, ref string, short bool) (string, error)

func (*ShellGit) TryRemoveRemote

func (s *ShellGit) TryRemoveRemote(repoPath, remoteName string) error

func (*ShellGit) UnsetUpstream

func (s *ShellGit) UnsetUpstream(repoPath string, branch string) error

func (*ShellGit) UpdateIndex

func (s *ShellGit) UpdateIndex(repoPath, file string) error

func (*ShellGit) UpdateRef

func (s *ShellGit) UpdateRef(repoPath, refName, commitHash string) error

Jump to

Keyboard shortcuts

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