Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions github_scripts/get_git_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions github_scripts/tests/test_get_git_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand Down