Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/git_rebase_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ def cli(parser: Optional[argparse.ArgumentParser] = None) -> argparse.ArgumentPa
def branches_that_do_not_contain(ref: str, /) -> list[str]:
"""Get a list of branches that do not contain a given ref."""
result = run(
["git", "branch", "--no-contains", ref, "--format=%(refname:short)"],
[
"git",
"for-each-ref",
"--no-contains",
ref,
"--format=%(refname:short)",
"refs/heads/",
],
capture_output=True,
check=True,
encoding="utf-8",
Expand Down
18 changes: 11 additions & 7 deletions tests/test_git_rebase_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ def branch_commit():
}


def test_git_rebase_branches(tmp_path, monkeypatch):
@pytest.mark.parametrize("detached", [False, True])
def test_git_rebase_branches(tmp_path, monkeypatch, detached):
"""Test a basic example."""
base_ref = "main"
branch_no_contains = "init"
branch_contains = "latest"

monkeypatch.chdir(tmp_path)
commit_opts = ["--allow-empty"]
for git_command in [
commands = [
["init", "-b", base_ref],
["config", "commit.gpgsign", "false"],
["config", "user.name", "Coder Joe"],
Expand All @@ -51,14 +52,17 @@ def test_git_rebase_branches(tmp_path, monkeypatch):
["branch", branch_no_contains],
["commit"] + commit_opts + ["-m", "New Commit on main"],
["branch", branch_contains],
]:
]
if detached:
commands.append(["switch", "-d", branch_no_contains])
for git_command in commands:
subprocess.run(["git"] + git_command, check=True)

head = git_rebase_branches.ref_commit("HEAD")
commit = git_rebase_branches.ref_commit(base_ref)
target_state = {
base_ref: head,
branch_no_contains: head,
branch_contains: head,
base_ref: commit,
branch_no_contains: commit,
branch_contains: commit,
}
assert branch_commit() != target_state

Expand Down