clone: cleanup the "cleanup dir" logic used during local clone
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 08 Jun 2021 03:40:36 +0200
changeset 47416 1c7f3d911d0f
parent 47415 b1b3127227be
child 47417 9ea525216edb
clone: cleanup the "cleanup dir" logic used during local clone With the previous code, there was a small windows were we could delete too much data. This should no longer be the case. (This is an opportunity improvement while looking at something next to that.) Differential Revision: https://phab.mercurial-scm.org/D10840
mercurial/hg.py
--- a/mercurial/hg.py	Fri Apr 09 17:04:39 2021 +0200
+++ b/mercurial/hg.py	Tue Jun 08 03:40:36 2021 +0200
@@ -825,7 +825,12 @@
             abspath = os.path.abspath(urlutil.urllocalpath(origsource))
 
         if islocal(dest):
-            cleandir = dest
+            if os.path.exists(dest):
+                # only clean up directories we create ourselves
+                hgdir = os.path.realpath(os.path.join(dest, b".hg"))
+                cleandir = hgdir
+            else:
+                cleandir = dest
 
         copy = False
         if (
@@ -855,9 +860,6 @@
             hgdir = os.path.realpath(os.path.join(dest, b".hg"))
             if not os.path.exists(dest):
                 util.makedirs(dest)
-            else:
-                # only clean up directories we create ourselves
-                cleandir = hgdir
             try:
                 destpath = hgdir
                 util.makedir(destpath, notindexed=True)