# HG changeset patch # User Pierre-Yves David # Date 2021-06-08 01:40:36 # Node ID 1c7f3d911d0fa67db85117c35f30c29ff48217e3 # Parent b1b3127227bed218bfded147414966db3c265131 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 diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -825,7 +825,12 @@ def clone( 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 @@ def clone( 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)