From: Yann E. MORIN Date: Tue, 17 Apr 2018 16:48:21 +0000 (+0200) Subject: download/git: ensure we have a sane repository X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d48a1b0d5e43c1dee5343f2d5dcbdc5808d8fb2b;p=buildroot.git download/git: ensure we have a sane repository There are cases where a repository might be broken, e.g. when a previous operation was killed or otherwise failed unexpectedly. We fix that by always initialising the repository, as suggested by Ricardo. git-init is safe on an otherwise-healthy repository: Running git init in an existing repository is safe. It will not overwrite things that are already there. [...] Using git-init will just ensure that we have the strictly required files to form a sane tree. Any blob that is still missing would get fetched later on. Reported-by: Thomas Petazzoni Reported-by: Ricardo Martincoski Signed-off-by: "Yann E. MORIN" Cc: Ricardo Martincoski Cc: Maxime Hadjinlian Cc: Arnout Vandecappelle Cc: Thomas Petazzoni Acked-by: Ricardo Martincoski Tested-by: Ricardo Martincoski Signed-off-by: Thomas Petazzoni --- diff --git a/support/download/git b/support/download/git index c166ae2813..1172310186 100755 --- a/support/download/git +++ b/support/download/git @@ -43,14 +43,16 @@ _git() { eval GIT_DIR="${git_cache}/.git" ${GIT} "${@}" } -# If the cache directory doesn't exists, init a new repo, which will be -# fetch'ed later. -if [ ! -d "${git_cache}" ]; then - # We can still go through the wrapper, because 'init' does not use - # the path pointed to by GIT_DIR, but really uses the directory - # passed as argument. - _git init "'${git_cache}'" -fi +# Initialise a repository in the git cache. If the repository already +# existed, this is a noop, unless the repository was broken, in which +# case this magically restores it to working conditions. In the latter +# case, we might be missing blobs, but that's not a problem: we'll +# fetch what we need later anyway. +# +# We can still go through the wrapper, because 'init' does not use the +# path pointed to by GIT_DIR, but really uses the directory passed as +# argument. +_git init "'${git_cache}'" pushd "${git_cache}" >/dev/null