Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func groupObjsForDiff(resources *application.ManagedResourcesResponse, objs map[
}

// GetDiff gets a diff between two unstructured objects to stdout using an external diff utility
func GetDiff(live *unstructured.Unstructured, target *unstructured.Unstructured) (string, error) {
func GetDiff(live *unstructured.Unstructured, target *unstructured.Unstructured, diffOptions DiffOptions) (string, error) {
tempDir, err := os.MkdirTemp("", "argocd-diff")
if err != nil {
return "", err
Expand Down Expand Up @@ -170,7 +170,14 @@ func GetDiff(live *unstructured.Unstructured, target *unstructured.Unstructured)
if err != nil {
return "", err
}
cmd := exec.Command("diff", liveFile.Name(), targetFile.Name())
args := []string{liveFile.Name(), targetFile.Name()}
if diffOptions.CopiedContextLines != "" {
args = append(args, "--context="+diffOptions.CopiedContextLines)
}
if diffOptions.IgnoreBlankLines {
args = append(args, "--ignore-blank-lines=")
}
cmd := exec.Command("diff", args...)
out, err := cmd.Output()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
Expand Down
6 changes: 6 additions & 0 deletions internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ type DiffAction struct {
Revision string `json:"revision,omitempty"`
Refresh bool `json:"refresh,omitempty"`
HardRefresh bool `json:"hardRefresh,omitempty"`
DiffOptions `json:"diffOptions,omitempty"`
}

type DiffOptions struct {
CopiedContextLines string `json:"copiedContextLines,omitempty"`
IgnoreBlankLines bool `json:"ignoreBlankLines,omitempty"`
}

// SyncAction describes an action that triggers an argocd sync.
Expand Down