remove renames with same source and destination

This commit is contained in:
itchyny 2020-01-08 09:00:08 +09:00
parent 0926ef4faa
commit d838f2b136
2 changed files with 30 additions and 0 deletions

6
mmv.go
View file

@ -61,6 +61,12 @@ func buildRenames(files map[string]string) ([]rename, error) {
}
revs[dst] = src
}
for src, dst := range files {
if src == dst {
delete(files, src)
delete(revs, dst)
}
}
var i int
for _, dst := range files {
if vs[dst] > 0 {

View file

@ -198,6 +198,30 @@ func TestRename(t *testing.T) {
},
err: &sameDestinationError{"baz"},
},
{
name: "same source and destination",
files: map[string]string{
"foo/": "foo",
"bar/": "bar",
},
cnt: 0,
contents: map[string]string{
"foo": "0",
"bar": "1",
},
expected: map[string]string{
"foo": "0",
"bar": "1",
},
},
{
name: "same source and destination with error",
files: map[string]string{
"foo/": "foo/",
"bar/": "foo",
},
err: &sameDestinationError{"foo"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {