git

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitClient

type GitClient interface {
	// Tag operations (all branch-aware via --merged HEAD)
	GetLatestTag(projectName string) (string, error)
	GetTagsWithPrefix(prefix string) ([]string, error)
	CreateTag(tagName, message string) error
	PushTag(tagName string) error
	TagExists(tagName string) (bool, error)
	GetTagAnnotation(tagName string) (string, error)

	// Repository operations
	IsGitRepo() (bool, error)
	GetCurrentBranch() (string, error)

	// RC tag operations
	ExtractRCNumber(tag string) (int, error)

	// File history operations
	GetFileCreationCommit(filePath string) (string, error)
	GetCommitMessage(commitSHA string) (string, error)

	// Context support for network operations
	WithContext(ctx context.Context) GitClient
}

GitClient provides an abstraction over git operations for testability

IMPORTANT: All tag operations are branch-aware and only return tags that are reachable from the current HEAD (using git's --merged HEAD).

This means:

  • On 'main': returns all tags merged into main
  • On 'canary': only returns tags in canary's ancestry
  • After merge: returns tags from both branches

This branch-awareness is critical for snapshot/RC workflows where different branches may have different sets of published versions.

type MockBranch

type MockBranch struct {
	Name string
	Head string // commit hash this branch points to
}

MockBranch represents a git branch

type MockCommit

type MockCommit struct {
	Hash    string
	Parents []string // parent commit hashes
	Message string
}

MockCommit represents a git commit

type MockGitClient

type MockGitClient struct {

	// Hooks for testing error scenarios
	GetLatestTagError     error
	CreateTagError        error
	PushTagError          error
	TagExistsError        error
	GetTagAnnotationError error
	// contains filtered or unexported fields
}

MockGitClient implements GitClient for testing with full commit graph simulation

func NewMockGitClient

func NewMockGitClient() *MockGitClient

NewMockGitClient creates a new MockGitClient with initial commit and main branch

func (*MockGitClient) AddPushedTag

func (m *MockGitClient) AddPushedTag(projectName, version, message string)

AddPushedTag adds a tag that's already pushed (for test setup) For backward compatibility, creates tag at current HEAD

func (*MockGitClient) AddTag

func (m *MockGitClient) AddTag(projectName, version, message string)

AddTag adds a tag to the mock (for test setup) For backward compatibility, creates tag at current HEAD

func (*MockGitClient) CheckoutBranch

func (m *MockGitClient) CheckoutBranch(name string) error

CheckoutBranch switches to an existing branch

func (*MockGitClient) CreateBranch

func (m *MockGitClient) CreateBranch(name string) error

CreateBranch creates a new branch pointing to current HEAD

func (*MockGitClient) CreateCommit

func (m *MockGitClient) CreateCommit(message string, parents ...string) string

CreateCommit creates a new commit with the given parent(s) If no parents specified, uses current HEAD as parent Returns the commit hash

func (*MockGitClient) CreateTag

func (m *MockGitClient) CreateTag(tagName, message string) error

func (*MockGitClient) ExtractRCNumber

func (m *MockGitClient) ExtractRCNumber(tag string) (int, error)

ExtractRCNumber extracts the RC number from a tag Delegates to the real implementation in os.go

func (*MockGitClient) GetAllTags

func (m *MockGitClient) GetAllTags() map[string]*MockTag

GetAllTags returns all tags (helper for testing)

func (*MockGitClient) GetCommitMessage

func (m *MockGitClient) GetCommitMessage(commitSHA string) (string, error)

GetCommitMessage returns the commit message for a given SHA

func (*MockGitClient) GetCurrentBranch

func (m *MockGitClient) GetCurrentBranch() (string, error)

func (*MockGitClient) GetFileCreationCommit

func (m *MockGitClient) GetFileCreationCommit(filePath string) (string, error)

GetFileCreationCommit returns the commit SHA that added a file Returns empty string if file not tracked

func (*MockGitClient) GetLatestTag

func (m *MockGitClient) GetLatestTag(projectName string) (string, error)

func (*MockGitClient) GetTagAnnotation

func (m *MockGitClient) GetTagAnnotation(tagName string) (string, error)

func (*MockGitClient) GetTagsWithPrefix

func (m *MockGitClient) GetTagsWithPrefix(prefix string) ([]string, error)

GetTagsWithPrefix returns all tags matching the prefix pattern that are reachable from current HEAD (uses git ancestry simulation) Supports wildcard patterns like "backend@v*"

func (*MockGitClient) IsGitRepo

func (m *MockGitClient) IsGitRepo() (bool, error)

func (*MockGitClient) MergeBranch

func (m *MockGitClient) MergeBranch(branchName string) (string, error)

MergeBranch merges a branch into the current branch (creates merge commit)

func (*MockGitClient) PushTag

func (m *MockGitClient) PushTag(tagName string) error

func (*MockGitClient) Reset

func (m *MockGitClient) Reset()

Reset clears all data from the mock and reinitializes with fresh commit graph (helper for testing)

func (*MockGitClient) SetBranch

func (m *MockGitClient) SetBranch(branch string)

SetBranch sets the current branch name

func (*MockGitClient) SetFileCreationCommit

func (m *MockGitClient) SetFileCreationCommit(filePath, commitSHA string)

SetFileCreationCommit tracks when a file was created (for testing)

func (*MockGitClient) SetIsRepo

func (m *MockGitClient) SetIsRepo(isRepo bool)

SetIsRepo sets whether this is a git repository

func (*MockGitClient) TagExists

func (m *MockGitClient) TagExists(tagName string) (bool, error)

func (*MockGitClient) WithContext

func (m *MockGitClient) WithContext(ctx context.Context) GitClient

WithContext returns a new client with the given context

type MockTag

type MockTag struct {
	Name       string
	Message    string
	IsPushed   bool
	ProjectTag string // e.g., "auth@v1.2.3"
	CommitHash string // NEW: which commit this tag points to
}

MockTag represents a git tag

type OSGitClient

type OSGitClient struct {
	// contains filtered or unexported fields
}

OSGitClient implements GitClient using real git commands

func NewOSGitClient

func NewOSGitClient() *OSGitClient

NewOSGitClient creates a new OSGitClient

func (*OSGitClient) CreateTag

func (g *OSGitClient) CreateTag(tagName, message string) error

CreateTag creates an annotated tag

func (*OSGitClient) ExtractRCNumber

func (g *OSGitClient) ExtractRCNumber(tag string) (int, error)

ExtractRCNumber extracts the RC number from a tag Examples:

  • "backend@v1.3.0-rc5" -> 5, nil
  • "backend@v1.3.0" -> -1, nil (not an RC)
  • "backend@v1.3.0-rc" -> -1, error

func (*OSGitClient) GetCommitMessage

func (g *OSGitClient) GetCommitMessage(commitSHA string) (string, error)

GetCommitMessage returns the commit message for a given SHA

func (*OSGitClient) GetCurrentBranch

func (g *OSGitClient) GetCurrentBranch() (string, error)

GetCurrentBranch returns the current git branch name

func (*OSGitClient) GetFileCreationCommit

func (g *OSGitClient) GetFileCreationCommit(filePath string) (string, error)

GetFileCreationCommit returns the commit SHA that added a file Returns empty string if file doesn't exist in git history

func (*OSGitClient) GetLatestTag

func (g *OSGitClient) GetLatestTag(projectName string) (string, error)

GetLatestTag returns the latest tag for a project on the current branch Tags are expected to be in the format: {projectName}@v{version}

func (*OSGitClient) GetTagAnnotation

func (g *OSGitClient) GetTagAnnotation(tagName string) (string, error)

GetTagAnnotation returns the annotation message of a tag

func (*OSGitClient) GetTagsWithPrefix

func (g *OSGitClient) GetTagsWithPrefix(prefix string) ([]string, error)

GetTagsWithPrefix returns all tags matching the prefix that are reachable from HEAD Uses --merged HEAD to ensure only tags in current branch's ancestry are returned

func (*OSGitClient) IsGitRepo

func (g *OSGitClient) IsGitRepo() (bool, error)

IsGitRepo checks if the current directory is a git repository

func (*OSGitClient) PushTag

func (g *OSGitClient) PushTag(tagName string) error

PushTag pushes a tag to the remote

func (*OSGitClient) TagExists

func (g *OSGitClient) TagExists(tagName string) (bool, error)

TagExists checks if a tag exists locally

func (*OSGitClient) WithContext

func (g *OSGitClient) WithContext(ctx context.Context) GitClient

WithContext returns a new client with the given context

Jump to

Keyboard shortcuts

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