Skip to content
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
10 changes: 8 additions & 2 deletions patch_rebaser/patch_rebaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,14 @@ def main():
)
if not patches_repo:
return

if config.remote_name not in repo.remote.names():
remotes = repo.remote.names_url_dict()
# If the remote url has changed, we removes to re-create
if (config.remote_name in remotes.keys() and
patches_repo != remotes[config.remote_name]):
repo.remote.remove(config.remote_name)
remotes = repo.remote.names_url_dict()
# Create the remote if it doesn't exist
if config.remote_name not in remotes.keys():
if not repo.remote.add(config.remote_name, patches_repo):
raise Exception(
"Could not add remote {0} ({1})".format(config.remote_name,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git_wrapper>=0.2.2
git_wrapper>=0.2.11
Distroinfo>=0.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
readme = readme_file.read()

requirements = [ 'Distroinfo>=0.1',
'git_wrapper>=0.2.2' ]
'git_wrapper>=0.2.11' ]

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

Expand Down
21 changes: 21 additions & 0 deletions tests/test_patch_rebaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,27 @@ def test_main_function(mock_env, mock_config, monkeypatch):
'private-rebaser-16.1-') is True


def test_main_function_update_remote_url(mock_env, mock_config, monkeypatch):
"""
GIVEN a valid patch_rebaser configuration and environment
WHEN main() is called
AND remote url has changed
THEN the remote.remove method is called
"""
repo = MagicMock()
monkeypatch.setattr(repo.remote, 'names_url_dict',
lambda: {"test_remote_name":
"http://origin_remote.com"})

with monkeypatch.context() as m:
m.setattr(patch_rebaser.patch_rebaser, 'GitRepo',
Mock(return_value=repo))
m.setattr(patch_rebaser.patch_rebaser, 'get_patches_repo',
Mock(return_value="http://test_repo.com"))
main()
repo.remote.remove.assert_called_once()


def test_packages_to_process_skips_packages_not_in_the_list(
mock_env, mock_config_with_pkgs_to_process, monkeypatch):
"""
Expand Down