git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-p4: don't allow cloning into non-empty directories

From
Joel Holdsworth <jholdsworth@nvidia.com>
Date
Jan 5, 2022, 14:06 UTC
Message-ID
<20220105140631.48252-1-jholdsworth@nvidia.com>

Previously, git-p4 would allow users to clone a Perforce repository into a pre-existing git repository. When attempting this, git-p4 would download the Perforce commits (a time consuming process), and would fail at the end during the final git fast-import with a cryptic error message.

This was easy to do inadvertently when running the same git-p4 clone command more than once.

This patch changes the behaviour of git-p4.py so that it matches that of git itself: disallowing all clones into non-empty directories.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
---
 git-p4.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index cb37545455..e15fbe1486 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -4099,12 +4099,19 @@ def run(self, args):
         if not self.cloneDestination:
             self.cloneDestination = self.defaultDestination(args)
 
-        print("Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination))
-
-        if not os.path.exists(self.cloneDestination):
+        if os.path.exists(self.cloneDestination):
+            if (not os.path.isdir(self.cloneDestination) or
+                os.listdir(self.cloneDestination)):
+                die(
+                    "fatal: destination path '{}' already exists and is not "
+                    "an empty directory.".format(self.cloneDestination))
+        else:
             os.makedirs(self.cloneDestination)
         chdir(self.cloneDestination)
 
+        print("Importing from {} into {}".format(
+            ', '.join(depotPaths), self.cloneDestination))
+
         init_cmd = [ "git", "init" ]
         if self.cloneBare:
             init_cmd.append("--bare")
-- 
2.34.1
Message 1 of 1 in “git-p4: don't allow cloning into non-empty directories”
  1. git-p4: don't allow cloning into non-empty directoriesJoel Holdsworth, Jan 5, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.