Detect default branch from grm.toml if possible
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import pytest
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
@@ -139,3 +141,56 @@ def test_worktree_clean_non_git():
|
||||
assert cmd.returncode != 0
|
||||
assert len(cmd.stdout) == 0
|
||||
assert len(cmd.stderr) != 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("configure_default_branch", [True, False])
|
||||
@pytest.mark.parametrize("branch_list_empty", [True, False])
|
||||
def test_worktree_clean_configured_default_branch(
|
||||
configure_default_branch, branch_list_empty
|
||||
):
|
||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||
if configure_default_branch:
|
||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
||||
if branch_list_empty:
|
||||
f.write(
|
||||
f"""
|
||||
persistent_branches = []
|
||||
"""
|
||||
)
|
||||
else:
|
||||
f.write(
|
||||
f"""
|
||||
persistent_branches = [
|
||||
"mybranch"
|
||||
]
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
|
||||
shell(
|
||||
f"""
|
||||
cd {base_dir}
|
||||
(
|
||||
cd ./test
|
||||
touch change
|
||||
git add change
|
||||
git commit -m commit
|
||||
)
|
||||
|
||||
git --git-dir ./.git-main-working-tree worktree add mybranch
|
||||
(
|
||||
cd ./mybranch
|
||||
git merge --no-ff test
|
||||
)
|
||||
git --git-dir ./.git-main-working-tree worktree remove mybranch
|
||||
"""
|
||||
)
|
||||
|
||||
cmd = grm(["wt", "clean"], cwd=base_dir)
|
||||
assert cmd.returncode == 0
|
||||
if configure_default_branch and not branch_list_empty:
|
||||
assert "test" not in os.listdir(base_dir)
|
||||
else:
|
||||
assert "test" in os.listdir(base_dir)
|
||||
|
||||
Reference in New Issue
Block a user