From 068a598025e925fc6268f6ed561ca2da102b10ef Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Tue, 14 May 2019 18:57:40 +1000 Subject: [PATCH] Ensure shallow repo mirror is updated when the git ref changes Shallow clones only contain the ref that was cloned, and so if a mirror is shallow and the ref is changed in a subsequent invocation of builder, the new ref is absent and git fails with an error. This patch avoids bailing out too soon when mirroring a repo if the requested ref does not exist, to ensure it is fetched. Fixes #285 Closes: #286 Approved by: alexlarsson --- src/builder-git.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/builder-git.c b/src/builder-git.c index a77000bd..ef517adb 100644 --- a/src/builder-git.c +++ b/src/builder-git.c @@ -531,8 +531,10 @@ builder_git_mirror_repo (const char *repo_location, else cached_git_dir = g_object_ref (cache_mirror_dir); - /* If we're not updating, only pull from cache to avoid network i/o */ - if (!update) + /* If the ref already exists (it may not with a shallow mirror + * if it has changed) and we're not updating, only pull from + * cache to avoid network i/o. */ + if (already_exists && !update) { if (cached_git_dir) origin = g_file_get_uri (cached_git_dir);