Commit cc19ce9d authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add pre_commit_run test for finding LCA when other branch is an ancestor

parent 30effd17
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -191,3 +191,23 @@ class PreCommitRunTests(unittest.TestCase):

		expect = ["run", "more", "arguments", "--all-files"]
		self.assertListEqual(expect, args)

	def test_comparison_branch_is_ancestor(self) -> None:
		"""
		Check find_lca works when the branch to assess against is a direct ancestor

		Regression test for an issue where an error was reported when calling:
			git fetch <repo> --shallow-exclude=<ancestor> <current-branch>

		Depending on transport the error was:
			ssh or file: "fatal: no commits selected for shallow requests"
			http: "fatal: error processing shallow info: 4"
		"""
		args, env = self.run_script(
			MAIN,
			CI_MERGE_REQUEST_TARGET_BRANCH_NAME=LCA,
		)

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