Skip to content

Commit 4999750

Browse files
authored
Merge pull request #107 from per1234/fix-modify-url
Don't preserve old repository on URL change
2 parents c566046 + d050161 commit 4999750

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

internal/command/modify/modify.go

+7-21
Original file line numberDiff line numberDiff line change
@@ -163,32 +163,18 @@ func modifyRepositoryURL(newRepositoryURL string) error {
163163

164164
fmt.Printf("Changing URL of library %s from %s to %s\n", libraryName, oldRepositoryURL, newRepositoryURL)
165165

166-
// Move the library Git clone to the new path.
167-
gitClonePath := func(url string) (*paths.Path, error) {
168-
libraryRegistration := libraries.Repo{URL: url}
169-
gitCloneSubfolder, err := libraryRegistration.AsFolder()
170-
if err != nil {
171-
return nil, err
172-
}
173-
174-
return paths.New(config.GitClonesFolder, gitCloneSubfolder), nil
175-
}
176-
oldGitClonePath, err := gitClonePath(oldRepositoryURL)
166+
// Remove the library Git clone folder. It will be cloned from the new URL on the next sync.
167+
libraryRegistration := libraries.Repo{URL: libraryData.Repository}
168+
gitCloneSubfolder, err := libraryRegistration.AsFolder()
177169
if err != nil {
178170
return err
179171
}
180-
newGitClonePath, err := gitClonePath(newRepositoryURL)
181-
if err != nil {
182-
return err
183-
}
184-
if err := newGitClonePath.Parent().MkdirAll(); err != nil {
185-
return fmt.Errorf("While creating new library Git clone path: %w", err)
186-
}
187-
if err := backup.Backup(oldGitClonePath); err != nil {
172+
gitClonePath := paths.New(config.GitClonesFolder, gitCloneSubfolder)
173+
if err := backup.Backup(gitClonePath); err != nil {
188174
return fmt.Errorf("While backing up library's Git clone: %w", err)
189175
}
190-
if err := oldGitClonePath.Rename(newGitClonePath); err != nil {
191-
return fmt.Errorf("While moving library's Git clone: %w", err)
176+
if err := gitClonePath.RemoveAll(); err != nil {
177+
return fmt.Errorf("While removing library's Git clone: %w", err)
192178
}
193179

194180
// Update the library repository URL in the database.

tests/test_modify.py

-5
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ def test_repo_url(
227227
new_library_release_archives_folder = pathlib.Path(configuration.data["LibrariesFolder"]).joinpath(
228228
new_host, new_owner
229229
)
230-
new_git_clone_path = pathlib.Path(configuration.data["GitClonesFolder"]).joinpath(
231-
new_host, new_owner, new_repo_name
232-
)
233230
# The "canary" library is not modified and so all its content should remain unchanged after running the command
234231
canary_name = "ArduinoIoTCloudBearSSL"
235232
sanitized_canary_name = "ArduinoIoTCloudBearSSL"
@@ -281,7 +278,6 @@ def get_release_archive_url(name, version):
281278
raise
282279

283280
assert old_git_clone_path.exists()
284-
assert not new_git_clone_path.exists()
285281
assert canary_git_clone_path.exists()
286282
assert get_library_repo_url(name=name) != new_repo_url
287283
assert get_library_repo_url(name=canary_name) == canary_repo_url
@@ -314,7 +310,6 @@ def get_release_archive_url(name, version):
314310

315311
# Verify the effect of the command was as expected
316312
assert not old_git_clone_path.exists()
317-
assert new_git_clone_path.exists()
318313
assert canary_release_archive_path.exists()
319314
assert canary_git_clone_path.exists()
320315
assert get_library_repo_url(name=name) == new_repo_url

0 commit comments

Comments
 (0)