diff --git a/poetry.lock b/poetry.lock index b0468d20..055c35e6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -255,7 +255,7 @@ PyYAML = ">=3.13,<6" [[package]] name = "libvcs" -version = "0.12.0b10" +version = "0.12.0b11" description = "vcs abstraction layer" category = "main" optional = false @@ -852,7 +852,7 @@ test = [] [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "b55113dc83d8c84ede5da587a67f15e012abd37ed5b7677e2ce9358e1f41eec6" +content-hash = "ece5385e1398b4ac02b2a72fbadc2d842da0e4a8503661502c5e820f4da019e3" [metadata.files] alabaster = [ @@ -1004,8 +1004,8 @@ kaptan = [ {file = "kaptan-0.5.12.tar.gz", hash = "sha256:1abd1f56731422fce5af1acc28801677a51e56f5d3c3e8636db761ed143c3dd2"}, ] libvcs = [ - {file = "libvcs-0.12.0b10-py3-none-any.whl", hash = "sha256:3f902ce0330be5e0ebab1453c64f18f3b83a2abf9551c679c4a4fff56253fa1a"}, - {file = "libvcs-0.12.0b10.tar.gz", hash = "sha256:ecfd3a1439124b909f30e9f662ab70c0e026d74a842cc4cd4de18eef18dcbd5e"}, + {file = "libvcs-0.12.0b11-py3-none-any.whl", hash = "sha256:a5b12fd326821fe2ab804768682fbf2be34047237d8a3eccde7789ef0bf186d1"}, + {file = "libvcs-0.12.0b11.tar.gz", hash = "sha256:ab2e025c5e664256f8dac7d125bcc99ae4e5cf39f03e1b6d2eab521928dcff01"}, ] livereload = [ {file = "livereload-2.6.3.tar.gz", hash = "sha256:776f2f865e59fde56490a56bcc6773b6917366bce0c267c60ee8aaf1a0959869"}, diff --git a/pyproject.toml b/pyproject.toml index 0f2a3dcd..dc1e7343 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ vcspull = 'vcspull:cli.cli' python = "^3.9" click = ">=7<8.1" kaptan = "*" -libvcs = "~0.12.0b10" +libvcs = "~0.12.0b11" colorama = ">=0.3.9" [tool.poetry.dev-dependencies] diff --git a/tests/test_sync.py b/tests/test_sync.py index 4c65f407..a5dc0c8e 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -71,7 +71,7 @@ def write_config_remote( {CLONE_NAME}: repo: git+file://{repo_dir} remotes: - secondremote: git+file://{repo_dir} + secondremote: git+file://{repo_dir} """, ["secondremote"], ], @@ -109,8 +109,6 @@ def test_config_variations( assert set(remote_list).issubset(remote_names) or {"origin"}.issubset( remote_names ) - captured = capsys.readouterr() - assert f"Updating remote {list(remote_names)[0]}" in captured.out for remote_name, remote_info in remotes.items(): current_remote = repo.remote(remote_name) @@ -141,7 +139,7 @@ def test_config_variations( {CLONE_NAME}: repo: git+file://{repo_dir} remotes: - secondremote: git+file://{repo_dir} + mirror_repo: git+file://{repo_dir} """, True, ], @@ -158,65 +156,53 @@ def test_updating_remote( dummy_repo_name = "dummy_repo" dummy_repo = create_git_dummy_repo(dummy_repo_name) + mirror_name = "mirror_repo" + mirror_repo = create_git_dummy_repo(mirror_name) + repo_parent = tmp_path / "study" / "myrepo" repo_parent.mkdir(parents=True) - base_config = { + initial_config = { "name": "myclone", "repo_dir": f"{tmp_path}/study/myrepo/myclone", "parent_dir": f"{tmp_path}/study/myrepo", "url": f"git+file://{dummy_repo}", "remotes": { - "secondremote": GitRemote( - name="secondremote", - fetch_url=f"git+file://{dummy_repo}", - push_url=f"git+file://{dummy_repo}", - ) + mirror_name: { + "name": mirror_name, + "fetch_url": f"git+file://{dummy_repo}", + "push_url": f"git+file://{dummy_repo}", + } }, } - def merge_dict(_dict, extra): - _dict = _dict.copy() - _dict.update(**extra) - return _dict - - configs = [base_config] - for repo_dict in filter_repos( - configs, + [initial_config], ): - update_repo(repo_dict).remotes()["origin"] - - expected_remote_url = f"git+file://{dummy_repo}/moo" - - config = merge_dict( - base_config, - extra={ - "remotes": { - "secondremote": GitRemote( - name="secondremote", - fetch_url=expected_remote_url, - push_url=expected_remote_url, - ) - } - }, - ) - configs = [config] - - repo_dict = filter_repos(configs, name="myclone")[0] - r = update_repo(repo_dict) - for remote_name, remote_info in r.remotes().items(): - current_remote_url = r.remote(remote_name).fetch_url.replace("git+", "") - config_remote_url = ( - next( - ( - r.fetch_url - for rname, r in config["remotes"].items() - if rname == remote_name - ), - None, + local_git_remotes = update_repo(repo_dict).remotes() + assert "origin" in local_git_remotes + + expected_remote_url = f"git+file://{mirror_repo}" + + config = initial_config | { + "remotes": { + mirror_name: GitRemote( + name=mirror_name, + fetch_url=expected_remote_url, + push_url=expected_remote_url, ) - if remote_name != "origin" - else config["url"] - ).replace("git+", "") - assert config_remote_url == current_remote_url + } + } + + repo_dict = filter_repos([config], name="myclone")[0] + repo = update_repo(repo_dict) + for remote_name, remote_info in repo.remotes().items(): + current_remote_url = repo.remote(remote_name).fetch_url.replace("git+", "") + if remote_name in config["remotes"]: + assert ( + config["remotes"][remote_name].fetch_url.replace("git+", "") + == current_remote_url + ) + + elif remote_name == "origin": + assert config["url"].replace("git+", "") == current_remote_url diff --git a/vcspull/cli/sync.py b/vcspull/cli/sync.py index 4469ad6c..b7268dd9 100644 --- a/vcspull/cli/sync.py +++ b/vcspull/cli/sync.py @@ -123,44 +123,6 @@ def update_repo(repo_dict): repo_dict["progress_callback"] = progress_cb r = create_repo_from_pip_url(**repo_dict) # Creates the repo object + r.update_repo(set_remotes=True) # Creates repo if not exists and fetches - remote_settings = repo_dict.get("remotes", {}) - if remote_settings.get("origin", {}) == {}: - from libvcs.git import GitRemote - - remote_settings["origin"] = GitRemote( - name="origin", - push_url=repo_dict["pip_url"], - fetch_url=repo_dict["pip_url"], - ) - - remotes_updated = False - r.update_repo() # Creates repo if not exists and fetches - - for remote_name, remote_setting in remote_settings.items(): - config_remote_name = remote_name # From config file - try: - current_remote = r.remote(config_remote_name) - except FileNotFoundError: # git repo doesn't exist yet, so cna't be outdated - break - - current_fetch_url = ( - current_remote.fetch_url if current_remote is not None else None - ) - - if current_remote is None or current_fetch_url != remote_setting.fetch_url: - print( - "Updating remote {name} ({current_url}) with {new_url}".format( - name=config_remote_name, - current_url=current_fetch_url, - new_url=remote_setting.fetch_url, - ) - ) - r.set_remote( - name=config_remote_name, url=remote_setting.fetch_url, overwrite=True - ) - remotes_updated = True - - if remotes_updated: # Fetch again since we added / changed remotes - r.update_repo() return r