aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2024-09-02 12:12:55 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2024-09-02 12:12:55 +0300
commit8b1a9523bd5050a51310a04bec6c0a2065d2b04b (patch)
treec9375101bbebb707946f4a4e73c7508817e76c19
parentf018d0f96577fc3589e6e1d2d480e709105a23f7 (diff)
Fix "ambiguous argument 'FETCH_HEAD'" error which appeared after git-fetch fails and makes FETCH_HEAD file empty
-rw-r--r--load/load-with-metadata.in9
1 files 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'"