diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index 6b4d26ca..80374c13 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -184,18 +184,27 @@ def merge_source( f"{source} at ref {ref} into {repo}" ) - if use_mirrors: - remote_path = Path(mirror_loc) / "MetOffice" / repo + if ".git" in str(source): + if use_mirrors: + remote_path = Path(mirror_loc) / "MetOffice" / repo + fetch = determine_mirror_fetch(source, ref) + else: + remote_path = source + fetch = ref else: + if not ref: + raise Exception( + f"Cannot merge local source '{source}' with empty ref.\n" + "Please enter a valid git ref - if you use a branch, then the latest " + "commit to that branch will be used." + ) remote_path = source - run_command(f"git -C {dest} remote add local {remote_path}") - - if use_mirrors: - fetch = determine_mirror_fetch(source, ref) - else: fetch = ref + run_command(f"git -C {dest} remote add local {remote_path}") + run_command(f"git -C {dest} fetch local {fetch}") + command = f"git -C {dest} merge --no-gpg-sign FETCH_HEAD" result = run_command(command, check=False) if result.returncode: diff --git a/github_scripts/tests/test_get_git_sources.py b/github_scripts/tests/test_get_git_sources.py index ba0e1787..ea6685b1 100644 --- a/github_scripts/tests/test_get_git_sources.py +++ b/github_scripts/tests/test_get_git_sources.py @@ -120,6 +120,7 @@ def test_merge_sources(setup_sources): target_clone = setup_sources / "SimSys_Scripts" + # Test Remote Source merges cleanly assert ( merge_source( "https://github.com/MetOffice/SimSys_Scripts.git", @@ -129,12 +130,17 @@ def test_merge_sources(setup_sources): ) is None ) + # Test Local Source Merges Cleanly assert ( merge_source(setup_sources / "merge0", "merge0", target_clone, "SimSys_Scripts") is None ) + # Test Local Source Doesn't Merge with pytest.raises(RuntimeError): merge_source(setup_sources / "merge1", "merge1", target_clone, "SimSys_Scripts") + # Test Local Source without ref raises error + with pytest.raises(Exception): + merge_source(setup_sources / "merge0", "", target_clone, "SimSys_Scripts") def test_check_exists(setup_sources):