Documentation
¶
Overview ¶
Package git provides operations for managing Git repositories.
The EnvironmentOperations struct provides methods for interacting with a particular clone of a repository. It ensures there is a separate clone for each environment to avoid concurrency issues.
When implementing operations that do not require an environment-specific clone, create a static function that accepts the GitOperationsProvider and the GitRepository as parameters. This avoids the need to manage state to avoid concurrency issues. See LsRemote for an example of such a function.
Index ¶
- func AddTrailerToCommitMessage(ctx context.Context, commitMessage, trailerKey, trailerValue string) (string, error)
- func LsRemote(ctx context.Context, gap scms.GitOperationsProvider, ...) (map[string]string, error)
- type BranchShas
- type EnvironmentOperations
- func (g *EnvironmentOperations) CloneRepo(ctx context.Context) error
- func (g *EnvironmentOperations) GetBranchShas(ctx context.Context, branch string) (BranchShas, error)
- func (g *EnvironmentOperations) GetRevListFirstParent(ctx context.Context, branch string, maxCount int) ([]string, error)
- func (g *EnvironmentOperations) GetShaAuthor(ctx context.Context, sha string) (string, error)
- func (g *EnvironmentOperations) GetShaBody(ctx context.Context, sha string) (string, error)
- func (g *EnvironmentOperations) GetShaMetadataFromFile(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)
- func (g *EnvironmentOperations) GetShaMetadataFromGit(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)
- func (g *EnvironmentOperations) GetShaSubject(ctx context.Context, sha string) (string, error)
- func (g *EnvironmentOperations) GetShaTime(ctx context.Context, sha string) (v1.Time, error)
- func (g *EnvironmentOperations) GetTrailers(ctx context.Context, sha string) (map[string]string, error)
- func (g *EnvironmentOperations) HasConflict(ctx context.Context, proposedBranch, activeBranch string) (bool, error)
- func (g *EnvironmentOperations) IsPullRequestRequired(ctx context.Context, environmentNextBranch, environmentBranch string) (bool, error)
- func (g *EnvironmentOperations) MergeWithOursStrategy(ctx context.Context, proposedBranch, activeBranch string) error
- func (g *EnvironmentOperations) PromoteEnvironmentWithMerge(ctx context.Context, environmentBranch, environmentNextBranch string) error
- type HydratorMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTrailerToCommitMessage ¶ added in v0.15.0
func AddTrailerToCommitMessage(ctx context.Context, commitMessage, trailerKey, trailerValue string) (string, error)
AddTrailerToCommitMessage adds a trailer to a commit message using git interpret-trailers. This ensures we follow Git's exact trailer conventions and formatting rules. The trailer will be appended at the end of the trailer block.
Note: We use git interpret-trailers instead of manually parsing/formatting trailers to ensure we follow Git's exact trailer conventions and formatting rules. While git interpret-trailers doesn't provide a way to place one trailer directly after another specific trailer (the --where flag only accepts general positions like 'after', 'before', 'start', 'end' relative to ALL trailers, not a specific one), it's still the most reliable approach. The alternative would be maintaining complex custom parsing logic, which is error-prone and doesn't handle all of Git's trailer edge cases.
Types ¶
type BranchShas ¶
type BranchShas struct {
// Dry is the SHA of the commit that was used as the dry source for hydration.
Dry string
// Hydrated is the SHA of the commit on the hydrated branch.
Hydrated string
}
BranchShas holds the hydrated and dry commit SHAs for a branch.
type EnvironmentOperations ¶ added in v0.8.0
type EnvironmentOperations struct {
// contains filtered or unexported fields
}
EnvironmentOperations provides methods for interacting with a specific clone of a Git repository for an environment.
func NewEnvironmentOperations ¶ added in v0.8.0
func NewEnvironmentOperations(gitRepo *v1alpha1.GitRepository, gap scms.GitOperationsProvider, activeBranch string) *EnvironmentOperations
NewEnvironmentOperations creates a new EnvironmentOperations instance. The activeBranch parameter is used to differentiate between different environments that might use the same GitRepository and avoid conflicts between concurrent operations.
func (*EnvironmentOperations) CloneRepo ¶ added in v0.8.0
func (g *EnvironmentOperations) CloneRepo(ctx context.Context) error
CloneRepo clones the gitRepo to a temporary directory if needed. Does nothing if the repo is already cloned.
func (*EnvironmentOperations) GetBranchShas ¶ added in v0.8.0
func (g *EnvironmentOperations) GetBranchShas(ctx context.Context, branch string) (BranchShas, error)
GetBranchShas checks out the given branch, pulls the latest changes, and returns the hydrated and dry SHAs.
func (*EnvironmentOperations) GetRevListFirstParent ¶ added in v0.11.0
func (g *EnvironmentOperations) GetRevListFirstParent(ctx context.Context, branch string, maxCount int) ([]string, error)
GetRevListFirstParent retrieves the first parent commit SHAs for the given branch using git rev-list.
func (*EnvironmentOperations) GetShaAuthor ¶ added in v0.8.0
GetShaAuthor retrieves the author of a commit given its SHA.
func (*EnvironmentOperations) GetShaBody ¶ added in v0.8.0
GetShaBody retrieves the body of a commit given its SHA.
func (*EnvironmentOperations) GetShaMetadataFromFile ¶ added in v0.8.0
func (g *EnvironmentOperations) GetShaMetadataFromFile(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)
GetShaMetadataFromFile retrieves commit metadata from the hydrator.metadata file for a given SHA.
func (*EnvironmentOperations) GetShaMetadataFromGit ¶ added in v0.8.0
func (g *EnvironmentOperations) GetShaMetadataFromGit(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)
GetShaMetadataFromGit retrieves commit metadata by running git commands for a given SHA.
func (*EnvironmentOperations) GetShaSubject ¶ added in v0.8.0
GetShaSubject retrieves the subject of a commit given its SHA.
func (*EnvironmentOperations) GetShaTime ¶ added in v0.8.0
GetShaTime retrieves the commit time of a commit given its SHA.
func (*EnvironmentOperations) GetTrailers ¶ added in v0.11.0
func (g *EnvironmentOperations) GetTrailers(ctx context.Context, sha string) (map[string]string, error)
GetTrailers retrieves the trailers from the last commit in the repository using git interpret-trailers.
func (*EnvironmentOperations) HasConflict ¶ added in v0.8.0
func (g *EnvironmentOperations) HasConflict(ctx context.Context, proposedBranch, activeBranch string) (bool, error)
HasConflict checks if there is a merge conflict between the proposed branch and the active branch using git merge-tree. This performs a stateless merge check without modifying the working directory. It assumes that origin/<branch> is currently fetched and updated in the local repository. This should happen via GetBranchShas function earlier in the reconcile.
func (*EnvironmentOperations) IsPullRequestRequired ¶ added in v0.8.0
func (g *EnvironmentOperations) IsPullRequestRequired(ctx context.Context, environmentNextBranch, environmentBranch string) (bool, error)
IsPullRequestRequired will compare the environment branch with the next environment branch and return true if a PR is required. The PR is required if the diff between the two branches contain edits to yaml files. This assumes that both branches have already been fetched via GetBranchShas earlier in the reconciliation, ensuring we check the same refs that were used for conflict detection.
func (*EnvironmentOperations) MergeWithOursStrategy ¶ added in v0.8.0
func (g *EnvironmentOperations) MergeWithOursStrategy(ctx context.Context, proposedBranch, activeBranch string) error
MergeWithOursStrategy merges the proposed branch into the active branch using the "ours" strategy. This assumes that both branches have already been fetched via GetBranchShas earlier in the reconciliation, ensuring we merge the exact same refs that were checked for conflicts.
func (*EnvironmentOperations) PromoteEnvironmentWithMerge ¶ added in v0.8.0
func (g *EnvironmentOperations) PromoteEnvironmentWithMerge(ctx context.Context, environmentBranch, environmentNextBranch string) error
PromoteEnvironmentWithMerge merges the next environment branch into the current environment branch and pushes the result. This assumes that both branches have already been fetched via GetBranchShas earlier in the reconciliation, ensuring we merge the exact same refs that were checked for PR requirements.
type HydratorMetadata ¶ added in v0.6.0
type HydratorMetadata struct {
// RepoURL is the URL of the repository where the commit is located.
RepoURL string `json:"repoURL,omitempty"`
// DrySha is the SHA of the commit that was used as the dry source for hydration.
DrySha string `json:"drySha,omitempty"`
// Author is the author of the dry commit that was used to hydrate the branch.
Author string `json:"author,omitempty"`
// Date is the date of the dry commit that was used to hydrate the branch.
Date v1.Time `json:"date,omitempty"`
// Subject is the subject line of the dry commit that was used to hydrate the branch.
Subject string `json:"subject,omitempty"`
// Body is the body of the dry commit that was used to hydrate the branch without the subject.
Body string `json:"body,omitempty"`
// References are the references to other commits, that went into the hydration of the branch.
References []v1alpha1.RevisionReference `json:"references,omitempty"`
}
HydratorMetadata contains metadata about the commit that is used to hydrate a branch.