From e3896043a59211017b5e7f9e94204879b2f3a12d Mon Sep 17 00:00:00 2001 From: James Bruten <109733895+james-bruten-mo@users.noreply.github.com> Date: Tue, 17 Feb 2026 13:59:54 +0000 Subject: [PATCH 1/6] check for .git --- github_scripts/get_git_sources.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index 6b4d26ca..24fbc418 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -184,8 +184,11 @@ def merge_source( f"{source} at ref {ref} into {repo}" ) - if use_mirrors: - remote_path = Path(mirror_loc) / "MetOffice" / repo + if ".git" in source: + if use_mirrors: + remote_path = Path(mirror_loc) / "MetOffice" / repo + else: + remote_path = source else: remote_path = source run_command(f"git -C {dest} remote add local {remote_path}") From 9156e31a16be3e6b8d0631e1afffd7fbfb8db183 Mon Sep 17 00:00:00 2001 From: James Bruten <109733895+james-bruten-mo@users.noreply.github.com> Date: Tue, 17 Feb 2026 14:21:32 +0000 Subject: [PATCH 2/6] update fetch --- github_scripts/get_git_sources.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index 24fbc418..d062d732 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -184,21 +184,17 @@ def merge_source( f"{source} at ref {ref} into {repo}" ) - if ".git" in source: - if use_mirrors: - remote_path = Path(mirror_loc) / "MetOffice" / repo - else: - remote_path = source - else: - remote_path = source - run_command(f"git -C {dest} remote add local {remote_path}") - - if use_mirrors: + if ".git" in source and use_mirrors: + remote_path = Path(mirror_loc) / "MetOffice" / repo fetch = determine_mirror_fetch(source, ref) else: + remote_path = source 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: From eab491d8eec0e0a63e8d8100800d44f4bbc32c39 Mon Sep 17 00:00:00 2001 From: James Bruten <109733895+james-bruten-mo@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:07:20 +0000 Subject: [PATCH 3/6] update fetch --- github_scripts/get_git_sources.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index d062d732..d02678a9 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -184,10 +184,16 @@ def merge_source( f"{source} at ref {ref} into {repo}" ) - if ".git" in source and use_mirrors: - remote_path = Path(mirror_loc) / "MetOffice" / repo - fetch = determine_mirror_fetch(source, ref) + if ".git" in 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") remote_path = source fetch = ref From aad9e2f034a58643b0db3834af912c34f611139f Mon Sep 17 00:00:00 2001 From: James Bruten <109733895+james-bruten-mo@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:20:55 +0000 Subject: [PATCH 4/6] update error message --- github_scripts/get_git_sources.py | 6 +++++- github_scripts/tests/test_get_git_sources.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index d02678a9..939b6b46 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -193,7 +193,11 @@ def merge_source( fetch = ref else: if not ref: - raise Exception(f"Cannot merge local source '{source}' with empty ref") + raise Exception( + f"Cannot merge local source '{source}' with empty ref.\n" + "It is likely you desire a branch name which will always merge the " + "latest commits to a branch." + ) remote_path = source fetch = ref 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): From e5bdb4714dfe41616a84eb4ff055df436b487e97 Mon Sep 17 00:00:00 2001 From: James Bruten <109733895+james-bruten-mo@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:26:28 +0000 Subject: [PATCH 5/6] fix syntax --- github_scripts/get_git_sources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index 939b6b46..afaf3079 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -184,7 +184,7 @@ def merge_source( f"{source} at ref {ref} into {repo}" ) - if ".git" in source: + if ".git" in str(source): if use_mirrors: remote_path = Path(mirror_loc) / "MetOffice" / repo fetch = determine_mirror_fetch(source, ref) From fd412652f4c61ef03450773f67eb0425afab6b7c Mon Sep 17 00:00:00 2001 From: James Bruten <109733895+james-bruten-mo@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:19:53 +0000 Subject: [PATCH 6/6] clarify error --- github_scripts/get_git_sources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github_scripts/get_git_sources.py b/github_scripts/get_git_sources.py index afaf3079..80374c13 100644 --- a/github_scripts/get_git_sources.py +++ b/github_scripts/get_git_sources.py @@ -195,8 +195,8 @@ def merge_source( if not ref: raise Exception( f"Cannot merge local source '{source}' with empty ref.\n" - "It is likely you desire a branch name which will always merge the " - "latest commits to a branch." + "Please enter a valid git ref - if you use a branch, then the latest " + "commit to that branch will be used." ) remote_path = source fetch = ref