Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: gclient_scm.py

Issue 19359002: Allow gclient clone in non-empty directories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_scm.py
diff --git a/gclient_scm.py b/gclient_scm.py
index 5a5dc075b3c6c4b5ffb81b11c9702a37e1815dc2..ee1e57ea31d39e75ce3a1d782d63ea81a50372e8 100644
--- a/gclient_scm.py
+++ b/gclient_scm.py
@@ -10,6 +10,7 @@ import os
import posixpath
import re
import sys
+import tempfile
import threading
import time
@@ -350,11 +351,7 @@ class GitWrapper(SCMWrapper):
# hash is also a tag, only make a distinction at checkout
rev_type = "hash"
- if not os.path.exists(self.checkout_path) or (
- os.path.isdir(self.checkout_path) and
- not os.listdir(self.checkout_path)):
- gclient_utils.safe_makedirs(os.path.dirname(self.checkout_path))
- self._Clone(revision, url, options)
+ def PostCloneSteps():
self.UpdateSubmoduleConfig()
if file_list is not None:
files = self._Capture(['ls-files']).splitlines()
@@ -363,7 +360,39 @@ class GitWrapper(SCMWrapper):
# Make the output a little prettier. It's nice to have some whitespace
# between projects when cloning.
print('')
- return
+
+ if (os.path.exists(self.checkout_path) and
+ getattr(options, 'stage_clone', None) and
+ not os.path.exists(os.path.join(self.checkout_path, '.git'))):
+ parent_dir = os.path.dirname(self.checkout_path)
+ gclient_utils.safe_makedirs(parent_dir)
+ try:
+ tmp_dir = tempfile.mkdtemp(
+ suffix='_%s' % os.path.basename(self.checkout_path),
+ dir=parent_dir)
+ self._Clone(revision, url, options, clone_path=tmp_dir)
+ src_files = os.listdir(tmp_dir)
+ overlap = set(src_files).intersection(os.listdir(self.checkout_path))
+ if overlap:
+ raise gclient_utils.Error(
+ "%s clone failure. Files exist: %s" % (
+ self.checkout_path, sorted(overlap)))
+ print('\n_____ copying %s -> %s' % (tmp_dir, self.checkout_path))
+ for src_file in src_files:
+ os.rename(os.path.join(tmp_dir, src_file),
+ os.path.join(self.checkout_path, src_file))
+ return PostCloneSteps()
+ finally:
+ if os.path.exists(tmp_dir):
+ if os.listdir(tmp_dir):
+ print('\n_____ removing non-empty tmp dir %s' % tmp_dir)
+ gclient_utils.rmtree(tmp_dir)
+ elif not os.path.exists(self.checkout_path) or (
+ os.path.isdir(self.checkout_path) and
+ not os.listdir(self.checkout_path)):
+ gclient_utils.safe_makedirs(os.path.dirname(self.checkout_path))
+ self._Clone(revision, url, options)
+ return PostCloneSteps()
if not managed:
self._UpdateBranchHeads(options, fetch=False)
@@ -412,7 +441,7 @@ class GitWrapper(SCMWrapper):
self._Run(['-c', 'core.deltaBaseCacheLimit=2g', 'pull', 'origin',
'master'], options)
self._FetchAndReset(revision, file_list, options)
-
+
M-A Ruel 2013/07/16 13:46:32 .
cur_branch = self._GetCurrentBranch()
# Cases:
@@ -774,7 +803,7 @@ class GitWrapper(SCMWrapper):
options, git_filter=True, filter_fn=filter_fn, cwd=folder)
return folder
- def _Clone(self, revision, url, options):
+ def _Clone(self, revision, url, options, clone_path=None):
"""Clone a git repository from the given URL.
Once we've cloned the repo, we checkout a working branch if the specified
@@ -799,7 +828,7 @@ class GitWrapper(SCMWrapper):
detach_head = True
if options.verbose:
clone_cmd.append('--verbose')
- clone_cmd.extend([url, self.checkout_path])
+ clone_cmd.extend([url, clone_path or self.checkout_path])
# If the parent directory does not exist, Git clone on Windows will not
# create it, so we need to do it manually.
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698