merge

package
v1.224.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasConflictMarkers

func HasConflictMarkers(content string) bool

HasConflictMarkers checks if the content contains diff3 conflict markers.

Types

type ConflictStrategy

type ConflictStrategy int

ConflictStrategy controls how a genuine ours/theirs divergence is resolved during a 3-way merge. Named distinctly from MergeStrategy (above), which instead picks WHICH merger algorithm runs (YAML vs text) — an unrelated axis.

const (
	// ConflictStrategyManual is the default (zero value): surface the
	// conflict rather than silently picking a side. This is today's existing
	// behavior on any real divergence, so it's the safe default — defaulting
	// to "ours" or "theirs" instead would silently change behavior for
	// existing callers (a merge that errors out today would newly succeed
	// silently, a data-loss risk).
	ConflictStrategyManual ConflictStrategy = iota
	// ConflictStrategyOurs auto-resolves by keeping the user's value.
	ConflictStrategyOurs
	// ConflictStrategyTheirs auto-resolves by keeping the template's value.
	ConflictStrategyTheirs
)

func ParseConflictStrategy

func ParseConflictStrategy(s string) (ConflictStrategy, error)

ParseConflictStrategy parses a --merge-strategy flag value. An empty string (flag not set) maps to the default ConflictStrategyManual.

type MergeResult

type MergeResult struct {
	Content       string
	HasConflicts  bool
	ConflictCount int
}

MergeResult contains the result of a merge operation.

type MergeStrategy

type MergeStrategy int

MergeStrategy represents the merge algorithm to use.

const (
	// StrategyText uses text-based diff3 merge.
	StrategyText MergeStrategy = iota
	// StrategyYAML uses structure-aware YAML merge.
	StrategyYAML
)

type TextMerger

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

TextMerger handles 3-way merging of text files using the diff3 algorithm.

func NewTextMerger

func NewTextMerger(thresholdPercent int) *TextMerger

NewTextMerger creates a new text merger with the specified percentage threshold.

func (*TextMerger) Merge

func (m *TextMerger) Merge(base, ours, theirs string) (*MergeResult, error)

Merge performs a 3-way merge using the diff3 algorithm. Parameters:

  • base: The original content (common ancestor)
  • ours: The user's version (with their changes)
  • theirs: The template's version (with template updates)

Returns the merged content or an error if conflicts exceed threshold.

func (*TextMerger) SetConflictStrategy

func (m *TextMerger) SetConflictStrategy(strategy ConflictStrategy)

SetConflictStrategy sets how a real ours/theirs divergence is resolved. The zero value (ConflictStrategyManual) is today's existing behavior: diff3's inline <<<<<<< / ======= / >>>>>>> conflict markers are left in place for the caller to resolve by hand. Ours/theirs instead auto-resolve every conflict block to the chosen side, so the flag isn't YAML-only.

type ThreeWayMerger

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

ThreeWayMerger handles 3-way merging with automatic file type detection.

func NewThreeWayMerger

func NewThreeWayMerger(thresholdPercent int) *ThreeWayMerger

NewThreeWayMerger creates a new 3-way merger with the specified percentage threshold.

func (*ThreeWayMerger) Merge

func (m *ThreeWayMerger) Merge(base, ours, theirs, fileName string) (*MergeResult, error)

Merge performs a 3-way merge with automatic file type detection. Parameters:

  • base: The original content (common ancestor)
  • ours: The user's version (with their changes)
  • theirs: The template's version (with template updates)
  • fileName: The file name (used for type detection)

The merger automatically selects the appropriate strategy:

  • YAML files (.yaml, .yml): Structure-aware YAML merge with comment preservation
  • All other files: Text-based diff3 merge

Returns the merged content or an error if conflicts exceed threshold.

func (*ThreeWayMerger) MergeWithStrategy

func (m *ThreeWayMerger) MergeWithStrategy(base, ours, theirs string, strategy MergeStrategy) (*MergeResult, error)

MergeWithStrategy allows explicit strategy selection, bypassing auto-detection. This is useful when the file extension doesn't accurately represent the content type.

func (*ThreeWayMerger) SetConflictStrategy

func (m *ThreeWayMerger) SetConflictStrategy(strategy ConflictStrategy)

SetConflictStrategy sets how a real ours/theirs divergence is resolved. The zero value (ConflictStrategyManual) is today's existing behavior: record the conflict rather than silently picking a side.

type YAMLMerger

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

YAMLMerger handles 3-way merging of YAML files with structure awareness. It preserves comments, anchors, and performs intelligent key-level merging.

Why not use pkg/merge (mergego)? The pkg/merge package uses dario.cat/mergo for runtime map[string]any merging during stack configuration processing. This YAMLMerger serves a fundamentally different purpose:

  • pkg/merge: Merges already-parsed data structures (map[string]any) for stack inheritance
  • pkg/generator/merge: Performs git-style 3-way merges for template updates with conflict detection

Key differences:

  1. Level of operation: mergo works on Go data structures; this works on YAML nodes
  2. Merge strategy: mergo does 2-way merges; this does 3-way merges (base, ours, theirs)
  3. Conflict detection: mergo overwrites; this detects and reports conflicts
  4. Preservation: mergo doesn't preserve YAML formatting; this preserves comments and anchors
  5. Use case: mergo for config inheritance; this for updating user-modified files from templates

Example: When a user runs "atmos init --update", this merger compares:

  • base: the original template file (from git history)
  • ours: the user's modified version (current working directory)
  • theirs: the new template version (from updated template)

It intelligently merges changes, preserving user customizations while incorporating template updates.

func NewYAMLMerger

func NewYAMLMerger(thresholdPercent int) *YAMLMerger

NewYAMLMerger creates a new YAML merger with the specified percentage threshold.

func (*YAMLMerger) Merge

func (m *YAMLMerger) Merge(base, ours, theirs string) (*MergeResult, error)

Merge performs a 3-way merge of YAML content with structure awareness. Parameters:

  • base: The original YAML content (common ancestor)
  • ours: The user's YAML version (with their changes)
  • theirs: The template's YAML version (with template updates)

Returns the merged YAML content or an error if conflicts exceed threshold.

func (*YAMLMerger) SetConflictStrategy

func (m *YAMLMerger) SetConflictStrategy(strategy ConflictStrategy)

SetConflictStrategy sets how a real ours/theirs divergence is resolved. The zero value (ConflictStrategyManual) is today's existing behavior.

Jump to

Keyboard shortcuts

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