From 88a2c2656a5de7791ae1e59ba6df50bd1179b3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 28 Jul 2023 12:35:41 +0200 Subject: [PATCH] get_clan_flake_toplevel: fix check --- pkgs/clan-cli/clan_cli/dirs.py | 2 +- pkgs/clan-cli/tests/test_dirs.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index 514bbe1..cf5151e 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -10,7 +10,7 @@ def get_clan_flake_toplevel() -> Path: for project_file in [".clan-flake", ".git", ".hg", ".svn", "flake.nix"]: initial_path = Path(os.getcwd()) path = Path(initial_path) - while path.parent == path: + while path.parent != path: if (path / project_file).exists(): return path path = path.parent diff --git a/pkgs/clan-cli/tests/test_dirs.py b/pkgs/clan-cli/tests/test_dirs.py index e379490..2dec0e1 100644 --- a/pkgs/clan-cli/tests/test_dirs.py +++ b/pkgs/clan-cli/tests/test_dirs.py @@ -12,3 +12,11 @@ def test_get_clan_flake_toplevel( monkeypatch.chdir(temporary_dir) with pytest.raises(ClanError): get_clan_flake_toplevel() + (temporary_dir / ".git").touch() + assert get_clan_flake_toplevel() == temporary_dir + + subdir = temporary_dir / "subdir" + subdir.mkdir() + monkeypatch.chdir(subdir) + (subdir / ".clan-flake").touch() + assert get_clan_flake_toplevel() == subdir