Add functionality for persistent branches

This commit is contained in:
2021-12-23 18:33:14 +01:00
parent 70eac10eaa
commit 27586b5ff0
6 changed files with 297 additions and 30 deletions

View File

@@ -0,0 +1,143 @@
#!/usr/bin/env python3
import os.path
from helpers import *
def test_worktree_never_clean_persistent_branches():
with TempGitRepositoryWorktree() as base_dir:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
f.write(
"""
persistent_branches = [
"mybranch",
]
"""
)
cmd = grm(["wt", "add", "mybranch", "--track", "origin/master"], cwd=base_dir)
assert cmd.returncode == 0
before = checksum_directory(f"{base_dir}/mybranch")
cmd = grm(["wt", "clean"], cwd=base_dir)
assert cmd.returncode == 0
assert "mybranch" in os.listdir(base_dir)
repo = git.Repo(os.path.join(base_dir, "mybranch"))
assert str(repo.active_branch) == "mybranch"
after = checksum_directory(f"{base_dir}/mybranch")
assert before == after
def test_worktree_clean_branch_merged_into_persistent():
with TempGitRepositoryWorktree() as base_dir:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
f.write(
"""
persistent_branches = [
"master",
]
"""
)
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
assert cmd.returncode == 0
shell(
f"""
cd {base_dir}/test
touch change1
git add change1
git commit -m "commit1"
"""
)
cmd = grm(["wt", "add", "master"], cwd=base_dir)
assert cmd.returncode == 0
shell(
f"""
cd {base_dir}/master
git merge --no-ff test
"""
)
cmd = grm(["wt", "clean"], cwd=base_dir)
assert cmd.returncode == 0
assert "test" not in os.listdir(base_dir)
def test_worktree_no_clean_unmerged_branch():
with TempGitRepositoryWorktree() as base_dir:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
f.write(
"""
persistent_branches = [
"master",
]
"""
)
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
assert cmd.returncode == 0
shell(
f"""
cd {base_dir}/test
touch change1
git add change1
git commit -m "commit1"
git push origin test
"""
)
cmd = grm(["wt", "add", "master"], cwd=base_dir)
assert cmd.returncode == 0
cmd = grm(["wt", "clean"], cwd=base_dir)
assert cmd.returncode == 0
assert "test" in os.listdir(base_dir)
def test_worktree_delete_branch_merged_into_persistent():
with TempGitRepositoryWorktree() as base_dir:
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
f.write(
"""
persistent_branches = [
"master",
]
"""
)
cmd = grm(["wt", "add", "test", "--track", "origin/test"], cwd=base_dir)
assert cmd.returncode == 0
shell(
f"""
cd {base_dir}/test
touch change1
git add change1
git commit -m "commit1"
"""
)
cmd = grm(["wt", "add", "master"], cwd=base_dir)
assert cmd.returncode == 0
shell(
f"""
cd {base_dir}/master
git merge --no-ff test
"""
)
cmd = grm(["wt", "delete", "test"], cwd=base_dir)
assert cmd.returncode == 0
assert "test" not in os.listdir(base_dir)