config package - github.com/rockholla/gitspork/v2/internal/config - Go Packages

config

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GitSpork                  string = "gitspork"
	GitSSHUsername            string = "git"
	GitSporkConfigFileName    string = ".gitspork.yml"
	GitSporkConfigFileNameAlt string = ".gitspork.yaml"
	GitSporkMarkerSeparator   string = "::"

	// TemplatedMergeStructuredPreferUpstream / TemplatedMergeStructuredPreferDownstream
	// are the valid values for GitSporkConfigTemplatedMerged.Structured.
	TemplatedMergeStructuredPreferUpstream   = "prefer-upstream"
	TemplatedMergeStructuredPreferDownstream = "prefer-downstream"
)

Variables

Functions

func FindGitSporkConfig

func FindGitSporkConfig(startDir string) (string, error)

FindGitSporkConfig walks up from startDir to find .gitspork.yml (or .gitspork.yaml) and returns its path.

func GetGitSporkConfigSchema

func GetGitSporkConfigSchema() (string, string, error)

GetGitSporkConfigSchema will render a version of the .gitspork.yml config w/ comments as a schema-like documentation source

func Init

func Init(initPath string, logger sdktypes.Logger) error

Init will initialize a path for use as a gitspork upstream

func NormalizeUpstreamPath

func NormalizeUpstreamPath(p string) string

NormalizeUpstreamPath returns a canonical, forward-slash logical path for user-supplied inputs like mv/rm arguments and UpstreamSpec.Subpath values.

It leans on path.Clean to collapse "//" segments, resolve "." and ".." segments, and strip trailing slashes — all of which shell tab-completion, autocomplete, or human error routinely produce. It also normalizes a leading slash away (git tree entries and .gitspork.yml patterns never carry one) and maps the "no path" input to the empty string rather than path.Clean's "." sentinel, so callers can special-case the root/no-subpath case naturally.

Examples:

""              -> ""
"/"             -> ""
"docs/foo"      -> "docs/foo"
"docs/foo/"     -> "docs/foo"
"/docs/foo"     -> "docs/foo"
"./docs/foo"    -> "docs/foo"
"docs//foo"     -> "docs/foo"
"docs/./foo"    -> "docs/foo"
"docs/bar/../foo" -> "docs/foo"

func UpstreamMv

func UpstreamMv(configPath, oldPath, newPath string) ([]string, error)

UpstreamMv updates the config at configPath to reflect a file/directory move from oldPath to newPath. It rewrites exact path entries, glob patterns whose non-wildcard prefix matches the old path, and emits warnings for patterns it can't automatically handle.

func UpstreamRm

func UpstreamRm(configPath, path string, recursive bool) ([]string, error)

UpstreamRm updates .gitspork.yml at configPath to remove entries matching path. If recursive is true, also removes entries whose non-wildcard prefix falls under path.

func WriteGitSporkConfig

func WriteGitSporkConfig(configPath string, config *GitSporkConfig, header ...string) error

WriteGitSporkConfig writes config to configPath, prepending header if non-empty. User-written YAML comments captured during ParseGitSporkConfig are re-injected automatically.

Types

type GitSporkConfig

type GitSporkConfig struct {
	UpstreamOwned   []OwnedEntry                  `` /* 195-byte string literal not displayed */
	UpstreamOnly    []string                      `` /* 269-byte string literal not displayed */
	DownstreamOwned []OwnedEntry                  `` /* 224-byte string literal not displayed */
	SharedOwnership GitSporkConfigSharedOwnership `` /* 161-byte string literal not displayed */
	Templated       []GitSporkConfigTemplated     `` /* 157-byte string literal not displayed */
	Migrations      []string                      `` /* 183-byte string literal not displayed */
	// contains filtered or unexported fields
}

GitSporkConfig represents the config an upstream repo defines in .gitspork.yml

func ComputeUpstreamMv

func ComputeUpstreamMv(configPath, oldPath, newPath string) (*GitSporkConfig, []string, error)

ComputeUpstreamMv returns the rewritten config and any warnings for a move from oldPath to newPath, without writing to disk. Use WriteGitSporkConfig to persist the result.

