diff --git a/internal/command/modify/modify.go b/internal/command/modify/modify.go index a21315a7..ab90e0f2 100644 --- a/internal/command/modify/modify.go +++ b/internal/command/modify/modify.go @@ -163,32 +163,18 @@ func modifyRepositoryURL(newRepositoryURL string) error { fmt.Printf("Changing URL of library %s from %s to %s\n", libraryName, oldRepositoryURL, newRepositoryURL) - // Move the library Git clone to the new path. - gitClonePath := func(url string) (*paths.Path, error) { - libraryRegistration := libraries.Repo{URL: url} - gitCloneSubfolder, err := libraryRegistration.AsFolder() - if err != nil { - return nil, err - } - - return paths.New(config.GitClonesFolder, gitCloneSubfolder), nil - } - oldGitClonePath, err := gitClonePath(oldRepositoryURL) + // Remove the library Git clone folder. It will be cloned from the new URL on the next sync. + libraryRegistration := libraries.Repo{URL: libraryData.Repository} + gitCloneSubfolder, err := libraryRegistration.AsFolder() if err != nil { return err } - newGitClonePath, err := gitClonePath(newRepositoryURL) - if err != nil { - return err - } - if err := newGitClonePath.Parent().MkdirAll(); err != nil { - return fmt.Errorf("While creating new library Git clone path: %w", err) - } - if err := backup.Backup(oldGitClonePath); err != nil { + gitClonePath := paths.New(config.GitClonesFolder, gitCloneSubfolder) + if err := backup.Backup(gitClonePath); err != nil { return fmt.Errorf("While backing up library's Git clone: %w", err) } - if err := oldGitClonePath.Rename(newGitClonePath); err != nil { - return fmt.Errorf("While moving library's Git clone: %w", err) + if err := gitClonePath.RemoveAll(); err != nil { + return fmt.Errorf("While removing library's Git clone: %w", err) } // Update the library repository URL in the database. diff --git a/tests/test_modify.py b/tests/test_modify.py index f6ef6b64..e8c247d9 100644 --- a/tests/test_modify.py +++ b/tests/test_modify.py @@ -227,9 +227,6 @@ def test_repo_url( new_library_release_archives_folder = pathlib.Path(configuration.data["LibrariesFolder"]).joinpath( new_host, new_owner ) - new_git_clone_path = pathlib.Path(configuration.data["GitClonesFolder"]).joinpath( - new_host, new_owner, new_repo_name - ) # The "canary" library is not modified and so all its content should remain unchanged after running the command canary_name = "ArduinoIoTCloudBearSSL" sanitized_canary_name = "ArduinoIoTCloudBearSSL" @@ -281,7 +278,6 @@ def get_release_archive_url(name, version): raise assert old_git_clone_path.exists() - assert not new_git_clone_path.exists() assert canary_git_clone_path.exists() assert get_library_repo_url(name=name) != new_repo_url assert get_library_repo_url(name=canary_name) == canary_repo_url @@ -314,7 +310,6 @@ def get_release_archive_url(name, version): # Verify the effect of the command was as expected assert not old_git_clone_path.exists() - assert new_git_clone_path.exists() assert canary_release_archive_path.exists() assert canary_git_clone_path.exists() assert get_library_repo_url(name=name) == new_repo_url