Skip to content

Commit

Permalink
Merge pull request #743 from twpayne/fix-740
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 10, 2020
2 parents a11b8b4 + 7274e81 commit 89d9dc7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *Config) runDiffCmd(cmd *cobra.Command, args []string) error {
case "chezmoi":
c.mutator = chezmoi.NullMutator{}
case "git":
c.mutator = chezmoi.NewFSMutator(vfs.NewReadOnlyFS(config.fs))
c.mutator = chezmoi.NewFSMutator(vfs.NewReadOnlyFS(c.fs))
default:
return fmt.Errorf("unknown diff format: %q", c.Diff.Format)
}
Expand Down
31 changes: 31 additions & 0 deletions cmd/diff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/twpayne/go-vfs/vfst"
)

func TestIssue740(t *testing.T) {
fs, cleanup, err := vfst.NewTestFS(map[string]interface{}{
"/home/user": map[string]interface{}{
"dir": map[string]interface{}{
"foo": "foo",
},
".local/share/chezmoi": map[string]interface{}{
"exact_dir": map[string]interface{}{
"foo": "foo",
"bar": "bar",
},
},
},
})
require.NoError(t, err)
defer cleanup()

c := newTestConfig(fs)
c.Diff.Format = "git"
assert.NoError(t, c.runDiffCmd(nil, nil))
}
4 changes: 3 additions & 1 deletion internal/chezmoi/gitdiffmutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ func (m *GitDiffMutator) WriteSymlink(oldname, newname string) error {

func (m *GitDiffMutator) getFileMode(name string) (filemode.FileMode, os.FileInfo, error) {
info, err := m.m.Stat(name)
if err != nil {
if os.IsNotExist(err) {
return filemode.Empty, nil, nil
} else if err != nil {
return filemode.Empty, nil, err
}
fileMode, err := filemode.NewFromOSFileMode(info.Mode())
Expand Down

0 comments on commit 89d9dc7

Please sign in to comment.