Commit 30effd17 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Remove lcam nonsense from pre_commit_run test fixtures

Replace the (only) entry in "lcam" (last common ancestor mapping) with
a simple branch ref pointing at the last common ancestor.  Not only
simpler and easier to understand, but needed for the next upcoming
test…
parent 313e7ad8
Loading
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ Sha = NewType("Sha", str)

MAIN = Ref("main")
FORK = Ref("fork")
LCA = Ref("lca")
ORPHAN = Ref("orphan")


@@ -43,7 +44,6 @@ class Branch:
		self.name = Ref(name)
		self.head = root
		self.root = root
		self.lcam = dict[Ref, Sha]()

	@property
	def head(self) -> Sha:
@@ -141,7 +141,7 @@ def setup_fixture_repo(repo: Repo) -> dict[Ref, Branch]:
	commonality with the other two:

	┌──────────────────────────────────┐
      Last common ancestor  
"lca" (Last common ancestor)
	│           ↓                      │
	│   ○─○─○─○─○─○─○─○─○─● "main"
	│           └─○─○─○─○─● "fork"
@@ -153,17 +153,16 @@ def setup_fixture_repo(repo: Repo) -> dict[Ref, Branch]:
	root = create_commit(repo)
	main = Branch(repo, MAIN, root)
	fork = Branch(repo, FORK, root)
	lca = Branch(repo, LCA, root)

	lca = create_commit_path(repo, root, 5)
	main.lcam[fork.name] = fork.lcam[main.name] = lca

	main.head = create_commit_path(repo, lca, 5)
	fork.head = create_commit_path(repo, lca, 5)
	lca.head = create_commit_path(repo, root, 5)
	main.head = create_commit_path(repo, lca.head, 5)
	fork.head = create_commit_path(repo, lca.head, 5)

	orphan = Branch(repo, ORPHAN, create_commit(repo))
	orphan.head = create_commit_path(repo, orphan.root, 5)

	return {b.name: b for b in (main, fork, orphan)}
	return {b.name: b for b in (main, fork, lca, orphan)}


def create_commit_path(repo: Repo, source: Sha, number: int) -> Sha:
+5 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ from typing import Iterable
from typing import Mapping

from .fixtures import FORK
from .fixtures import LCA
from .fixtures import MAIN
from .fixtures import ORPHAN
from .fixtures import Branch
@@ -130,8 +131,8 @@ class PreCommitRunTests(unittest.TestCase):
			CI_MERGE_REQUEST_TARGET_BRANCH_NAME=MAIN,
		)

		lca = self.branches[MAIN].lcam[FORK]
		expect = ["run", f"--from-ref={lca}", f"--to-ref={env['CI_COMMIT_SHA']}"]
		lca = self.branches[LCA]
		expect = ["run", f"--from-ref={lca.head}", f"--to-ref={env['CI_COMMIT_SHA']}"]
		self.assertListEqual(expect, args)

	def test_new_branch(self) -> None:
@@ -146,8 +147,8 @@ class PreCommitRunTests(unittest.TestCase):
			CI_COMMIT_BEFORE_SHA="0" * 40,
		)

		lca = self.branches[MAIN].lcam[FORK]
		expect = ["run", f"--from-ref={lca}", f"--to-ref={env['CI_COMMIT_SHA']}"]
		lca = self.branches[LCA]
		expect = ["run", f"--from-ref={lca.head}", f"--to-ref={env['CI_COMMIT_SHA']}"]
		self.assertListEqual(expect, args)

	def test_new_default_branch(self) -> None: