Skip to content

Commit

Permalink
verbose diff can be saved
Browse files Browse the repository at this point in the history
  • Loading branch information
seanenck committed Oct 21, 2024
1 parent e24e8a5 commit d819037
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/dotfiles/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ func deploy(vars variables, s Settings) error {
}

func (v variables) different(file string, b []byte, verbose bool) ([]byte, error) {
if !verbose {
read, err := os.ReadFile(file)
if err != nil {
return nil, err
}
if slices.Compare(read, b) == 0 {
return nil, nil
}
return simpleDiff, nil
}
f, err := os.CreateTemp("", "dotfiles.")
if err != nil {
return nil, err
Expand All @@ -368,20 +378,14 @@ func (v variables) different(file string, b []byte, verbose bool) ([]byte, error
if _, err := f.Write(b); err != nil {
return nil, err
}
return v.doDiff(file, f.Name(), verbose), nil
return v.doDiff(file, f.Name()), nil
}

func (v variables) doDiff(left, right string, verbose bool) []byte {
func (v variables) doDiff(left, right string) []byte {
args := v.diff.args
args = append(args, left, right)
cmd := exec.Command(v.diff.exe, args...)
b, _ := cmd.CombinedOutput()
if !verbose {
if len(b) == 0 {
return nil
}
return simpleDiff
}
return b
}

Expand Down

0 comments on commit d819037

Please sign in to comment.