All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-p4: don't allow cloning into non-empty directories
@ 2022-01-05 14:06 Joel Holdsworth
  0 siblings, 0 replies; only message in thread
From: Joel Holdsworth @ 2022-01-05 14:06 UTC (permalink / raw)
  To: git, Luke Diamand, Junio C Hamano
  Cc: Tzadik Vanderhoof, Dorgon Chang, Joachim Kuebart, Daniel Levin,
	Johannes Schindelin, Ben Keene, Andrew Oakley, Joel Holdsworth

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-05 14:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 14:06 [PATCH] git-p4: don't allow cloning into non-empty directories Joel Holdsworth

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.