Skip to content

Commit 7e497a7

Browse files
authored
Update remote if url has changed (#34)
Previously we were checking if the remote name is there to add it. Now, if the patches_repo url has changed, but we maintain the same remote_name, this is updated. For doing this, we just check if the remote_name exists and if the patches_repo differs from its value. If so, we just remove the remote so next line below it'd recreate it. Not it's based on new git_wrapper version that allows to return the remote dict with its value but also to remove the remote. Requires: release-depot/git_wrapper#114
1 parent afbdf34 commit 7e497a7

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

patch_rebaser/patch_rebaser.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,14 @@ def main():
457457
)
458458
if not patches_repo:
459459
return
460-
461-
if config.remote_name not in repo.remote.names():
460+
remotes = repo.remote.names_url_dict()
461+
# If the remote url has changed, we removes to re-create
462+
if (config.remote_name in remotes.keys() and
463+
patches_repo != remotes[config.remote_name]):
464+
repo.remote.remove(config.remote_name)
465+
remotes = repo.remote.names_url_dict()
466+
# Create the remote if it doesn't exist
467+
if config.remote_name not in remotes.keys():
462468
if not repo.remote.add(config.remote_name, patches_repo):
463469
raise Exception(
464470
"Could not add remote {0} ({1})".format(config.remote_name,

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
git_wrapper>=0.2.2
1+
git_wrapper>=0.2.11
22
Distroinfo>=0.1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
readme = readme_file.read()
1010

1111
requirements = [ 'Distroinfo>=0.1',
12-
'git_wrapper>=0.2.2' ]
12+
'git_wrapper>=0.2.11' ]
1313

1414
test_requirements = [ 'mock', 'pytest', ]
1515

tests/test_patch_rebaser.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,27 @@ def test_main_function(mock_env, mock_config, monkeypatch):
354354
'private-rebaser-16.1-') is True
355355

356356

357+
def test_main_function_update_remote_url(mock_env, mock_config, monkeypatch):
358+
"""
359+
GIVEN a valid patch_rebaser configuration and environment
360+
WHEN main() is called
361+
AND remote url has changed
362+
THEN the remote.remove method is called
363+
"""
364+
repo = MagicMock()
365+
monkeypatch.setattr(repo.remote, 'names_url_dict',
366+
lambda: {"test_remote_name":
367+
"http://origin_remote.com"})
368+
369+
with monkeypatch.context() as m:
370+
m.setattr(patch_rebaser.patch_rebaser, 'GitRepo',
371+
Mock(return_value=repo))
372+
m.setattr(patch_rebaser.patch_rebaser, 'get_patches_repo',
373+
Mock(return_value="http://test_repo.com"))
374+
main()
375+
repo.remote.remove.assert_called_once()
376+
377+
357378
def test_packages_to_process_skips_packages_not_in_the_list(
358379
mock_env, mock_config_with_pkgs_to_process, monkeypatch):
359380
"""

0 commit comments

Comments
 (0)