def test_find_git_root_submodule(self): with tempfile.TemporaryDirectory() as tempdir: cime_path = os.path.join(tempdir, "cime") os.makedirs(cime_path) cime_git_dot_file = os.path.join(cime_path, ".git") with open(cime_git_dot_file, "w") as fd: fd.write(f"gitdir: {tempdir}/.git/modules/cime") temp_dot_git_path = os.path.join(tempdir, ".git", "modules", "cime") os.makedirs(temp_dot_git_path) temp_config = os.path.join(temp_dot_git_path, "config") with open(temp_config, "w") as fd: fd.write("") value = provenance._find_git_root(cime_path) assert value == f"{tempdir}/.git/modules/cime" # relative path with open(cime_git_dot_file, "w") as fd: fd.write(f"gitdir: ../.git/modules/cime") value = provenance._find_git_root(cime_path) assert value == f"{tempdir}/.git/modules/cime"
def test_find_git_root_worktree_bad_contents(self): with tempfile.TemporaryDirectory() as tempdir: with open(os.path.join(tempdir, ".git"), "w") as fd: fd.write("some value: /src/CIME/.git/worktrees/test") with self.assertRaises(utils.CIMEError): provenance._find_git_root(tempdir)
def test_find_git_root(self): with tempfile.TemporaryDirectory() as tempdir: os.makedirs(os.path.join(tempdir, ".git")) value = provenance._find_git_root(tempdir) assert value == f"{tempdir}/.git"
def test_find_git_root_worktree(self): with tempfile.TemporaryDirectory() as tempdir: git_dot_file = os.path.join(tempdir, ".git") with open(git_dot_file, "w") as fd: fd.write("gitdir: /src/CIME/.git/worktrees/test") value = provenance._find_git_root(tempdir) assert value == "/src/CIME/.git"
def test_find_git_root_does_not_exist(self): with tempfile.TemporaryDirectory() as tempdir: with self.assertRaises(utils.CIMEError): provenance._find_git_root(tempdir)