From 877ae0489d6101847711e5699bf8af301262f2c4 Mon Sep 17 00:00:00 2001 From: Ayooluwa Isaiah Date: Mon, 22 Jul 2024 01:15:56 +0100 Subject: [PATCH] ensure sort is performed before validations --- rename/rename.go | 5 ----- replace/replace.go | 4 ++++ replace/replace_test/replace_test.go | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rename/rename.go b/rename/rename.go index 7ce6e65..f720ff8 100644 --- a/rename/rename.go +++ b/rename/rename.go @@ -22,7 +22,6 @@ import ( "github.com/ayoisaiah/f2/internal/file" "github.com/ayoisaiah/f2/internal/jsonutil" "github.com/ayoisaiah/f2/internal/osutil" - "github.com/ayoisaiah/f2/internal/sortfiles" "github.com/ayoisaiah/f2/report" ) @@ -214,10 +213,6 @@ func Rename( conf *config.Config, fileChanges []*file.Change, ) error { - if conf.IncludeDir { - sortfiles.ForRenamingAndUndo(fileChanges, conf.Revert) - } - if !conf.Interactive && !conf.Exec && !conf.JSON { report.NonInteractive(fileChanges) return nil diff --git a/replace/replace.go b/replace/replace.go index 21b5e15..3930a9f 100644 --- a/replace/replace.go +++ b/replace/replace.go @@ -777,5 +777,9 @@ func Replace( return nil, err } + if conf.IncludeDir { + sortfiles.ForRenamingAndUndo(changes, conf.Revert) + } + return changes, nil } diff --git a/replace/replace_test/replace_test.go b/replace/replace_test/replace_test.go index 6d0238d..2e5a547 100644 --- a/replace/replace_test/replace_test.go +++ b/replace/replace_test/replace_test.go @@ -166,10 +166,10 @@ func TestReplace(t *testing.T) { }, }, Want: []string{ - "music/2013/overgrown", "music/Overgrown (2013)/01-overgrown.flac", "music/Overgrown (2013)/02-i-am-sold.flac", "music/Overgrown (2013)/cover.jpg", + "music/2013/overgrown", }, Args: []string{ "-f",