func ComputeUpstreamMvFromConfig

func ComputeUpstreamMvFromConfig(config *GitSporkConfig, oldPath, newPath string) (*GitSporkConfig, []string, error)

ComputeUpstreamMvFromConfig applies a move rewrite to an already-parsed config. Used to chain multiple source rewrites without re-reading the file between each.

func ComputeUpstreamRm

func ComputeUpstreamRm(configPath, path string, recursive bool) (*GitSporkConfig, []string, error)

ComputeUpstreamRm returns the rewritten config and any warnings for a removal of path, without writing to disk. Use WriteGitSporkConfig to persist the result.

func ComputeUpstreamRmFromConfig

func ComputeUpstreamRmFromConfig(config *GitSporkConfig, path string, recursive bool) (*GitSporkConfig, []string, error)

ComputeUpstreamRmFromConfig applies a removal to an already-parsed config. Used to chain multiple path removals without re-reading the file between each.

func ParseGitSporkConfig

func ParseGitSporkConfig(gitSporkConfigFilePath string) (*GitSporkConfig, error)

ParseGitSporkConfig will parse a .gitspork.yml config file at the provided path

type GitSporkConfigMigration

type GitSporkConfigMigration struct {
	PreIntegrate  *GitSporkConfigMigrationInstructions `yaml:"pre_integrate,omitempty"`
	PostIntegrate *GitSporkConfigMigrationInstructions `yaml:"post_integrate,omitempty"`
}

GitSporkConfigMigration represents config for a single downstream repo migration

func ParseMigrationConfig

func ParseMigrationConfig(migrationConfigPath string) (*GitSporkConfigMigration, error)

ParseMigrationConfig will read a migration config YAML file, parse its instruction and return the parsed data

type GitSporkConfigMigrationInstructions

type GitSporkConfigMigrationInstructions struct {
	ID   string `yaml:"-"`
	Exec string `` /* 177-byte string literal not displayed */
}

GitSporkConfigMigrationInstruction provides specific instructions for a migration operation/set of operations

type GitSporkConfigSharedOwnership

type GitSporkConfigSharedOwnership struct {
	Merged     []string                                `` /* 219-byte string literal not displayed */
	Structured GitSporkConfigSharedOwnershipStructured `` /* 192-byte string literal not displayed */
}

GitSporkConfigSharedOwnership represents config for what files will have shared ownership

type GitSporkConfigSharedOwnershipStructured

type GitSporkConfigSharedOwnershipStructured struct {
	PreferUpstream   []string `` /* 170-byte string literal not displayed */
	PreferDownstream []string `` /* 174-byte string literal not displayed */
}

GitSporkConfigSharedOwnershipStructured represents config for what files will have shared ownership of structured data in yaml or json format

type GitSporkConfigTemplated

type GitSporkConfigTemplated struct {
	Template        string                         `yaml:"template" comment:"source path of the Go template file to use in the upstream"`
	Destination     string                         `yaml:"destination" comment:"destination path and file name in the dowstream where the template will be rendered"`
	DownstreamOwned bool                           `` /* 208-byte string literal not displayed */
	Inputs          []GitSporkConfigTemplatedInput `yaml:"inputs" comment:"list of inputs to provide to the template, and how to determine them"`
	Merged          *GitSporkConfigTemplatedMerged `` /* 133-byte string literal not displayed */
}

GitSporkConfigTemplated is a single templated/render template instruction from upstream -> downstream

type GitSporkConfigTemplatedInput

type GitSporkConfigTemplatedInput struct {
	Name                      string                                             `yaml:"name" comment:"name of the input as defined in the template like 'index .Inputs \"[name]\"'"`
	Prompt                    string                                             `` /* 126-byte string literal not displayed */
	PromptDefault             *GitSporkConfigTemplatedPromptDefault              `` /* 148-byte string literal not displayed */
	ExpectSeeded              bool                                               `` /* 219-byte string literal not displayed */
	JSONDataPath              string                                             `` /* 262-byte string literal not displayed */
	PreviousInput             *GitSporkConfigTemplatedInputPrevious              `` /* 168-byte string literal not displayed */
	FromDestinationStructured *GitSporkConfigTemplatedInputDestinationStructured `` /* 368-byte string literal not displayed */
}

GitSporkConfigTemplatedInput is instruction for dynamically input data to templates to render from upstream -> downstream

type GitSporkConfigTemplatedInputDestinationStructured added in v2.2.10

type GitSporkConfigTemplatedInputDestinationStructured struct {
	Path string `` /* 159-byte string literal not displayed */
}

GitSporkConfigTemplatedInputDestinationStructured allows for re-using an already-rendered destination template's value, assuming the destination type is structured data, as the value to use as input

type GitSporkConfigTemplatedInputPrevious

type GitSporkConfigTemplatedInputPrevious struct {
	Template string `yaml:"template" comment:"Name of a previous template defined in the gitspork config from which to pull the value"`
	Name     string `yaml:"name" comment:"Name of the input from that template from which to pull the value"`
}

GitSporkConfigTemplatedInputPrevious allows for GitSporkConfigTemplatedInput to use a value that's already been captured in a previous template instruction as the input value

type GitSporkConfigTemplatedMerged

type GitSporkConfigTemplatedMerged struct {
	Structured string `yaml:"structured" comment:"instruction for a structured merged post-render, either 'prefer-upstream' or 'prefer-downstream'"`
}

GitSporkConfigTemplatedMerged

type GitSporkConfigTemplatedPromptDefault added in v2.3.0

type GitSporkConfigTemplatedPromptDefault struct {
	FromSeeded string `` /* 190-byte string literal not displayed */
	Value      string `yaml:"value,omitempty" comment:"static value to use as the default value should the user not provide input to the prompt"`
}

GitSporkConfigTemplatedPromptDefault is instruction on how to fill in a default value for a prompt should the user not provide input

type OwnedEntry

type OwnedEntry struct {
	Pattern string `yaml:"pattern,omitempty" comment:"a single glob file pattern"`
	From    string `yaml:"from,omitempty" comment:"(rename) upstream source glob/path"`
	To      string `yaml:"to,omitempty" comment:"(rename) downstream destination glob/path"`
}

OwnedEntry is a single entry in an ownership list (upstream_owned or downstream_owned). It is either a plain glob pattern (Pattern, from a YAML scalar) or a rename (From/To, from a {from, to} YAML map). The forms are mutually exclusive. The type is ownership-neutral: it describes a path/rename, not a policy — the difference between the two lists lives in their integrators.

The yaml/comment struct tags are consumed ONLY by the reflection-based marshal.YAMLWithComments schema renderer. goccy uses the custom UnmarshalYAML/MarshalYAML below, which ignore tags.

func (OwnedEntry) IsRename

func (e OwnedEntry) IsRename() bool

IsRename reports whether the entry renames a file (From/To form).

func (OwnedEntry) MarshalYAML

func (e OwnedEntry) MarshalYAML() ([]byte, error)

MarshalYAML emits a scalar for plain entries and a {from, to} map for renames.

func (OwnedEntry) ResolveDest

func (e OwnedEntry) ResolveDest(matchedFile string) string

ResolveDest returns the downstream destination path for an upstream file that matched this entry's SourcePattern. Plain entries map to the same path; rename entries swap the source pattern's non-wildcard prefix for the destination's, preserving the remainder (prefix substitution).

func (OwnedEntry) SourcePattern

func (e OwnedEntry) SourcePattern() string

SourcePattern returns the glob matched against the upstream tree.

func (*OwnedEntry) UnmarshalYAML

func (e *OwnedEntry) UnmarshalYAML(b []byte) error

UnmarshalYAML accepts either a scalar (plain pattern) or a {from, to} map.

func (OwnedEntry) Validate

func (e OwnedEntry) Validate() error

Validate reports a configuration error if the entry is malformed: a rename must set both From and To, and the two sides must agree on whether they are globs (both contain a wildcard or neither does). An asymmetric rename — a glob source with a scalar destination, or vice versa — silently produces malformed destination paths in ResolveDest, so it is rejected at parse time instead.

Jump to

Keyboard shortcuts

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