Repository navigation
A configured entry may not share a clone under another remote #1548
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
94181f1
A configured entry may not share a clone with another repository
KaloyanNaumov cd1401e
Compare a held clone dir by its canonical path
KaloyanNaumov 004b81f
Key held clone dirs by path and by directory identity
KaloyanNaumov c97ad5e
Refuse git_dir spellings that differ only in case before either exists
KaloyanNaumov 553cbe2
Hold clone dirs by path and identity only, and document the first-run…
KaloyanNaumov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| """Two entries on one clone dir share the bare clone only when their `git_remote` | ||
| values, after the defaults, are the same: a fork and its upstream derive the same | ||
| clone dir, and one clone would let each fetch move the other's refs.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| import server.code.domain.index.repos as repos | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def cfg(monkeypatch: pytest.MonkeyPatch, scalar_code_repo): | ||
| from server.settings import settings | ||
|
|
||
| def _set(entries): | ||
| monkeypatch.setattr(settings, "code_repos_json", json.dumps(entries)) | ||
| repos._config_errors.clear() | ||
| repos._config_errors_logged.clear() | ||
| return {r.namespace: r for r in repos.configured_repos()} | ||
|
|
||
| return _set | ||
|
|
||
|
|
||
| def test_a_fork_and_its_upstream_do_not_share_a_clone(cfg) -> None: | ||
| got = cfg( | ||
| [ | ||
| { | ||
| "namespace": "code-widgets-fork", | ||
| "repo": "git.example.com/acme/widgets", | ||
| "git_remote": "https://git.example.com/acme/widgets.git", | ||
| }, | ||
| {"namespace": "code-widgets-upstream", "repo": "widgets-org/widgets"}, | ||
| ] | ||
| ) | ||
| assert "code-widgets-fork" in got | ||
| assert "code-widgets-upstream" not in got | ||
| msg = repos._config_errors["git_dir:code-widgets-upstream"] | ||
| assert "code-widgets-fork" in msg | ||
| assert "use one spelling of the remote, or set a separate git_dir" in msg | ||
|
|
||
|
|
||
| def test_branches_with_one_spelling_of_the_remote_share_their_clone(cfg) -> None: | ||
| got = cfg( | ||
| [ | ||
| {"namespace": "code-widgets", "repo": "acme/widgets", "git_branch": "main"}, | ||
| { | ||
| "namespace": "code-widgets-2-4", | ||
| "repo": "acme/widgets", | ||
| "git_branch": "release/2.4", | ||
| "git_remote": "https://github.com/acme/widgets.git", | ||
| }, | ||
| ] | ||
| ) | ||
| assert got["code-widgets"].git_dir == got["code-widgets-2-4"].git_dir | ||
| assert repos.config_error_count() == 0 | ||
|
|
||
|
|
||
| def test_two_spellings_of_one_remote_are_refused(cfg) -> None: | ||
| got = cfg( | ||
| [ | ||
| {"namespace": "code-widgets", "repo": "acme/widgets", "git_branch": "main"}, | ||
| { | ||
| "namespace": "code-widgets-2-4", | ||
| "repo": "acme/widgets", | ||
| "git_branch": "release/2.4", | ||
| "git_remote": "git@github.com:acme/widgets.git", | ||
| }, | ||
| ] | ||
| ) | ||
| assert "code-widgets" in got | ||
| assert "code-widgets-2-4" not in got | ||
| msg = repos._config_errors["git_dir:code-widgets-2-4"] | ||
| assert "code-widgets" in msg | ||
| assert "use one spelling of the remote, or set a separate git_dir" in msg | ||
|
|
||
|
|
||
| def test_a_separate_git_dir_lets_both_in(cfg) -> None: | ||
| got = cfg( | ||
| [ | ||
| { | ||
| "namespace": "code-widgets-fork", | ||
| "repo": "git.example.com/acme/widgets", | ||
| "git_remote": "https://git.example.com/acme/widgets.git", | ||
| }, | ||
| { | ||
| "namespace": "code-widgets-upstream", | ||
| "repo": "widgets-org/widgets", | ||
| "git_dir": "var/code_repos/widgets-upstream.git", | ||
| }, | ||
| ] | ||
| ) | ||
| assert got["code-widgets-fork"].git_dir != got["code-widgets-upstream"].git_dir | ||
| assert repos.config_error_count() == 0 | ||
|
|
||
|
|
||
| def _two_repositories(first_dir: str, second_dir: str) -> list[dict[str, str]]: | ||
| return [ | ||
| {"namespace": "code-widgets-fork", "repo": "acme/widgets", "git_dir": first_dir}, | ||
| { | ||
| "namespace": "code-widgets-upstream", | ||
| "repo": "widgets-org/widgets", | ||
| "git_dir": second_dir, | ||
| }, | ||
| ] | ||
|
|
||
|
|
||
| def test_two_spellings_of_one_clone_are_one_clone( | ||
| cfg, monkeypatch: pytest.MonkeyPatch, tmp_path | ||
| ) -> None: | ||
| monkeypatch.chdir(tmp_path) | ||
| got = cfg(_two_repositories("var/widgets.git", str(tmp_path / "var" / "widgets.git"))) | ||
| assert "code-widgets-fork" in got | ||
| assert "code-widgets-upstream" not in got | ||
| assert "code-widgets-fork" in repos._config_errors["git_dir:code-widgets-upstream"] | ||
|
|
||
|
|
||
| def test_a_symlink_to_a_held_clone_is_the_same_clone( | ||
| cfg, monkeypatch: pytest.MonkeyPatch, tmp_path | ||
| ) -> None: | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "widgets.git").mkdir() | ||
| (tmp_path / "alias.git").symlink_to(tmp_path / "widgets.git") | ||
| got = cfg(_two_repositories("widgets.git", "alias.git")) | ||
| assert "code-widgets-upstream" not in got | ||
| assert "git_dir:code-widgets-upstream" in repos._config_errors | ||
|
|
||
|
|
||
| def test_a_case_alias_of_a_held_clone_is_the_same_clone( | ||
| cfg, monkeypatch: pytest.MonkeyPatch, tmp_path | ||
| ) -> None: | ||
| # One directory, as on a case-insensitive volume: the lookup of either spelling | ||
| # finds `Widget.git`, so `os.stat` reports the same identity for both. | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "Widget.git").mkdir() | ||
| real_stat = os.stat | ||
|
|
||
| def stat(path, *args, **kwargs): | ||
| if os.path.basename(path).lower() == "widget.git": | ||
| path = tmp_path / "Widget.git" | ||
| return real_stat(path, *args, **kwargs) | ||
|
|
||
| monkeypatch.setattr(os, "stat", stat) | ||
| got = cfg(_two_repositories("Widget.git", "widget.git")) | ||
| assert "code-widgets-fork" in got | ||
| assert "code-widgets-upstream" not in got | ||
| assert "code-widgets-fork" in repos._config_errors["git_dir:code-widgets-upstream"] | ||
|
|
||
|
|
||
| def test_a_missing_spelling_of_a_held_clone_is_the_same_clone( | ||
| cfg, monkeypatch: pytest.MonkeyPatch, tmp_path | ||
| ) -> None: | ||
| # `os.stat` fails on the missing component while the canonical path collapses `..`: | ||
| # the entry has no identity yet but still names the held directory. | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "widgets.git").mkdir() | ||
| got = cfg(_two_repositories("widgets.git", "missing/../widgets.git")) | ||
| assert "code-widgets-fork" in got | ||
| assert "code-widgets-upstream" not in got | ||
| assert "code-widgets-fork" in repos._config_errors["git_dir:code-widgets-upstream"] | ||
|
|
||
|
|
||
| def test_clone_dirs_that_differ_only_in_case_stay_distinct_on_a_case_sensitive_volume( | ||
| cfg, monkeypatch: pytest.MonkeyPatch, tmp_path | ||
| ) -> None: | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "Widget.git").mkdir() | ||
| (tmp_path / "widget.git").mkdir(exist_ok=True) | ||
| if len(list(tmp_path.iterdir())) != 2: | ||
| pytest.skip("the volume is case-insensitive: both spellings are one directory") | ||
| got = cfg(_two_repositories("Widget.git", "widget.git")) | ||
| assert "code-widgets-fork" in got | ||
| assert "code-widgets-upstream" in got | ||
| assert repos.config_error_count() == 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.