All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Holdsworth <jholdsworth@nvidia.com>
To: git@vger.kernel.org, Luke Diamand <luke@diamand.org>,
	Junio C Hamano <gitster@pobox.com>
Cc: Tzadik Vanderhoof <tzadik.vanderhoof@gmail.com>,
	Dorgon Chang <dorgonman@hotmail.com>,
	Joachim Kuebart <joachim.kuebart@gmail.com>,
	Daniel Levin <dendy.ua@gmail.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Ben Keene <seraphire@gmail.com>,
	Andrew Oakley <andrew@adoakley.name>,
	Joel Holdsworth <jholdsworth@nvidia.com>
Subject: [PATCH] git-p4: don't allow cloning into non-empty directories
Date: Wed,  5 Jan 2022 14:06:31 +0000	[thread overview]
Message-ID: <20220105140631.48252-1-jholdsworth@nvidia.com> (raw)

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


                 reply	other threads:[~2022-01-05 14:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220105140631.48252-1-jholdsworth@nvidia.com \
    --to=jholdsworth@nvidia.com \
    --cc=andrew@adoakley.name \
    --cc=dendy.ua@gmail.com \
    --cc=dorgonman@hotmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=joachim.kuebart@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=luke@diamand.org \
    --cc=seraphire@gmail.com \
    --cc=tzadik.vanderhoof@gmail.com \
    /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.