From: Joshua Watt <jpewhacker@gmail.com>
To: bitbake-devel@lists.openembedded.org
Cc: Joshua Watt <JPEWhacker@gmail.com>
Subject: [bitbake-devel][PATCH] fetch2: git: Check if directory is a bare git repo
Date: Fri, 4 Aug 2023 09:54:24 -0600 [thread overview]
Message-ID: <20230804155424.1502010-1-JPEWhacker@gmail.com> (raw)
If the clone target directory exists, but isn't the valid top level of a
bare git repo, it needs to be erased and re-cloned. One example of how
this can happen is if a clone creates the directory, but then fails to
actual clone and make it a git repository. This left-over directory can
be particularly problematic if the download directory is a descent of
some top layer git repo (e.g. the default with poky), as the commands
that operate on the remote later will then mangle the layers git
repository instead of the download git repo.
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
bitbake/lib/bb/fetch2/git.py | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 2a3c06fe4e9..112bed294f0 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -65,6 +65,7 @@ import fnmatch
import os
import re
import shlex
+import shutil
import subprocess
import tempfile
import bb
@@ -365,8 +366,29 @@ class Git(FetchMethod):
runfetchcmd(fetch_cmd, d, workdir=ud.clonedir)
repourl = self._get_repo_url(ud)
+ needs_clone = False
+ if os.path.exists(ud.clonedir):
+ # The directory may exist, but not be the top level of a bare git
+ # repository in which case it needs to be deleted and re-cloned.
+ try:
+ # Since clones are bare, use --absolute-git-dir instead of --show-toplevel
+ output = runfetchcmd("LANG=C %s rev-parse --absolute-git-dir" % ud.basecmd, d, workdir=ud.clonedir)
+ except bb.fetch2.FetchError as e:
+ logger.warning("Unable to get top level for %s (not a git directory?): %s", ud.clonedir, e)
+ needs_clone = True
+ else:
+ toplevel = output.rstrip()
+ if os.path.abspath(toplevel) != os.path.abspath(ud.clonedir):
+ logger.warning("Top level directory '%s' doesn't match expected '%s'. Re-cloning", toplevel, ud.clonedir)
+ needs_clone = True
+
+ if needs_clone:
+ shutil.rmtree(ud.clonedir)
+ else:
+ needs_clone = True
+
# If the repo still doesn't exist, fallback to cloning it
- if not os.path.exists(ud.clonedir):
+ if needs_clone:
# We do this since git will use a "-l" option automatically for local urls where possible,
# but it doesn't work when git/objects is a symlink, only works when it is a directory.
if repourl.startswith("file://"):
--
2.33.0
next reply other threads:[~2023-08-04 15:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-04 15:54 Joshua Watt [this message]
2023-08-09 1:52 ` [bitbake-devel][PATCH] fetch2: git: Check if directory is a bare git repo Alexandre Belloni
2023-08-17 19:19 ` Joshua Watt
2023-08-17 20:14 ` Alexandre Belloni
[not found] ` <177C44DDA5F18A0D.21730@lists.openembedded.org>
2023-08-19 12:21 ` Alexandre Belloni
2023-08-24 19:54 ` Joshua Watt
2023-08-24 19:53 ` [bitbake-devel][PATCH v2] fetch2: git: Check if clone directory is a " Joshua Watt
2023-08-25 9:18 ` Paulo Neves
2023-08-25 14:19 ` Joshua Watt
2023-08-31 12:21 ` Paulo Neves
2023-08-31 14:27 ` Joshua Watt
[not found] ` <177E95B06B95EDA3.23833@lists.openembedded.org>
2023-08-25 9:33 ` Paulo Neves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230804155424.1502010-1-JPEWhacker@gmail.com \
--to=jpewhacker@gmail.com \
--cc=bitbake-devel@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.