Skip to content

Don't preserve old repository on URL change #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions internal/command/modify/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions tests/test_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down