From 8b1a9523bd5050a51310a04bec6c0a2065d2b04b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 2 Sep 2024 12:12:55 +0300 Subject: Fix "ambiguous argument 'FETCH_HEAD'" error which appeared after git-fetch fails and makes FETCH_HEAD file empty --- load/load-with-metadata.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/load/load-with-metadata.in b/load/load-with-metadata.in index 293f8db..01ccd16 100644 --- a/load/load-with-metadata.in +++ b/load/load-with-metadata.in @@ -99,11 +99,14 @@ if ! remote_url="$(git -C "$repo_dir" config --get remote.origin.url)"; then error "'$repo_dir' is not a git repository" fi -# Save the repository name and branch of where the latest commit has been +# Save the repository name and branch of where the current commit has been # fetched from, separated by space. For example 'origin master'. # -refs=$(git -C "$repo_dir" log -1 --format=%D FETCH_HEAD) -repo_branch="$(sed -n -E 's%^.+ ([^/ ]+)/([^/ ]+)$%\1 \2%p' <<<"$refs")" +# Note that if the commit belongs to multiple repositories/branches, then we +# extract the first their pair from the git-log output. +# +refs=$(git -C "$repo_dir" log -1 --format=%D) +repo_branch="$(sed -n -E 's%^[^/]+ ([^/ ]+)/([^/ ,]+).*$%\1 \2%p' <<<"$refs")" if [[ -z "$repo_branch" ]]; then error "unable to extract repository and branch from '$refs'" -- cgit v1.1