blob: 97495fbb9bb97f48cb80df9791ba6ba38cd2f0e9 [file] [log] [blame]
[email protected]93567042012-02-15 01:02:261# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5aeb7dd2009-11-17 18:09:012# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
[email protected]5f3eee32009-09-17 00:34:304
[email protected]d5800f12009-11-12 20:03:435"""Gclient-specific SCM-specific operations."""
[email protected]5f3eee32009-09-17 00:34:306
[email protected]fe0d1902014-04-08 20:50:447from __future__ import print_function
8
[email protected]b2256212014-05-07 20:57:289import errno
[email protected]754960e2009-09-21 12:31:0510import logging
[email protected]5f3eee32009-09-17 00:34:3011import os
[email protected]ee4071d2009-12-22 22:25:3712import posixpath
[email protected]5f3eee32009-09-17 00:34:3013import re
[email protected]90541732011-04-01 17:54:1814import sys
[email protected]3534aa52013-07-20 01:58:0815import tempfile
[email protected]6279e8a2014-02-13 01:45:2516import traceback
[email protected]2f2ca142014-01-07 03:59:1817import urlparse
[email protected]5f3eee32009-09-17 00:34:3018
[email protected]2f2ca142014-01-07 03:59:1819import download_from_google_storage
[email protected]5f3eee32009-09-17 00:34:3020import gclient_utils
[email protected]848fd492014-04-09 19:06:4421import git_cache
[email protected]31cb48a2011-04-04 18:01:3622import scm
[email protected]b2256212014-05-07 20:57:2823import shutil
[email protected]31cb48a2011-04-04 18:01:3624import subprocess2
[email protected]5f3eee32009-09-17 00:34:3025
26
[email protected]71cbb502013-04-19 23:30:1527THIS_FILE_PATH = os.path.abspath(__file__)
28
[email protected]2f2ca142014-01-07 03:59:1829GSUTIL_DEFAULT_PATH = os.path.join(
30 os.path.dirname(os.path.abspath(__file__)),
31 'third_party', 'gsutil', 'gsutil')
32
[email protected]848fd492014-04-09 19:06:4433CHROMIUM_SRC_URL = 'https://chromium.googlesource.com/chromium/src.git'
[email protected]306080c2012-05-04 13:11:2934class DiffFiltererWrapper(object):
35 """Simple base class which tracks which file is being diffed and
[email protected]ee4071d2009-12-22 22:25:3736 replaces instances of its file name in the original and
[email protected]d6504212010-01-13 17:34:3137 working copy lines of the svn/git diff output."""
[email protected]306080c2012-05-04 13:11:2938 index_string = None
[email protected]ee4071d2009-12-22 22:25:3739 original_prefix = "--- "
40 working_prefix = "+++ "
41
[email protected]fe0d1902014-04-08 20:50:4442 def __init__(self, relpath, print_func):
[email protected]ee4071d2009-12-22 22:25:3743 # Note that we always use '/' as the path separator to be
44 # consistent with svn's cygwin-style output on Windows
45 self._relpath = relpath.replace("\\", "/")
[email protected]306080c2012-05-04 13:11:2946 self._current_file = None
[email protected]fe0d1902014-04-08 20:50:4447 self._print_func = print_func
[email protected]ee4071d2009-12-22 22:25:3748
[email protected]6e29d572010-06-04 17:32:2049 def SetCurrentFile(self, current_file):
50 self._current_file = current_file
[email protected]306080c2012-05-04 13:11:2951
[email protected]3830a672013-02-19 20:15:1452 @property
53 def _replacement_file(self):
[email protected]306080c2012-05-04 13:11:2954 return posixpath.join(self._relpath, self._current_file)
[email protected]ee4071d2009-12-22 22:25:3755
[email protected]f5d37bf2010-09-02 00:50:3456 def _Replace(self, line):
57 return line.replace(self._current_file, self._replacement_file)
[email protected]ee4071d2009-12-22 22:25:3758
59 def Filter(self, line):
60 if (line.startswith(self.index_string)):
61 self.SetCurrentFile(line[len(self.index_string):])
[email protected]f5d37bf2010-09-02 00:50:3462 line = self._Replace(line)
[email protected]ee4071d2009-12-22 22:25:3763 else:
64 if (line.startswith(self.original_prefix) or
65 line.startswith(self.working_prefix)):
[email protected]f5d37bf2010-09-02 00:50:3466 line = self._Replace(line)
[email protected]fe0d1902014-04-08 20:50:4467 self._print_func(line)
[email protected]ee4071d2009-12-22 22:25:3768
69
[email protected]306080c2012-05-04 13:11:2970class SvnDiffFilterer(DiffFiltererWrapper):
71 index_string = "Index: "
72
73
74class GitDiffFilterer(DiffFiltererWrapper):
75 index_string = "diff --git "
76
77 def SetCurrentFile(self, current_file):
78 # Get filename by parsing "a/<filename> b/<filename>"
79 self._current_file = current_file[:(len(current_file)/2)][2:]
80
81 def _Replace(self, line):
82 return re.sub("[a|b]/" + self._current_file, self._replacement_file, line)
83
84
[email protected]5f3eee32009-09-17 00:34:3085### SCM abstraction layer
86
[email protected]cb5442b2009-09-22 16:51:2487# Factory Method for SCM wrapper creation
88
[email protected]9eda4112010-06-11 18:56:1089def GetScmName(url):
90 if url:
91 url, _ = gclient_utils.SplitUrlRevision(url)
92 if (url.startswith('git://') or url.startswith('ssh://') or
[email protected]4e075672011-11-21 16:35:0893 url.startswith('git+http://') or url.startswith('git+https://') or
[email protected]a2aec972014-04-22 21:35:1594 url.endswith('.git') or url.startswith('sso://') or
95 'googlesource' in url):
[email protected]9eda4112010-06-11 18:56:1096 return 'git'
[email protected]b74dca22010-06-11 20:10:4097 elif (url.startswith('http://') or url.startswith('https://') or
[email protected]54a07a22010-06-14 19:07:3998 url.startswith('svn://') or url.startswith('svn+ssh://')):
[email protected]9eda4112010-06-11 18:56:1099 return 'svn'
100 return None
101
102
[email protected]fe0d1902014-04-08 20:50:44103def CreateSCM(url, root_dir=None, relpath=None, out_fh=None, out_cb=None):
[email protected]9eda4112010-06-11 18:56:10104 SCM_MAP = {
[email protected]cb5442b2009-09-22 16:51:24105 'svn' : SVNWrapper,
[email protected]e28e4982009-09-25 20:51:45106 'git' : GitWrapper,
[email protected]cb5442b2009-09-22 16:51:24107 }
[email protected]e28e4982009-09-25 20:51:45108
[email protected]9eda4112010-06-11 18:56:10109 scm_name = GetScmName(url)
110 if not scm_name in SCM_MAP:
111 raise gclient_utils.Error('No SCM found for url %s' % url)
[email protected]9e3e82c2012-04-18 12:55:43112 scm_class = SCM_MAP[scm_name]
113 if not scm_class.BinaryExists():
114 raise gclient_utils.Error('%s command not found' % scm_name)
[email protected]fe0d1902014-04-08 20:50:44115 return scm_class(url, root_dir, relpath, out_fh, out_cb)
[email protected]cb5442b2009-09-22 16:51:24116
117
118# SCMWrapper base class
119
[email protected]5f3eee32009-09-17 00:34:30120class SCMWrapper(object):
121 """Add necessary glue between all the supported SCM.
122
[email protected]d6504212010-01-13 17:34:31123 This is the abstraction layer to bind to different SCM.
124 """
[email protected]fe0d1902014-04-08 20:50:44125
126 def __init__(self, url=None, root_dir=None, relpath=None, out_fh=None,
127 out_cb=None):
[email protected]5f3eee32009-09-17 00:34:30128 self.url = url
[email protected]5e73b0c2009-09-18 19:47:48129 self._root_dir = root_dir
130 if self._root_dir:
131 self._root_dir = self._root_dir.replace('/', os.sep)
132 self.relpath = relpath
133 if self.relpath:
134 self.relpath = self.relpath.replace('/', os.sep)
[email protected]e28e4982009-09-25 20:51:45135 if self.relpath and self._root_dir:
136 self.checkout_path = os.path.join(self._root_dir, self.relpath)
[email protected]fe0d1902014-04-08 20:50:44137 if out_fh is None:
138 out_fh = sys.stdout
139 self.out_fh = out_fh
140 self.out_cb = out_cb
141
142 def Print(self, *args, **kwargs):
143 kwargs.setdefault('file', self.out_fh)
144 if kwargs.pop('timestamp', True):
145 self.out_fh.write('[%s] ' % gclient_utils.Elapsed())
146 print(*args, **kwargs)
[email protected]5f3eee32009-09-17 00:34:30147
[email protected]5f3eee32009-09-17 00:34:30148 def RunCommand(self, command, options, args, file_list=None):
[email protected]6e043f72011-05-02 07:24:32149 commands = ['cleanup', 'update', 'updatesingle', 'revert',
[email protected]4b5b1772010-04-08 01:52:56150 'revinfo', 'status', 'diff', 'pack', 'runhooks']
[email protected]5f3eee32009-09-17 00:34:30151
152 if not command in commands:
153 raise gclient_utils.Error('Unknown command %s' % command)
154
[email protected]cb5442b2009-09-22 16:51:24155 if not command in dir(self):
[email protected]ee4071d2009-12-22 22:25:37156 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % (
[email protected]9eda4112010-06-11 18:56:10157 command, self.__class__.__name__))
[email protected]cb5442b2009-09-22 16:51:24158
159 return getattr(self, command)(options, args, file_list)
160
[email protected]fa2b9b42014-08-22 18:08:53161 @staticmethod
162 def _get_first_remote_url(checkout_path):
163 log = scm.GIT.Capture(
164 ['config', '--local', '--get-regexp', r'remote.*.url'],
165 cwd=checkout_path)
166 # Get the second token of the first line of the log.
167 return log.splitlines()[0].split(' ', 1)[1]
168
[email protected]d33eab32014-07-07 19:35:18169 def GetActualRemoteURL(self, options):
[email protected]88d10082014-03-21 17:24:48170 """Attempt to determine the remote URL for this SCMWrapper."""
[email protected]d33eab32014-07-07 19:35:18171 # Git
[email protected]bda475e2014-03-24 19:04:45172 if os.path.exists(os.path.join(self.checkout_path, '.git')):
[email protected]fa2b9b42014-08-22 18:08:53173 actual_remote_url = self._get_first_remote_url(self.checkout_path)
[email protected]4e9be262014-04-08 19:40:30174
175 # If a cache_dir is used, obtain the actual remote URL from the cache.
176 if getattr(self, 'cache_dir', None):
[email protected]46d09f62014-04-10 18:50:23177 url, _ = gclient_utils.SplitUrlRevision(self.url)
178 mirror = git_cache.Mirror(url)
[email protected]848fd492014-04-09 19:06:44179 if (mirror.exists() and mirror.mirror_path.replace('\\', '/') ==
[email protected]4e9be262014-04-08 19:40:30180 actual_remote_url.replace('\\', '/')):
[email protected]fa2b9b42014-08-22 18:08:53181 actual_remote_url = self._get_first_remote_url(mirror.mirror_path)
[email protected]4e9be262014-04-08 19:40:30182 return actual_remote_url
183
184 # Svn
[email protected]bda475e2014-03-24 19:04:45185 if os.path.exists(os.path.join(self.checkout_path, '.svn')):
[email protected]88d10082014-03-21 17:24:48186 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL']
[email protected]88d10082014-03-21 17:24:48187 return None
188
[email protected]4e9be262014-04-08 19:40:30189 def DoesRemoteURLMatch(self, options):
[email protected]88d10082014-03-21 17:24:48190 """Determine whether the remote URL of this checkout is the expected URL."""
191 if not os.path.exists(self.checkout_path):
192 # A checkout which doesn't exist can't be broken.
193 return True
194
[email protected]d33eab32014-07-07 19:35:18195 actual_remote_url = self.GetActualRemoteURL(options)
[email protected]88d10082014-03-21 17:24:48196 if actual_remote_url:
[email protected]8156c9f2014-04-01 16:41:36197 return (gclient_utils.SplitUrlRevision(actual_remote_url)[0].rstrip('/')
198 == gclient_utils.SplitUrlRevision(self.url)[0].rstrip('/'))
[email protected]88d10082014-03-21 17:24:48199 else:
200 # This may occur if the self.checkout_path exists but does not contain a
201 # valid git or svn checkout.
202 return False
203
[email protected]b09097a2014-04-09 19:09:08204 def _DeleteOrMove(self, force):
205 """Delete the checkout directory or move it out of the way.
206
207 Args:
208 force: bool; if True, delete the directory. Otherwise, just move it.
209 """
[email protected]b2256212014-05-07 20:57:28210 if force and os.environ.get('CHROME_HEADLESS') == '1':
211 self.Print('_____ Conflicting directory found in %s. Removing.'
212 % self.checkout_path)
213 gclient_utils.AddWarning('Conflicting directory %s deleted.'
214 % self.checkout_path)
215 gclient_utils.rmtree(self.checkout_path)
216 else:
217 bad_scm_dir = os.path.join(self._root_dir, '_bad_scm',
218 os.path.dirname(self.relpath))
219
220 try:
221 os.makedirs(bad_scm_dir)
222 except OSError as e:
223 if e.errno != errno.EEXIST:
224 raise
225
226 dest_path = tempfile.mkdtemp(
227 prefix=os.path.basename(self.relpath),
228 dir=bad_scm_dir)
229 self.Print('_____ Conflicting directory found in %s. Moving to %s.'
230 % (self.checkout_path, dest_path))
231 gclient_utils.AddWarning('Conflicting directory %s moved to %s.'
232 % (self.checkout_path, dest_path))
233 shutil.move(self.checkout_path, dest_path)
[email protected]b09097a2014-04-09 19:09:08234
[email protected]cb5442b2009-09-22 16:51:24235
[email protected]55e724e2010-03-11 19:36:49236class GitWrapper(SCMWrapper):
[email protected]e28e4982009-09-25 20:51:45237 """Wrapper for Git"""
[email protected]2702bcd2013-09-24 19:10:07238 name = 'git'
[email protected]1a60dca2013-11-26 14:06:26239 remote = 'origin'
[email protected]e28e4982009-09-25 20:51:45240
[email protected]53456aa2013-07-03 19:38:34241 cache_dir = None
[email protected]53456aa2013-07-03 19:38:34242
[email protected]848fd492014-04-09 19:06:44243 def __init__(self, url=None, *args):
[email protected]4e075672011-11-21 16:35:08244 """Removes 'git+' fake prefix from git URL."""
245 if url.startswith('git+http://') or url.startswith('git+https://'):
246 url = url[4:]
[email protected]848fd492014-04-09 19:06:44247 SCMWrapper.__init__(self, url, *args)
248 filter_kwargs = { 'time_throttle': 1, 'out_fh': self.out_fh }
249 if self.out_cb:
250 filter_kwargs['predicate'] = self.out_cb
251 self.filter = gclient_utils.GitFilter(**filter_kwargs)
[email protected]4e075672011-11-21 16:35:08252
[email protected]9e3e82c2012-04-18 12:55:43253 @staticmethod
254 def BinaryExists():
255 """Returns true if the command exists."""
256 try:
257 # We assume git is newer than 1.7. See: crbug.com/114483
258 result, version = scm.GIT.AssertVersion('1.7')
259 if not result:
260 raise gclient_utils.Error('Git version is older than 1.7: %s' % version)
261 return result
262 except OSError:
263 return False
264
[email protected]885a9602013-05-31 09:54:40265 def GetCheckoutRoot(self):
266 return scm.GIT.GetCheckoutRoot(self.checkout_path)
267
[email protected]396e1a62013-07-03 19:41:04268 def GetRevisionDate(self, _revision):
[email protected]eaab7842011-04-28 09:07:58269 """Returns the given revision's date in ISO-8601 format (which contains the
270 time zone)."""
271 # TODO(floitsch): get the time-stamp of the given revision and not just the
272 # time-stamp of the currently checked out revision.
273 return self._Capture(['log', '-n', '1', '--format=%ai'])
274
[email protected]6e29d572010-06-04 17:32:20275 @staticmethod
276 def cleanup(options, args, file_list):
[email protected]d8a63782010-01-25 17:47:05277 """'Cleanup' the repo.
278
279 There's no real git equivalent for the svn cleanup command, do a no-op.
280 """
[email protected]e28e4982009-09-25 20:51:45281
[email protected]396e1a62013-07-03 19:41:04282 def diff(self, options, _args, _file_list):
[email protected]1a60dca2013-11-26 14:06:26283 merge_base = self._Capture(['merge-base', 'HEAD', self.remote])
[email protected]37e89872010-09-07 16:11:33284 self._Run(['diff', merge_base], options)
[email protected]e28e4982009-09-25 20:51:45285
[email protected]396e1a62013-07-03 19:41:04286 def pack(self, _options, _args, _file_list):
[email protected]ee4071d2009-12-22 22:25:37287 """Generates a patch file which can be applied to the root of the
[email protected]d6504212010-01-13 17:34:31288 repository.
289
290 The patch file is generated from a diff of the merge base of HEAD and
291 its upstream branch.
292 """
[email protected]1a60dca2013-11-26 14:06:26293 merge_base = self._Capture(['merge-base', 'HEAD', self.remote])
[email protected]17d01792010-09-01 18:07:10294 gclient_utils.CheckCallAndFilter(
[email protected]8469bf92010-09-03 19:03:15295 ['git', 'diff', merge_base],
296 cwd=self.checkout_path,
[email protected]fe0d1902014-04-08 20:50:44297 filter_fn=GitDiffFilterer(self.relpath).Filter, print_func=self.Print)
[email protected]ee4071d2009-12-22 22:25:37298
[email protected]d33eab32014-07-07 19:35:18299 def _FetchAndReset(self, revision, file_list, options):
[email protected]50fd47f2014-02-13 01:03:19300 """Equivalent to git fetch; git reset."""
301 quiet = []
302 if not options.verbose:
303 quiet = ['--quiet']
304 self._UpdateBranchHeads(options, fetch=False)
305
[email protected]680f2172014-06-25 00:39:32306 self._Fetch(options, prune=True, quiet=options.verbose)
[email protected]d33eab32014-07-07 19:35:18307 self._Run(['reset', '--hard', revision] + quiet, options)
[email protected]50fd47f2014-02-13 01:03:19308 if file_list is not None:
309 files = self._Capture(['ls-files']).splitlines()
310 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
311
[email protected]8a139702014-06-20 15:55:01312 def _DisableHooks(self):
313 hook_dir = os.path.join(self.checkout_path, '.git', 'hooks')
314 if not os.path.isdir(hook_dir):
315 return
316 for f in os.listdir(hook_dir):
317 if not f.endswith('.sample') and not f.endswith('.disabled'):
318 os.rename(os.path.join(hook_dir, f),
319 os.path.join(hook_dir, f + '.disabled'))
320
[email protected]e28e4982009-09-25 20:51:45321 def update(self, options, args, file_list):
322 """Runs git to update or transparently checkout the working copy.
323
324 All updated files will be appended to file_list.
325
326 Raises:
327 Error: if can't get URL for relative path.
328 """
[email protected]e28e4982009-09-25 20:51:45329 if args:
330 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
331
[email protected]ece406f2010-02-23 17:29:15332 self._CheckMinVersion("1.6.6")
[email protected]923a0372009-12-11 20:42:43333
[email protected]1a60dca2013-11-26 14:06:26334 # If a dependency is not pinned, track the default remote branch.
[email protected]d33eab32014-07-07 19:35:18335 default_rev = 'refs/remotes/%s/master' % self.remote
[email protected]7080e942010-03-15 15:06:16336 url, deps_revision = gclient_utils.SplitUrlRevision(self.url)
[email protected]ac915bb2009-11-13 17:03:01337 rev_str = ""
[email protected]7080e942010-03-15 15:06:16338 revision = deps_revision
[email protected]eb2756d2011-09-20 20:17:51339 managed = True
[email protected]e28e4982009-09-25 20:51:45340 if options.revision:
[email protected]ac915bb2009-11-13 17:03:01341 # Override the revision number.
342 revision = str(options.revision)
[email protected]eb2756d2011-09-20 20:17:51343 if revision == 'unmanaged':
[email protected]483a0ba2014-05-30 00:06:07344 # Check again for a revision in case an initial ref was specified
345 # in the url, for example bla.git@refs/heads/custombranch
346 revision = deps_revision
[email protected]eb2756d2011-09-20 20:17:51347 managed = False
[email protected]d90ba3f2010-02-23 14:42:57348 if not revision:
349 revision = default_rev
[email protected]e28e4982009-09-25 20:51:45350
[email protected]8a139702014-06-20 15:55:01351 if managed:
352 self._DisableHooks()
353
[email protected]eaab7842011-04-28 09:07:58354 if gclient_utils.IsDateRevision(revision):
355 # Date-revisions only work on git-repositories if the reflog hasn't
356 # expired yet. Use rev-list to get the corresponding revision.
357 # git rev-list -n 1 --before='time-stamp' branchname
358 if options.transitive:
[email protected]fe0d1902014-04-08 20:50:44359 self.Print('Warning: --transitive only works for SVN repositories.')
[email protected]eaab7842011-04-28 09:07:58360 revision = default_rev
361
[email protected]d90ba3f2010-02-23 14:42:57362 rev_str = ' at %s' % revision
[email protected]396e1a62013-07-03 19:41:04363 files = [] if file_list is not None else None
[email protected]d90ba3f2010-02-23 14:42:57364
365 printed_path = False
366 verbose = []
[email protected]b1a22bf2009-11-07 02:33:50367 if options.verbose:
[email protected]fe0d1902014-04-08 20:50:44368 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
[email protected]d90ba3f2010-02-23 14:42:57369 verbose = ['--verbose']
370 printed_path = True
371
[email protected]d33eab32014-07-07 19:35:18372 if revision.startswith('refs/'):
373 rev_type = "branch"
374 elif revision.startswith(self.remote + '/'):
375 # Rewrite remote refs to their local equivalents.
376 revision = 'refs/remotes/' + revision
377 rev_type = "branch"
378 else:
379 # hash is also a tag, only make a distinction at checkout
380 rev_type = "hash"
381
[email protected]b0a13a22014-06-18 00:52:25382 mirror = self._GetMirror(url, options)
383 if mirror:
384 url = mirror.mirror_path
385
[email protected]6c2b49d2014-02-26 23:57:38386 if (not os.path.exists(self.checkout_path) or
387 (os.path.isdir(self.checkout_path) and
388 not os.path.exists(os.path.join(self.checkout_path, '.git')))):
[email protected]b0a13a22014-06-18 00:52:25389 if mirror:
390 self._UpdateMirror(mirror, options)
[email protected]90fe58b2014-05-01 18:22:00391 try:
[email protected]d33eab32014-07-07 19:35:18392 self._Clone(revision, url, options)
[email protected]90fe58b2014-05-01 18:22:00393 except subprocess2.CalledProcessError:
394 self._DeleteOrMove(options.force)
[email protected]d33eab32014-07-07 19:35:18395 self._Clone(revision, url, options)
[email protected]048da082014-05-06 08:32:40396 if deps_revision and deps_revision.startswith('branch-heads/'):
397 deps_branch = deps_revision.replace('branch-heads/', '')
398 self._Capture(['branch', deps_branch, deps_revision])
[email protected]bb424c02014-06-23 22:42:51399 self._Checkout(options, deps_branch, quiet=True)
[email protected]396e1a62013-07-03 19:41:04400 if file_list is not None:
401 files = self._Capture(['ls-files']).splitlines()
402 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
[email protected]d90ba3f2010-02-23 14:42:57403 if not verbose:
404 # Make the output a little prettier. It's nice to have some whitespace
405 # between projects when cloning.
[email protected]fe0d1902014-04-08 20:50:44406 self.Print('')
[email protected]2702bcd2013-09-24 19:10:07407 return self._Capture(['rev-parse', '--verify', 'HEAD'])
[email protected]e28e4982009-09-25 20:51:45408
[email protected]3dc5cb72014-06-17 15:06:05409 if not managed:
410 self._UpdateBranchHeads(options, fetch=False)
411 self.Print('________ unmanaged solution; skipping %s' % self.relpath)
412 return self._Capture(['rev-parse', '--verify', 'HEAD'])
413
[email protected]b0a13a22014-06-18 00:52:25414 if mirror:
415 self._UpdateMirror(mirror, options)
416
[email protected]6c2b49d2014-02-26 23:57:38417 # See if the url has changed (the unittests use git://foo for the url, let
418 # that through).
419 current_url = self._Capture(['config', 'remote.%s.url' % self.remote])
420 return_early = False
421 # TODO(maruel): Delete url != 'git://foo' since it's just to make the
422 # unit test pass. (and update the comment above)
423 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set.
424 # This allows devs to use experimental repos which have a different url
425 # but whose branch(s) are the same as official repos.
[email protected]b09097a2014-04-09 19:09:08426 if (current_url.rstrip('/') != url.rstrip('/') and
[email protected]6c2b49d2014-02-26 23:57:38427 url != 'git://foo' and
428 subprocess2.capture(
429 ['git', 'config', 'remote.%s.gclient-auto-fix-url' % self.remote],
430 cwd=self.checkout_path).strip() != 'False'):
[email protected]fe0d1902014-04-08 20:50:44431 self.Print('_____ switching %s to a new upstream' % self.relpath)
[email protected]78514212014-08-20 23:08:00432 if not (options.force or options.reset):
433 # Make sure it's clean
434 self._CheckClean(rev_str)
[email protected]6c2b49d2014-02-26 23:57:38435 # Switch over to the new upstream
436 self._Run(['remote', 'set-url', self.remote, url], options)
[email protected]d33eab32014-07-07 19:35:18437 self._FetchAndReset(revision, file_list, options)
[email protected]6c2b49d2014-02-26 23:57:38438 return_early = True
439
[email protected]50fd47f2014-02-13 01:03:19440 if return_early:
441 return self._Capture(['rev-parse', '--verify', 'HEAD'])
442
[email protected]5bde4852009-12-14 16:47:12443 cur_branch = self._GetCurrentBranch()
444
[email protected]d90ba3f2010-02-23 14:42:57445 # Cases:
[email protected]786fb682010-06-02 15:16:23446 # 0) HEAD is detached. Probably from our initial clone.
447 # - make sure HEAD is contained by a named ref, then update.
448 # Cases 1-4. HEAD is a branch.
449 # 1) current branch is not tracking a remote branch (could be git-svn)
450 # - try to rebase onto the new hash or branch
451 # 2) current branch is tracking a remote branch with local committed
452 # changes, but the DEPS file switched to point to a hash
[email protected]d90ba3f2010-02-23 14:42:57453 # - rebase those changes on top of the hash
[email protected]786fb682010-06-02 15:16:23454 # 3) current branch is tracking a remote branch w/or w/out changes,
455 # no switch
[email protected]d90ba3f2010-02-23 14:42:57456 # - see if we can FF, if not, prompt the user for rebase, merge, or stop
[email protected]786fb682010-06-02 15:16:23457 # 4) current branch is tracking a remote branch, switches to a different
458 # remote branch
[email protected]d90ba3f2010-02-23 14:42:57459 # - exit
460
[email protected]81e012c2010-04-29 16:07:24461 # GetUpstreamBranch returns something like 'refs/remotes/origin/master' for
462 # a tracking branch
[email protected]d90ba3f2010-02-23 14:42:57463 # or 'master' if not a tracking branch (it's based on a specific rev/hash)
464 # or it returns None if it couldn't find an upstream
[email protected]786fb682010-06-02 15:16:23465 if cur_branch is None:
466 upstream_branch = None
467 current_type = "detached"
468 logging.debug("Detached HEAD")
[email protected]d90ba3f2010-02-23 14:42:57469 else:
[email protected]786fb682010-06-02 15:16:23470 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path)
471 if not upstream_branch or not upstream_branch.startswith('refs/remotes'):
472 current_type = "hash"
473 logging.debug("Current branch is not tracking an upstream (remote)"
474 " branch.")
475 elif upstream_branch.startswith('refs/remotes'):
476 current_type = "branch"
477 else:
478 raise gclient_utils.Error('Invalid Upstream: %s' % upstream_branch)
[email protected]d90ba3f2010-02-23 14:42:57479
[email protected]d33eab32014-07-07 19:35:18480 if not scm.GIT.IsValidRevision(self.checkout_path, revision, sha_only=True):
[email protected]cbd20a42012-06-27 13:49:27481 # Update the remotes first so we have all the refs.
[email protected]a41249c2013-07-03 00:09:12482 remote_output = scm.GIT.Capture(['remote'] + verbose + ['update'],
[email protected]cbd20a42012-06-27 13:49:27483 cwd=self.checkout_path)
[email protected]cbd20a42012-06-27 13:49:27484 if verbose:
[email protected]fe0d1902014-04-08 20:50:44485 self.Print(remote_output)
[email protected]d90ba3f2010-02-23 14:42:57486
[email protected]e409df62013-04-16 17:28:57487 self._UpdateBranchHeads(options, fetch=True)
488
[email protected]d90ba3f2010-02-23 14:42:57489 # This is a big hammer, debatable if it should even be here...
[email protected]793796d2010-02-19 17:27:41490 if options.force or options.reset:
[email protected]d4fffee2013-06-28 00:35:26491 target = 'HEAD'
492 if options.upstream and upstream_branch:
493 target = upstream_branch
494 self._Run(['reset', '--hard', target], options)
[email protected]d90ba3f2010-02-23 14:42:57495
[email protected]786fb682010-06-02 15:16:23496 if current_type == 'detached':
497 # case 0
498 self._CheckClean(rev_str)
[email protected]f5d37bf2010-09-02 00:50:34499 self._CheckDetachedHead(rev_str, options)
[email protected]d33eab32014-07-07 19:35:18500 if self._Capture(['rev-list', '-n', '1', 'HEAD']) == revision:
[email protected]848fd492014-04-09 19:06:44501 self.Print('Up-to-date; skipping checkout.')
502 else:
[email protected]2b7d3ed2014-06-20 18:15:37503 # 'git checkout' may need to overwrite existing untracked files. Allow
504 # it only when nuclear options are enabled.
[email protected]bb424c02014-06-23 22:42:51505 self._Checkout(
506 options,
507 revision,
508 force=(options.force and options.delete_unversioned_trees),
509 quiet=True,
510 )
[email protected]786fb682010-06-02 15:16:23511 if not printed_path:
[email protected]fe0d1902014-04-08 20:50:44512 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
[email protected]786fb682010-06-02 15:16:23513 elif current_type == 'hash':
[email protected]d90ba3f2010-02-23 14:42:57514 # case 1
[email protected]55e724e2010-03-11 19:36:49515 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None:
[email protected]d90ba3f2010-02-23 14:42:57516 # Our git-svn branch (upstream_branch) is our upstream
[email protected]f5d37bf2010-09-02 00:50:34517 self._AttemptRebase(upstream_branch, files, options,
[email protected]d33eab32014-07-07 19:35:18518 newbase=revision, printed_path=printed_path,
519 merge=options.merge)
[email protected]d90ba3f2010-02-23 14:42:57520 printed_path = True
521 else:
522 # Can't find a merge-base since we don't know our upstream. That makes
523 # this command VERY likely to produce a rebase failure. For now we
524 # assume origin is our upstream since that's what the old behavior was.
[email protected]1a60dca2013-11-26 14:06:26525 upstream_branch = self.remote
[email protected]7080e942010-03-15 15:06:16526 if options.revision or deps_revision:
[email protected]d33eab32014-07-07 19:35:18527 upstream_branch = revision
[email protected]f5d37bf2010-09-02 00:50:34528 self._AttemptRebase(upstream_branch, files, options,
[email protected]30c46d62014-01-23 12:11:56529 printed_path=printed_path, merge=options.merge)
[email protected]d90ba3f2010-02-23 14:42:57530 printed_path = True
[email protected]d33eab32014-07-07 19:35:18531 elif rev_type == 'hash':
[email protected]d90ba3f2010-02-23 14:42:57532 # case 2
[email protected]f5d37bf2010-09-02 00:50:34533 self._AttemptRebase(upstream_branch, files, options,
[email protected]d33eab32014-07-07 19:35:18534 newbase=revision, printed_path=printed_path,
[email protected]30c46d62014-01-23 12:11:56535 merge=options.merge)
[email protected]d90ba3f2010-02-23 14:42:57536 printed_path = True
[email protected]d33eab32014-07-07 19:35:18537 elif revision.replace('heads', 'remotes/' + self.remote) != upstream_branch:
[email protected]d90ba3f2010-02-23 14:42:57538 # case 4
[email protected]d33eab32014-07-07 19:35:18539 new_base = revision.replace('heads', 'remotes/' + self.remote)
[email protected]d90ba3f2010-02-23 14:42:57540 if not printed_path:
[email protected]fe0d1902014-04-08 20:50:44541 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
[email protected]d90ba3f2010-02-23 14:42:57542 switch_error = ("Switching upstream branch from %s to %s\n"
543 % (upstream_branch, new_base) +
544 "Please merge or rebase manually:\n" +
545 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) +
546 "OR git checkout -b <some new branch> %s" % new_base)
547 raise gclient_utils.Error(switch_error)
548 else:
549 # case 3 - the default case
[email protected]396e1a62013-07-03 19:41:04550 if files is not None:
551 files = self._Capture(['diff', upstream_branch, '--name-only']).split()
[email protected]d90ba3f2010-02-23 14:42:57552 if verbose:
[email protected]fe0d1902014-04-08 20:50:44553 self.Print('Trying fast-forward merge to branch : %s' % upstream_branch)
[email protected]d90ba3f2010-02-23 14:42:57554 try:
[email protected]2aad1b22011-07-22 12:00:41555 merge_args = ['merge']
[email protected]30c46d62014-01-23 12:11:56556 if options.merge:
557 merge_args.append('--ff')
558 else:
[email protected]2aad1b22011-07-22 12:00:41559 merge_args.append('--ff-only')
560 merge_args.append(upstream_branch)
[email protected]fe0d1902014-04-08 20:50:44561 merge_output = self._Capture(merge_args)
[email protected]18fa4542013-05-21 13:30:46562 except subprocess2.CalledProcessError as e:
[email protected]d90ba3f2010-02-23 14:42:57563 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr):
[email protected]30c46d62014-01-23 12:11:56564 files = []
[email protected]d90ba3f2010-02-23 14:42:57565 if not printed_path:
[email protected]fe0d1902014-04-08 20:50:44566 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
[email protected]d90ba3f2010-02-23 14:42:57567 printed_path = True
568 while True:
569 try:
[email protected]30c46d62014-01-23 12:11:56570 action = self._AskForData(
571 'Cannot %s, attempt to rebase? '
572 '(y)es / (q)uit / (s)kip : ' %
573 ('merge' if options.merge else 'fast-forward merge'),
574 options)
[email protected]d90ba3f2010-02-23 14:42:57575 except ValueError:
[email protected]90541732011-04-01 17:54:18576 raise gclient_utils.Error('Invalid Character')
[email protected]d90ba3f2010-02-23 14:42:57577 if re.match(r'yes|y', action, re.I):
[email protected]f5d37bf2010-09-02 00:50:34578 self._AttemptRebase(upstream_branch, files, options,
[email protected]30c46d62014-01-23 12:11:56579 printed_path=printed_path, merge=False)
[email protected]d90ba3f2010-02-23 14:42:57580 printed_path = True
581 break
582 elif re.match(r'quit|q', action, re.I):
583 raise gclient_utils.Error("Can't fast-forward, please merge or "
584 "rebase manually.\n"
585 "cd %s && git " % self.checkout_path
586 + "rebase %s" % upstream_branch)
587 elif re.match(r'skip|s', action, re.I):
[email protected]fe0d1902014-04-08 20:50:44588 self.Print('Skipping %s' % self.relpath)
[email protected]d90ba3f2010-02-23 14:42:57589 return
590 else:
[email protected]fe0d1902014-04-08 20:50:44591 self.Print('Input not recognized')
[email protected]d90ba3f2010-02-23 14:42:57592 elif re.match("error: Your local changes to '.*' would be "
593 "overwritten by merge. Aborting.\nPlease, commit your "
594 "changes or stash them before you can merge.\n",
595 e.stderr):
596 if not printed_path:
[email protected]fe0d1902014-04-08 20:50:44597 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
[email protected]d90ba3f2010-02-23 14:42:57598 printed_path = True
599 raise gclient_utils.Error(e.stderr)
600 else:
601 # Some other problem happened with the merge
602 logging.error("Error during fast-forward merge in %s!" % self.relpath)
[email protected]fe0d1902014-04-08 20:50:44603 self.Print(e.stderr)
[email protected]d90ba3f2010-02-23 14:42:57604 raise
605 else:
606 # Fast-forward merge was successful
607 if not re.match('Already up-to-date.', merge_output) or verbose:
608 if not printed_path:
[email protected]fe0d1902014-04-08 20:50:44609 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
[email protected]d90ba3f2010-02-23 14:42:57610 printed_path = True
[email protected]fe0d1902014-04-08 20:50:44611 self.Print(merge_output.strip())
[email protected]d90ba3f2010-02-23 14:42:57612 if not verbose:
613 # Make the output a little prettier. It's nice to have some
614 # whitespace between projects when syncing.
[email protected]fe0d1902014-04-08 20:50:44615 self.Print('')
[email protected]d90ba3f2010-02-23 14:42:57616
[email protected]396e1a62013-07-03 19:41:04617 if file_list is not None:
618 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
[email protected]5bde4852009-12-14 16:47:12619
620 # If the rebase generated a conflict, abort and ask user to fix
[email protected]786fb682010-06-02 15:16:23621 if self._IsRebasing():
[email protected]5bde4852009-12-14 16:47:12622 raise gclient_utils.Error('\n____ %s%s\n'
623 '\nConflict while rebasing this branch.\n'
624 'Fix the conflict and run gclient again.\n'
625 'See man git-rebase for details.\n'
626 % (self.relpath, rev_str))
627
[email protected]d90ba3f2010-02-23 14:42:57628 if verbose:
[email protected]fe0d1902014-04-08 20:50:44629 self.Print('Checked out revision %s' % self.revinfo(options, (), None),
630 timestamp=False)
[email protected]e28e4982009-09-25 20:51:45631
[email protected]98e69452012-02-16 16:36:43632 # If --reset and --delete_unversioned_trees are specified, remove any
633 # untracked directories.
634 if options.reset and options.delete_unversioned_trees:
635 # GIT.CaptureStatus() uses 'dit diff' to compare to a specific SHA1 (the
636 # merge-base by default), so doesn't include untracked files. So we use
637 # 'git ls-files --directory --others --exclude-standard' here directly.
638 paths = scm.GIT.Capture(
639 ['ls-files', '--directory', '--others', '--exclude-standard'],
640 self.checkout_path)
641 for path in (p for p in paths.splitlines() if p.endswith('/')):
642 full_path = os.path.join(self.checkout_path, path)
643 if not os.path.islink(full_path):
[email protected]fe0d1902014-04-08 20:50:44644 self.Print('_____ removing unversioned directory %s' % path)
[email protected]dc112ac2013-04-24 13:00:19645 gclient_utils.rmtree(full_path)
[email protected]98e69452012-02-16 16:36:43646
[email protected]2702bcd2013-09-24 19:10:07647 return self._Capture(['rev-parse', '--verify', 'HEAD'])
648
[email protected]98e69452012-02-16 16:36:43649
[email protected]396e1a62013-07-03 19:41:04650 def revert(self, options, _args, file_list):
[email protected]e28e4982009-09-25 20:51:45651 """Reverts local modifications.
652
653 All reverted files will be appended to file_list.
654 """
[email protected]8469bf92010-09-03 19:03:15655 if not os.path.isdir(self.checkout_path):
[email protected]260c6532009-10-28 03:22:35656 # revert won't work if the directory doesn't exist. It needs to
657 # checkout instead.
[email protected]fe0d1902014-04-08 20:50:44658 self.Print('_____ %s is missing, synching instead' % self.relpath)
[email protected]260c6532009-10-28 03:22:35659 # Don't reuse the args.
660 return self.update(options, [], file_list)
[email protected]b2b46312010-04-30 20:58:03661
662 default_rev = "refs/heads/master"
[email protected]d4fffee2013-06-28 00:35:26663 if options.upstream:
664 if self._GetCurrentBranch():
665 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path)
666 default_rev = upstream_branch or default_rev
[email protected]6e29d572010-06-04 17:32:20667 _, deps_revision = gclient_utils.SplitUrlRevision(self.url)
[email protected]b2b46312010-04-30 20:58:03668 if not deps_revision:
669 deps_revision = default_rev
[email protected]d33eab32014-07-07 19:35:18670 if deps_revision.startswith('refs/heads/'):
671 deps_revision = deps_revision.replace('refs/heads/', self.remote + '/')
672 deps_revision = self.GetUsableRev(deps_revision, options)
[email protected]b2b46312010-04-30 20:58:03673
[email protected]396e1a62013-07-03 19:41:04674 if file_list is not None:
675 files = self._Capture(['diff', deps_revision, '--name-only']).split()
676
[email protected]37e89872010-09-07 16:11:33677 self._Run(['reset', '--hard', deps_revision], options)
[email protected]ade83db2012-09-27 14:06:49678 self._Run(['clean', '-f', '-d'], options)
[email protected]e28e4982009-09-25 20:51:45679
[email protected]396e1a62013-07-03 19:41:04680 if file_list is not None:
681 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
682
683 def revinfo(self, _options, _args, _file_list):
[email protected]6cafa132010-09-07 14:17:26684 """Returns revision"""
685 return self._Capture(['rev-parse', 'HEAD'])
[email protected]0f282062009-11-06 20:14:02686
[email protected]e28e4982009-09-25 20:51:45687 def runhooks(self, options, args, file_list):
688 self.status(options, args, file_list)
689
[email protected]396e1a62013-07-03 19:41:04690 def status(self, options, _args, file_list):
[email protected]e28e4982009-09-25 20:51:45691 """Display status information."""
692 if not os.path.isdir(self.checkout_path):
[email protected]fe0d1902014-04-08 20:50:44693 self.Print('________ couldn\'t run status in %s:\n'
694 'The directory does not exist.' % self.checkout_path)
[email protected]e28e4982009-09-25 20:51:45695 else:
[email protected]1a60dca2013-11-26 14:06:26696 merge_base = self._Capture(['merge-base', 'HEAD', self.remote])
[email protected]fe0d1902014-04-08 20:50:44697 self._Run(['diff', '--name-status', merge_base], options,
698 stdout=self.out_fh)
[email protected]396e1a62013-07-03 19:41:04699 if file_list is not None:
700 files = self._Capture(['diff', '--name-only', merge_base]).split()
701 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
[email protected]e28e4982009-09-25 20:51:45702
[email protected]e5d1e612011-12-19 19:49:19703 def GetUsableRev(self, rev, options):
704 """Finds a useful revision for this repository.
705
706 If SCM is git-svn and the head revision is less than |rev|, git svn fetch
707 will be called on the source."""
708 sha1 = None
[email protected]3830a672013-02-19 20:15:14709 if not os.path.isdir(self.checkout_path):
710 raise gclient_utils.Error(
711 ( 'We could not find a valid hash for safesync_url response "%s".\n'
712 'Safesync URLs with a git checkout currently require the repo to\n'
713 'be cloned without a safesync_url before adding the safesync_url.\n'
714 'For more info, see: '
715 'http://code.google.com/p/chromium/wiki/UsingNewGit'
716 '#Initial_checkout' ) % rev)
717 elif rev.isdigit() and len(rev) < 7:
718 # Handles an SVN rev. As an optimization, only verify an SVN revision as
719 # [0-9]{1,6} for now to avoid making a network request.
[email protected]6c2b49d2014-02-26 23:57:38720 if scm.GIT.IsGitSvn(cwd=self.checkout_path):
[email protected]051c88b2011-12-22 00:23:03721 local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path)
722 if not local_head or local_head < int(rev):
[email protected]2a75fdb2012-02-15 01:32:57723 try:
724 logging.debug('Looking for git-svn configuration optimizations.')
725 if scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
726 cwd=self.checkout_path):
[email protected]680f2172014-06-25 00:39:32727 self._Fetch(options)
[email protected]2a75fdb2012-02-15 01:32:57728 except subprocess2.CalledProcessError:
729 logging.debug('git config --get svn-remote.svn.fetch failed, '
730 'ignoring possible optimization.')
[email protected]051c88b2011-12-22 00:23:03731 if options.verbose:
[email protected]fe0d1902014-04-08 20:50:44732 self.Print('Running git svn fetch. This might take a while.\n')
[email protected]051c88b2011-12-22 00:23:03733 scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path)
[email protected]312a6a42012-10-11 21:19:42734 try:
[email protected]c51def32012-10-15 18:50:37735 sha1 = scm.GIT.GetBlessedSha1ForSvnRev(
736 cwd=self.checkout_path, rev=rev)
[email protected]312a6a42012-10-11 21:19:42737 except gclient_utils.Error, e:
738 sha1 = e.message
[email protected]fe0d1902014-04-08 20:50:44739 self.Print('Warning: Could not find a git revision with accurate\n'
[email protected]312a6a42012-10-11 21:19:42740 '.DEPS.git that maps to SVN revision %s. Sync-ing to\n'
741 'the closest sane git revision, which is:\n'
742 ' %s\n' % (rev, e.message))
[email protected]051c88b2011-12-22 00:23:03743 if not sha1:
744 raise gclient_utils.Error(
745 ( 'It appears that either your git-svn remote is incorrectly\n'
746 'configured or the revision in your safesync_url is\n'
747 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n'
748 'corresponding git hash for SVN rev %s.' ) % rev)
[email protected]3830a672013-02-19 20:15:14749 else:
750 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev):
751 sha1 = rev
752 else:
753 # May exist in origin, but we don't have it yet, so fetch and look
754 # again.
[email protected]680f2172014-06-25 00:39:32755 self._Fetch(options)
[email protected]3830a672013-02-19 20:15:14756 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev):
757 sha1 = rev
[email protected]051c88b2011-12-22 00:23:03758
[email protected]e5d1e612011-12-19 19:49:19759 if not sha1:
760 raise gclient_utils.Error(
[email protected]051c88b2011-12-22 00:23:03761 ( 'We could not find a valid hash for safesync_url response "%s".\n'
762 'Safesync URLs with a git checkout currently require a git-svn\n'
763 'remote or a safesync_url that provides git sha1s. Please add a\n'
764 'git-svn remote or change your safesync_url. For more info, see:\n'
[email protected]e5d1e612011-12-19 19:49:19765 'http://code.google.com/p/chromium/wiki/UsingNewGit'
[email protected]051c88b2011-12-22 00:23:03766 '#Initial_checkout' ) % rev)
767
[email protected]e5d1e612011-12-19 19:49:19768 return sha1
769
[email protected]e6f78352010-01-13 17:05:33770 def FullUrlForRelativeUrl(self, url):
771 # Strip from last '/'
772 # Equivalent to unix basename
773 base_url = self.url
774 return base_url[:base_url.rfind('/')] + url
775
[email protected]b0a13a22014-06-18 00:52:25776 def _GetMirror(self, url, options):
777 """Get a git_cache.Mirror object for the argument url."""
778 if not git_cache.Mirror.GetCachePath():
779 return None
[email protected]b1b54572014-04-16 22:29:23780 mirror_kwargs = {
781 'print_func': self.filter,
782 'refs': []
783 }
[email protected]356cb5f2014-04-25 00:02:21784 # TODO(hinoka): This currently just fails because lkcr/lkgr are branches
785 # not tags. This also adds 20 seconds to every bot_update
786 # run, so I'm commenting this out until lkcr/lkgr become
787 # tags. (2014/4/24)
788 # if url == CHROMIUM_SRC_URL or url + '.git' == CHROMIUM_SRC_URL:
789 # mirror_kwargs['refs'].extend(['refs/tags/lkgr', 'refs/tags/lkcr'])
[email protected]b1b54572014-04-16 22:29:23790 if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
791 mirror_kwargs['refs'].append('refs/branch-heads/*')
[email protected]8d3348f2014-08-19 22:49:16792 if hasattr(options, 'with_tags') and options.with_tags:
793 mirror_kwargs['refs'].append('refs/tags/*')
[email protected]b0a13a22014-06-18 00:52:25794 return git_cache.Mirror(url, **mirror_kwargs)
795
796 @staticmethod
797 def _UpdateMirror(mirror, options):
798 """Update a git mirror by fetching the latest commits from the remote."""
[email protected]3ec84f62014-08-22 21:00:22799 if getattr(options, 'shallow', False):
[email protected]46b87412014-05-15 00:42:05800 # HACK(hinoka): These repositories should be super shallow.
[email protected]b0a13a22014-06-18 00:52:25801 if 'flash' in mirror.url:
[email protected]46b87412014-05-15 00:42:05802 depth = 10
803 else:
804 depth = 10000
805 else:
806 depth = None
[email protected]8a10f6d2014-06-23 18:38:57807 mirror.populate(verbose=options.verbose, bootstrap=True, depth=depth,
808 ignore_lock=options.ignore_locks)
[email protected]848fd492014-04-09 19:06:44809 mirror.unlock()
[email protected]53456aa2013-07-03 19:38:34810
[email protected]f5d37bf2010-09-02 00:50:34811 def _Clone(self, revision, url, options):
[email protected]d90ba3f2010-02-23 14:42:57812 """Clone a git repository from the given URL.
813
[email protected]786fb682010-06-02 15:16:23814 Once we've cloned the repo, we checkout a working branch if the specified
815 revision is a branch head. If it is a tag or a specific commit, then we
816 leave HEAD detached as it makes future updates simpler -- in this case the
817 user should first create a new branch or switch to an existing branch before
818 making changes in the repo."""
[email protected]f5d37bf2010-09-02 00:50:34819 if not options.verbose:
[email protected]d90ba3f2010-02-23 14:42:57820 # git clone doesn't seem to insert a newline properly before printing
821 # to stdout
[email protected]fe0d1902014-04-08 20:50:44822 self.Print('')
[email protected]f1d73eb2014-04-21 17:07:04823 cfg = gclient_utils.DefaultIndexPackConfig(url)
[email protected]8a139702014-06-20 15:55:01824 clone_cmd = cfg + ['clone', '--no-checkout', '--progress']
[email protected]53456aa2013-07-03 19:38:34825 if self.cache_dir:
826 clone_cmd.append('--shared')
[email protected]f5d37bf2010-09-02 00:50:34827 if options.verbose:
[email protected]d90ba3f2010-02-23 14:42:57828 clone_cmd.append('--verbose')
[email protected]3534aa52013-07-20 01:58:08829 clone_cmd.append(url)
[email protected]328c3c72011-06-01 20:50:27830 # If the parent directory does not exist, Git clone on Windows will not
831 # create it, so we need to do it manually.
832 parent_dir = os.path.dirname(self.checkout_path)
[email protected]3534aa52013-07-20 01:58:08833 gclient_utils.safe_makedirs(parent_dir)
[email protected]5439ea52014-08-06 17:18:18834
835 template_dir = None
836 if hasattr(options, 'no_history') and options.no_history:
837 if gclient_utils.IsGitSha(revision):
838 # In the case of a subproject, the pinned sha is not necessarily the
839 # head of the remote branch (so we can't just use --depth=N). Instead,
840 # we tell git to fetch all the remote objects from SHA..HEAD by means of
841 # a template git dir which has a 'shallow' file pointing to the sha.
842 template_dir = tempfile.mkdtemp(
843 prefix='_gclient_gittmp_%s' % os.path.basename(self.checkout_path),
844 dir=parent_dir)
845 self._Run(['init', '--bare', template_dir], options, cwd=self._root_dir)
846 with open(os.path.join(template_dir, 'shallow'), 'w') as template_file:
847 template_file.write(revision)
848 clone_cmd.append('--template=' + template_dir)
849 else:
850 # Otherwise, we're just interested in the HEAD. Just use --depth.
851 clone_cmd.append('--depth=1')
852
[email protected]3534aa52013-07-20 01:58:08853 tmp_dir = tempfile.mkdtemp(
854 prefix='_gclient_%s_' % os.path.basename(self.checkout_path),
855 dir=parent_dir)
856 try:
857 clone_cmd.append(tmp_dir)
[email protected]fd5b6382013-10-25 20:54:34858 self._Run(clone_cmd, options, cwd=self._root_dir, retry=True)
[email protected]3534aa52013-07-20 01:58:08859 gclient_utils.safe_makedirs(self.checkout_path)
[email protected]ef509e42013-09-20 13:19:08860 gclient_utils.safe_rename(os.path.join(tmp_dir, '.git'),
861 os.path.join(self.checkout_path, '.git'))
[email protected]6279e8a2014-02-13 01:45:25862 except:
[email protected]fe0d1902014-04-08 20:50:44863 traceback.print_exc(file=self.out_fh)
[email protected]6279e8a2014-02-13 01:45:25864 raise
[email protected]3534aa52013-07-20 01:58:08865 finally:
866 if os.listdir(tmp_dir):
[email protected]fe0d1902014-04-08 20:50:44867 self.Print('_____ removing non-empty tmp dir %s' % tmp_dir)
[email protected]3534aa52013-07-20 01:58:08868 gclient_utils.rmtree(tmp_dir)
[email protected]5439ea52014-08-06 17:18:18869 if template_dir:
870 gclient_utils.rmtree(template_dir)
[email protected]1a6bec02014-06-02 21:53:29871 self._UpdateBranchHeads(options, fetch=True)
[email protected]d33eab32014-07-07 19:35:18872 self._Checkout(options, revision.replace('refs/heads/', ''), quiet=True)
[email protected]483a0ba2014-05-30 00:06:07873 if self._GetCurrentBranch() is None:
[email protected]786fb682010-06-02 15:16:23874 # Squelch git's very verbose detached HEAD warning and use our own
[email protected]fe0d1902014-04-08 20:50:44875 self.Print(
[email protected]d33eab32014-07-07 19:35:18876 ('Checked out %s to a detached HEAD. Before making any commits\n'
877 'in this repo, you should use \'git checkout <branch>\' to switch to\n'
878 'an existing branch or use \'git checkout %s -b <branch>\' to\n'
879 'create a new branch for your work.') % (revision, self.remote))
[email protected]d90ba3f2010-02-23 14:42:57880
[email protected]6cd41b62014-04-21 23:55:22881 def _AskForData(self, prompt, options):
[email protected]30c46d62014-01-23 12:11:56882 if options.jobs > 1:
[email protected]6cd41b62014-04-21 23:55:22883 self.Print(prompt)
[email protected]30c46d62014-01-23 12:11:56884 raise gclient_utils.Error("Background task requires input. Rerun "
885 "gclient with --jobs=1 so that\n"
886 "interaction is possible.")
887 try:
888 return raw_input(prompt)
889 except KeyboardInterrupt:
890 # Hide the exception.
891 sys.exit(1)
892
893
[email protected]f5d37bf2010-09-02 00:50:34894 def _AttemptRebase(self, upstream, files, options, newbase=None,
[email protected]30c46d62014-01-23 12:11:56895 branch=None, printed_path=False, merge=False):
[email protected]d90ba3f2010-02-23 14:42:57896 """Attempt to rebase onto either upstream or, if specified, newbase."""
[email protected]396e1a62013-07-03 19:41:04897 if files is not None:
898 files.extend(self._Capture(['diff', upstream, '--name-only']).split())
[email protected]d90ba3f2010-02-23 14:42:57899 revision = upstream
900 if newbase:
901 revision = newbase
[email protected]30c46d62014-01-23 12:11:56902 action = 'merge' if merge else 'rebase'
[email protected]d90ba3f2010-02-23 14:42:57903 if not printed_path:
[email protected]fe0d1902014-04-08 20:50:44904 self.Print('_____ %s : Attempting %s onto %s...' % (
[email protected]30c46d62014-01-23 12:11:56905 self.relpath, action, revision))
[email protected]d90ba3f2010-02-23 14:42:57906 printed_path = True
907 else:
[email protected]fe0d1902014-04-08 20:50:44908 self.Print('Attempting %s onto %s...' % (action, revision))
[email protected]30c46d62014-01-23 12:11:56909
910 if merge:
911 merge_output = self._Capture(['merge', revision])
912 if options.verbose:
[email protected]fe0d1902014-04-08 20:50:44913 self.Print(merge_output)
[email protected]30c46d62014-01-23 12:11:56914 return
[email protected]d90ba3f2010-02-23 14:42:57915
916 # Build the rebase command here using the args
917 # git rebase [options] [--onto <newbase>] <upstream> [<branch>]
918 rebase_cmd = ['rebase']
[email protected]f5d37bf2010-09-02 00:50:34919 if options.verbose:
[email protected]d90ba3f2010-02-23 14:42:57920 rebase_cmd.append('--verbose')
921 if newbase:
922 rebase_cmd.extend(['--onto', newbase])
923 rebase_cmd.append(upstream)
924 if branch:
925 rebase_cmd.append(branch)
926
927 try:
[email protected]ad80e3b2010-09-09 14:18:28928 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path)
[email protected]bffad372011-09-08 17:54:22929 except subprocess2.CalledProcessError, e:
[email protected]ad80e3b2010-09-09 14:18:28930 if (re.match(r'cannot rebase: you have unstaged changes', e.stderr) or
931 re.match(r'cannot rebase: your index contains uncommitted changes',
932 e.stderr)):
[email protected]d90ba3f2010-02-23 14:42:57933 while True:
[email protected]30c46d62014-01-23 12:11:56934 rebase_action = self._AskForData(
[email protected]90541732011-04-01 17:54:18935 'Cannot rebase because of unstaged changes.\n'
936 '\'git reset --hard HEAD\' ?\n'
937 'WARNING: destroys any uncommitted work in your current branch!'
[email protected]18fa4542013-05-21 13:30:46938 ' (y)es / (q)uit / (s)how : ', options)
[email protected]d90ba3f2010-02-23 14:42:57939 if re.match(r'yes|y', rebase_action, re.I):
[email protected]37e89872010-09-07 16:11:33940 self._Run(['reset', '--hard', 'HEAD'], options)
[email protected]d90ba3f2010-02-23 14:42:57941 # Should this be recursive?
[email protected]ad80e3b2010-09-09 14:18:28942 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path)
[email protected]d90ba3f2010-02-23 14:42:57943 break
944 elif re.match(r'quit|q', rebase_action, re.I):
945 raise gclient_utils.Error("Please merge or rebase manually\n"
946 "cd %s && git " % self.checkout_path
947 + "%s" % ' '.join(rebase_cmd))
948 elif re.match(r'show|s', rebase_action, re.I):
[email protected]fe0d1902014-04-08 20:50:44949 self.Print('%s' % e.stderr.strip())
[email protected]d90ba3f2010-02-23 14:42:57950 continue
951 else:
952 gclient_utils.Error("Input not recognized")
953 continue
954 elif re.search(r'^CONFLICT', e.stdout, re.M):
955 raise gclient_utils.Error("Conflict while rebasing this branch.\n"
956 "Fix the conflict and run gclient again.\n"
957 "See 'man git-rebase' for details.\n")
958 else:
[email protected]fe0d1902014-04-08 20:50:44959 self.Print(e.stdout.strip())
960 self.Print('Rebase produced error output:\n%s' % e.stderr.strip())
[email protected]d90ba3f2010-02-23 14:42:57961 raise gclient_utils.Error("Unrecognized error, please merge or rebase "
962 "manually.\ncd %s && git " %
963 self.checkout_path
964 + "%s" % ' '.join(rebase_cmd))
965
[email protected]fe0d1902014-04-08 20:50:44966 self.Print(rebase_output.strip())
[email protected]f5d37bf2010-09-02 00:50:34967 if not options.verbose:
[email protected]d90ba3f2010-02-23 14:42:57968 # Make the output a little prettier. It's nice to have some
969 # whitespace between projects when syncing.
[email protected]fe0d1902014-04-08 20:50:44970 self.Print('')
[email protected]d90ba3f2010-02-23 14:42:57971
[email protected]6e29d572010-06-04 17:32:20972 @staticmethod
973 def _CheckMinVersion(min_version):
[email protected]d0f854a2010-03-11 19:35:53974 (ok, current_version) = scm.GIT.AssertVersion(min_version)
975 if not ok:
976 raise gclient_utils.Error('git version %s < minimum required %s' %
977 (current_version, min_version))
[email protected]923a0372009-12-11 20:42:43978
[email protected]786fb682010-06-02 15:16:23979 def _IsRebasing(self):
980 # Check for any of REBASE-i/REBASE-m/REBASE/AM. Unfortunately git doesn't
981 # have a plumbing command to determine whether a rebase is in progress, so
982 # for now emualate (more-or-less) git-rebase.sh / git-completion.bash
983 g = os.path.join(self.checkout_path, '.git')
984 return (
985 os.path.isdir(os.path.join(g, "rebase-merge")) or
986 os.path.isdir(os.path.join(g, "rebase-apply")))
987
988 def _CheckClean(self, rev_str):
989 # Make sure the tree is clean; see git-rebase.sh for reference
990 try:
991 scm.GIT.Capture(['update-index', '--ignore-submodules', '--refresh'],
[email protected]ad80e3b2010-09-09 14:18:28992 cwd=self.checkout_path)
[email protected]bffad372011-09-08 17:54:22993 except subprocess2.CalledProcessError:
[email protected]6e29d572010-06-04 17:32:20994 raise gclient_utils.Error('\n____ %s%s\n'
995 '\tYou have unstaged changes.\n'
996 '\tPlease commit, stash, or reset.\n'
997 % (self.relpath, rev_str))
[email protected]786fb682010-06-02 15:16:23998 try:
999 scm.GIT.Capture(['diff-index', '--cached', '--name-status', '-r',
[email protected]ad80e3b2010-09-09 14:18:281000 '--ignore-submodules', 'HEAD', '--'],
1001 cwd=self.checkout_path)
[email protected]bffad372011-09-08 17:54:221002 except subprocess2.CalledProcessError:
[email protected]6e29d572010-06-04 17:32:201003 raise gclient_utils.Error('\n____ %s%s\n'
1004 '\tYour index contains uncommitted changes\n'
1005 '\tPlease commit, stash, or reset.\n'
1006 % (self.relpath, rev_str))
[email protected]786fb682010-06-02 15:16:231007
[email protected]396e1a62013-07-03 19:41:041008 def _CheckDetachedHead(self, rev_str, _options):
[email protected]786fb682010-06-02 15:16:231009 # HEAD is detached. Make sure it is safe to move away from (i.e., it is
1010 # reference by a commit). If not, error out -- most likely a rebase is
1011 # in progress, try to detect so we can give a better error.
1012 try:
[email protected]ad80e3b2010-09-09 14:18:281013 scm.GIT.Capture(['name-rev', '--no-undefined', 'HEAD'],
1014 cwd=self.checkout_path)
[email protected]bffad372011-09-08 17:54:221015 except subprocess2.CalledProcessError:
[email protected]786fb682010-06-02 15:16:231016 # Commit is not contained by any rev. See if the user is rebasing:
1017 if self._IsRebasing():
1018 # Punt to the user
1019 raise gclient_utils.Error('\n____ %s%s\n'
1020 '\tAlready in a conflict, i.e. (no branch).\n'
1021 '\tFix the conflict and run gclient again.\n'
1022 '\tOr to abort run:\n\t\tgit-rebase --abort\n'
1023 '\tSee man git-rebase for details.\n'
1024 % (self.relpath, rev_str))
1025 # Let's just save off the commit so we can proceed.
[email protected]6cafa132010-09-07 14:17:261026 name = ('saved-by-gclient-' +
1027 self._Capture(['rev-parse', '--short', 'HEAD']))
[email protected]77bd7362013-09-25 23:46:141028 self._Capture(['branch', '-f', name])
[email protected]fe0d1902014-04-08 20:50:441029 self.Print('_____ found an unreferenced commit and saved it as \'%s\'' %
[email protected]f5d37bf2010-09-02 00:50:341030 name)
[email protected]786fb682010-06-02 15:16:231031
[email protected]5bde4852009-12-14 16:47:121032 def _GetCurrentBranch(self):
[email protected]786fb682010-06-02 15:16:231033 # Returns name of current branch or None for detached HEAD
[email protected]6cafa132010-09-07 14:17:261034 branch = self._Capture(['rev-parse', '--abbrev-ref=strict', 'HEAD'])
[email protected]786fb682010-06-02 15:16:231035 if branch == 'HEAD':
[email protected]5bde4852009-12-14 16:47:121036 return None
1037 return branch
1038
[email protected]c3e09d22014-04-10 13:58:181039 def _Capture(self, args, **kwargs):
[email protected]fe0d1902014-04-08 20:50:441040 kwargs.setdefault('cwd', self.checkout_path)
1041 kwargs.setdefault('stderr', subprocess2.PIPE)
[email protected]6d8115d2014-04-23 20:59:231042 env = scm.GIT.ApplyEnvVars(kwargs)
1043 return subprocess2.check_output(['git'] + args, env=env, **kwargs).strip()
[email protected]6cafa132010-09-07 14:17:261044
[email protected]bb424c02014-06-23 22:42:511045 def _Checkout(self, options, ref, force=False, quiet=None):
1046 """Performs a 'git-checkout' operation.
1047
1048 Args:
1049 options: The configured option set
1050 ref: (str) The branch/commit to checkout
1051 quiet: (bool/None) Whether or not the checkout shoud pass '--quiet'; if
1052 'None', the behavior is inferred from 'options.verbose'.
1053 Returns: (str) The output of the checkout operation
1054 """
1055 if quiet is None:
1056 quiet = (not options.verbose)
1057 checkout_args = ['checkout']
1058 if force:
1059 checkout_args.append('--force')
1060 if quiet:
1061 checkout_args.append('--quiet')
1062 checkout_args.append(ref)
1063 return self._Capture(checkout_args)
1064
[email protected]680f2172014-06-25 00:39:321065 def _Fetch(self, options, remote=None, prune=False, quiet=False):
1066 cfg = gclient_utils.DefaultIndexPackConfig(self.url)
1067 fetch_cmd = cfg + [
1068 'fetch',
1069 remote or self.remote,
1070 ]
1071
1072 if prune:
1073 fetch_cmd.append('--prune')
1074 if options.verbose:
1075 fetch_cmd.append('--verbose')
1076 elif quiet:
1077 fetch_cmd.append('--quiet')
1078 self._Run(fetch_cmd, options, show_header=options.verbose, retry=True)
1079
1080 # Return the revision that was fetched; this will be stored in 'FETCH_HEAD'
1081 return self._Capture(['rev-parse', '--verify', 'FETCH_HEAD'])
1082
[email protected]e409df62013-04-16 17:28:571083 def _UpdateBranchHeads(self, options, fetch=False):
[email protected]8d3348f2014-08-19 22:49:161084 """Adds, and optionally fetches, "branch-heads" and "tags" refspecs
1085 if requested."""
1086 need_fetch = fetch
[email protected]e409df62013-04-16 17:28:571087 if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
[email protected]1a60dca2013-11-26 14:06:261088 config_cmd = ['config', 'remote.%s.fetch' % self.remote,
[email protected]f2d7d6b2013-10-17 20:41:431089 '+refs/branch-heads/*:refs/remotes/branch-heads/*',
1090 '^\\+refs/branch-heads/\\*:.*$']
1091 self._Run(config_cmd, options)
[email protected]8d3348f2014-08-19 22:49:161092 need_fetch = True
1093 if hasattr(options, 'with_tags') and options.with_tags:
1094 config_cmd = ['config', 'remote.%s.fetch' % self.remote,
1095 '+refs/tags/*:refs/tags/*',
1096 '^\\+refs/tags/\\*:.*$']
1097 self._Run(config_cmd, options)
1098 need_fetch = True
1099 if fetch and need_fetch:
1100 self._Fetch(options)
[email protected]e409df62013-04-16 17:28:571101
[email protected]680f2172014-06-25 00:39:321102 def _Run(self, args, options, show_header=True, **kwargs):
1103 # Disable 'unused options' warning | pylint: disable=W0613
[email protected]fe0d1902014-04-08 20:50:441104 cwd = kwargs.setdefault('cwd', self.checkout_path)
1105 kwargs.setdefault('stdout', self.out_fh)
[email protected]848fd492014-04-09 19:06:441106 kwargs['filter_fn'] = self.filter
[email protected]fe0d1902014-04-08 20:50:441107 kwargs.setdefault('print_stdout', False)
[email protected]6d8115d2014-04-23 20:59:231108 env = scm.GIT.ApplyEnvVars(kwargs)
[email protected]772efaf2014-04-01 02:35:441109 cmd = ['git'] + args
[email protected]680f2172014-06-25 00:39:321110 if show_header:
1111 header = "running '%s' in '%s'" % (' '.join(cmd), cwd)
1112 self.filter(header)
[email protected]6d8115d2014-04-23 20:59:231113 return gclient_utils.CheckCallAndFilter(cmd, env=env, **kwargs)
[email protected]e28e4982009-09-25 20:51:451114
1115
[email protected]55e724e2010-03-11 19:36:491116class SVNWrapper(SCMWrapper):
[email protected]cb5442b2009-09-22 16:51:241117 """ Wrapper for SVN """
[email protected]2702bcd2013-09-24 19:10:071118 name = 'svn'
[email protected]5f3eee32009-09-17 00:34:301119
[email protected]9e3e82c2012-04-18 12:55:431120 @staticmethod
1121 def BinaryExists():
1122 """Returns true if the command exists."""
1123 try:
1124 result, version = scm.SVN.AssertVersion('1.4')
1125 if not result:
1126 raise gclient_utils.Error('SVN version is older than 1.4: %s' % version)
1127 return result
1128 except OSError:
1129 return False
1130
[email protected]885a9602013-05-31 09:54:401131 def GetCheckoutRoot(self):
1132 return scm.SVN.GetCheckoutRoot(self.checkout_path)
1133
[email protected]eaab7842011-04-28 09:07:581134 def GetRevisionDate(self, revision):
1135 """Returns the given revision's date in ISO-8601 format (which contains the
1136 time zone)."""
[email protected]d579fcf2011-12-13 20:36:031137 date = scm.SVN.Capture(
1138 ['propget', '--revprop', 'svn:date', '-r', revision],
1139 os.path.join(self.checkout_path, '.'))
[email protected]eaab7842011-04-28 09:07:581140 return date.strip()
1141
[email protected]396e1a62013-07-03 19:41:041142 def cleanup(self, options, args, _file_list):
[email protected]5f3eee32009-09-17 00:34:301143 """Cleanup working copy."""
[email protected]669600d2010-09-01 19:06:311144 self._Run(['cleanup'] + args, options)
[email protected]5f3eee32009-09-17 00:34:301145
[email protected]396e1a62013-07-03 19:41:041146 def diff(self, options, args, _file_list):
[email protected]5f3eee32009-09-17 00:34:301147 # NOTE: This function does not currently modify file_list.
[email protected]8469bf92010-09-03 19:03:151148 if not os.path.isdir(self.checkout_path):
1149 raise gclient_utils.Error('Directory %s is not present.' %
1150 self.checkout_path)
[email protected]669600d2010-09-01 19:06:311151 self._Run(['diff'] + args, options)
[email protected]5f3eee32009-09-17 00:34:301152
[email protected]396e1a62013-07-03 19:41:041153 def pack(self, _options, args, _file_list):
[email protected]ee4071d2009-12-22 22:25:371154 """Generates a patch file which can be applied to the root of the
1155 repository."""
[email protected]8469bf92010-09-03 19:03:151156 if not os.path.isdir(self.checkout_path):
1157 raise gclient_utils.Error('Directory %s is not present.' %
1158 self.checkout_path)
1159 gclient_utils.CheckCallAndFilter(
1160 ['svn', 'diff', '-x', '--ignore-eol-style'] + args,
1161 cwd=self.checkout_path,
1162 print_stdout=False,
[email protected]fe0d1902014-04-08 20:50:441163 filter_fn=SvnDiffFilterer(self.relpath).Filter, print_func=self.Print)
[email protected]ee4071d2009-12-22 22:25:371164
[email protected]5f3eee32009-09-17 00:34:301165 def update(self, options, args, file_list):
[email protected]d6504212010-01-13 17:34:311166 """Runs svn to update or transparently checkout the working copy.
[email protected]5f3eee32009-09-17 00:34:301167
1168 All updated files will be appended to file_list.
1169
1170 Raises:
1171 Error: if can't get URL for relative path.
1172 """
[email protected]b09097a2014-04-09 19:09:081173 # Only update if hg is not controlling the directory.
[email protected]6c2b49d2014-02-26 23:57:381174 hg_path = os.path.join(self.checkout_path, '.hg')
1175 if os.path.exists(hg_path):
[email protected]fe0d1902014-04-08 20:50:441176 self.Print('________ found .hg directory; skipping %s' % self.relpath)
[email protected]6c2b49d2014-02-26 23:57:381177 return
1178
[email protected]5f3eee32009-09-17 00:34:301179 if args:
1180 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
1181
[email protected]8e0e9262010-08-17 19:20:271182 # revision is the revision to match. It is None if no revision is specified,
1183 # i.e. the 'deps ain't pinned'.
[email protected]ac915bb2009-11-13 17:03:011184 url, revision = gclient_utils.SplitUrlRevision(self.url)
[email protected]50fd47f2014-02-13 01:03:191185 # Keep the original unpinned url for reference in case the repo is switched.
1186 base_url = url
[email protected]eb2756d2011-09-20 20:17:511187 managed = True
[email protected]5f3eee32009-09-17 00:34:301188 if options.revision:
1189 # Override the revision number.
[email protected]ac915bb2009-11-13 17:03:011190 revision = str(options.revision)
[email protected]5f3eee32009-09-17 00:34:301191 if revision:
[email protected]eb2756d2011-09-20 20:17:511192 if revision != 'unmanaged':
1193 forced_revision = True
1194 # Reconstruct the url.
1195 url = '%s@%s' % (url, revision)
1196 rev_str = ' at %s' % revision
1197 else:
1198 managed = False
1199 revision = None
[email protected]8e0e9262010-08-17 19:20:271200 else:
1201 forced_revision = False
1202 rev_str = ''
[email protected]5f3eee32009-09-17 00:34:301203
[email protected]d0b0a5b2014-03-10 19:30:211204 exists = os.path.exists(self.checkout_path)
[email protected]7ff04292014-03-10 12:57:251205 if exists and managed:
[email protected]b09097a2014-04-09 19:09:081206 # Git is only okay if it's a git-svn checkout of the right repo.
1207 if scm.GIT.IsGitSvn(self.checkout_path):
1208 remote_url = scm.GIT.Capture(['config', '--local', '--get',
1209 'svn-remote.svn.url'],
1210 cwd=self.checkout_path).rstrip()
1211 if remote_url.rstrip('/') == base_url.rstrip('/'):
[email protected]b2256212014-05-07 20:57:281212 self.Print('\n_____ %s looks like a git-svn checkout. Skipping.'
1213 % self.relpath)
[email protected]b09097a2014-04-09 19:09:081214 return # TODO(borenet): Get the svn revision number?
1215
1216 # Get the existing scm url and the revision number of the current checkout.
1217 if exists and managed:
[email protected]13349e22012-11-15 17:11:281218 try:
1219 from_info = scm.SVN.CaptureLocalInfo(
1220 [], os.path.join(self.checkout_path, '.'))
1221 except (gclient_utils.Error, subprocess2.CalledProcessError):
[email protected]b09097a2014-04-09 19:09:081222 self._DeleteOrMove(options.force)
1223 exists = False
[email protected]13349e22012-11-15 17:11:281224
[email protected]2f2ca142014-01-07 03:59:181225 BASE_URLS = {
1226 '/chrome/trunk/src': 'gs://chromium-svn-checkout/chrome/',
1227 '/blink/trunk': 'gs://chromium-svn-checkout/blink/',
1228 }
[email protected]ca35be32014-01-17 01:48:181229 WHITELISTED_ROOTS = [
1230 'svn://svn.chromium.org',
1231 'svn://svn-mirror.golo.chromium.org',
1232 ]
[email protected]13349e22012-11-15 17:11:281233 if not exists:
[email protected]2f2ca142014-01-07 03:59:181234 try:
1235 # Split out the revision number since it's not useful for us.
1236 base_path = urlparse.urlparse(url).path.split('@')[0]
[email protected]ca35be32014-01-17 01:48:181237 # Check to see if we're on a whitelisted root. We do this because
1238 # only some svn servers have matching UUIDs.
1239 local_parsed = urlparse.urlparse(url)
1240 local_root = '%s://%s' % (local_parsed.scheme, local_parsed.netloc)
[email protected]2f2ca142014-01-07 03:59:181241 if ('CHROME_HEADLESS' in os.environ
1242 and sys.platform == 'linux2' # TODO(hinoka): Enable for win/mac.
[email protected]ca35be32014-01-17 01:48:181243 and base_path in BASE_URLS
1244 and local_root in WHITELISTED_ROOTS):
1245
[email protected]2f2ca142014-01-07 03:59:181246 # Use a tarball for initial sync if we are on a bot.
1247 # Get an unauthenticated gsutil instance.
1248 gsutil = download_from_google_storage.Gsutil(
1249 GSUTIL_DEFAULT_PATH, boto_path=os.devnull)
1250
1251 gs_path = BASE_URLS[base_path]
1252 _, out, _ = gsutil.check_call('ls', gs_path)
1253 # So that we can get the most recent revision.
1254 sorted_items = sorted(out.splitlines())
1255 latest_checkout = sorted_items[-1]
1256
1257 tempdir = tempfile.mkdtemp()
[email protected]fe0d1902014-04-08 20:50:441258 self.Print('Downloading %s...' % latest_checkout)
[email protected]2f2ca142014-01-07 03:59:181259 code, out, err = gsutil.check_call('cp', latest_checkout, tempdir)
1260 if code:
[email protected]fe0d1902014-04-08 20:50:441261 self.Print('%s\n%s' % (out, err))
[email protected]2f2ca142014-01-07 03:59:181262 raise Exception()
1263 filename = latest_checkout.split('/')[-1]
1264 tarball = os.path.join(tempdir, filename)
[email protected]fe0d1902014-04-08 20:50:441265 self.Print('Unpacking into %s...' % self.checkout_path)
[email protected]2f2ca142014-01-07 03:59:181266 gclient_utils.safe_makedirs(self.checkout_path)
1267 # TODO(hinoka): Use 7z for windows.
1268 cmd = ['tar', '--extract', '--ungzip',
1269 '--directory', self.checkout_path,
1270 '--file', tarball]
1271 gclient_utils.CheckCallAndFilter(
1272 cmd, stdout=sys.stdout, print_stdout=True)
1273
[email protected]fe0d1902014-04-08 20:50:441274 self.Print('Deleting temp file')
[email protected]2f2ca142014-01-07 03:59:181275 gclient_utils.rmtree(tempdir)
1276
1277 # Rewrite the repository root to match.
1278 tarball_url = scm.SVN.CaptureLocalInfo(
1279 ['.'], self.checkout_path)['Repository Root']
1280 tarball_parsed = urlparse.urlparse(tarball_url)
1281 tarball_root = '%s://%s' % (tarball_parsed.scheme,
1282 tarball_parsed.netloc)
[email protected]2f2ca142014-01-07 03:59:181283
1284 if tarball_root != local_root:
[email protected]fe0d1902014-04-08 20:50:441285 self.Print('Switching repository root to %s' % local_root)
[email protected]2f2ca142014-01-07 03:59:181286 self._Run(['switch', '--relocate', tarball_root,
1287 local_root, self.checkout_path],
1288 options)
1289 except Exception as e:
[email protected]fe0d1902014-04-08 20:50:441290 self.Print('We tried to get a source tarball but failed.')
1291 self.Print('Resuming normal operations.')
1292 self.Print(str(e))
[email protected]2f2ca142014-01-07 03:59:181293
[email protected]6c48a302011-10-20 23:44:201294 gclient_utils.safe_makedirs(os.path.dirname(self.checkout_path))
[email protected]5f3eee32009-09-17 00:34:301295 # We need to checkout.
[email protected]8469bf92010-09-03 19:03:151296 command = ['checkout', url, self.checkout_path]
[email protected]8e0e9262010-08-17 19:20:271297 command = self._AddAdditionalUpdateFlags(command, options, revision)
[email protected]669600d2010-09-01 19:06:311298 self._RunAndGetFileList(command, options, file_list, self._root_dir)
[email protected]2702bcd2013-09-24 19:10:071299 return self.Svnversion()
[email protected]5f3eee32009-09-17 00:34:301300
[email protected]6c2b49d2014-02-26 23:57:381301 if not managed:
[email protected]fe0d1902014-04-08 20:50:441302 self.Print(('________ unmanaged solution; skipping %s' % self.relpath))
[email protected]b09097a2014-04-09 19:09:081303 if os.path.exists(os.path.join(self.checkout_path, '.svn')):
1304 return self.Svnversion()
1305 return
[email protected]6c2b49d2014-02-26 23:57:381306
[email protected]49fcb0c2011-09-23 14:34:381307 if 'URL' not in from_info:
1308 raise gclient_utils.Error(
1309 ('gclient is confused. Couldn\'t get the url for %s.\n'
1310 'Try using @unmanaged.\n%s') % (
1311 self.checkout_path, from_info))
1312
[email protected]3031d732014-04-21 22:18:021313 # Look for locked directories.
1314 dir_info = scm.SVN.CaptureStatus(
1315 None, os.path.join(self.checkout_path, '.'))
1316 if any(d[0][2] == 'L' for d in dir_info):
1317 try:
1318 self._Run(['cleanup', self.checkout_path], options)
1319 except subprocess2.CalledProcessError, e:
1320 # Get the status again, svn cleanup may have cleaned up at least
1321 # something.
1322 dir_info = scm.SVN.CaptureStatus(
1323 None, os.path.join(self.checkout_path, '.'))
1324
[email protected]d558c4b2011-09-22 18:56:241325 # Try to fix the failures by removing troublesome files.
1326 for d in dir_info:
1327 if d[0][2] == 'L':
1328 if d[0][0] == '!' and options.force:
[email protected]1580d952013-08-19 07:31:401329 # We don't pass any files/directories to CaptureStatus and set
1330 # cwd=self.checkout_path, so we should get relative paths here.
1331 assert not os.path.isabs(d[1])
1332 path_to_remove = os.path.normpath(
1333 os.path.join(self.checkout_path, d[1]))
[email protected]fe0d1902014-04-08 20:50:441334 self.Print('Removing troublesome path %s' % path_to_remove)
[email protected]1580d952013-08-19 07:31:401335 gclient_utils.rmtree(path_to_remove)
[email protected]d558c4b2011-09-22 18:56:241336 else:
[email protected]fe0d1902014-04-08 20:50:441337 self.Print(
1338 'Not removing troublesome path %s automatically.' % d[1])
[email protected]d558c4b2011-09-22 18:56:241339 if d[0][0] == '!':
[email protected]fe0d1902014-04-08 20:50:441340 self.Print('You can pass --force to enable automatic removal.')
[email protected]d558c4b2011-09-22 18:56:241341 raise e
[email protected]e407c9a2010-08-09 19:11:371342
[email protected]8e0e9262010-08-17 19:20:271343 # Retrieve the current HEAD version because svn is slow at null updates.
1344 if options.manually_grab_svn_rev and not revision:
[email protected]d579fcf2011-12-13 20:36:031345 from_info_live = scm.SVN.CaptureRemoteInfo(from_info['URL'])
[email protected]8e0e9262010-08-17 19:20:271346 revision = str(from_info_live['Revision'])
1347 rev_str = ' at %s' % revision
[email protected]5f3eee32009-09-17 00:34:301348
[email protected]b09097a2014-04-09 19:09:081349 if from_info['URL'].rstrip('/') != base_url.rstrip('/'):
[email protected]6c2b49d2014-02-26 23:57:381350 # The repository url changed, need to switch.
1351 try:
1352 to_info = scm.SVN.CaptureRemoteInfo(url)
1353 except (gclient_utils.Error, subprocess2.CalledProcessError):
1354 # The url is invalid or the server is not accessible, it's safer to bail
1355 # out right now.
1356 raise gclient_utils.Error('This url is unreachable: %s' % url)
1357 can_switch = ((from_info['Repository Root'] != to_info['Repository Root'])
1358 and (from_info['UUID'] == to_info['UUID']))
1359 if can_switch:
[email protected]fe0d1902014-04-08 20:50:441360 self.Print('_____ relocating %s to a new checkout' % self.relpath)
[email protected]6c2b49d2014-02-26 23:57:381361 # We have different roots, so check if we can switch --relocate.
1362 # Subversion only permits this if the repository UUIDs match.
1363 # Perform the switch --relocate, then rewrite the from_url
1364 # to reflect where we "are now." (This is the same way that
1365 # Subversion itself handles the metadata when switch --relocate
1366 # is used.) This makes the checks below for whether we
1367 # can update to a revision or have to switch to a different
1368 # branch work as expected.
1369 # TODO(maruel): TEST ME !
1370 command = ['switch', '--relocate',
1371 from_info['Repository Root'],
1372 to_info['Repository Root'],
1373 self.relpath]
1374 self._Run(command, options, cwd=self._root_dir)
1375 from_info['URL'] = from_info['URL'].replace(
1376 from_info['Repository Root'],
1377 to_info['Repository Root'])
1378 else:
1379 if not options.force and not options.reset:
1380 # Look for local modifications but ignore unversioned files.
1381 for status in scm.SVN.CaptureStatus(None, self.checkout_path):
1382 if status[0][0] != '?':
1383 raise gclient_utils.Error(
1384 ('Can\'t switch the checkout to %s; UUID don\'t match and '
1385 'there is local changes in %s. Delete the directory and '
1386 'try again.') % (url, self.checkout_path))
1387 # Ok delete it.
[email protected]fe0d1902014-04-08 20:50:441388 self.Print('_____ switching %s to a new checkout' % self.relpath)
[email protected]6c2b49d2014-02-26 23:57:381389 gclient_utils.rmtree(self.checkout_path)
1390 # We need to checkout.
1391 command = ['checkout', url, self.checkout_path]
1392 command = self._AddAdditionalUpdateFlags(command, options, revision)
1393 self._RunAndGetFileList(command, options, file_list, self._root_dir)
1394 return self.Svnversion()
1395
[email protected]5f3eee32009-09-17 00:34:301396 # If the provided url has a revision number that matches the revision
1397 # number of the existing directory, then we don't need to bother updating.
[email protected]2e0c6852009-09-24 00:02:071398 if not options.force and str(from_info['Revision']) == revision:
[email protected]5f3eee32009-09-17 00:34:301399 if options.verbose or not forced_revision:
[email protected]fe0d1902014-04-08 20:50:441400 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
[email protected]98e69452012-02-16 16:36:431401 else:
1402 command = ['update', self.checkout_path]
1403 command = self._AddAdditionalUpdateFlags(command, options, revision)
1404 self._RunAndGetFileList(command, options, file_list, self._root_dir)
[email protected]5f3eee32009-09-17 00:34:301405
[email protected]98e69452012-02-16 16:36:431406 # If --reset and --delete_unversioned_trees are specified, remove any
1407 # untracked files and directories.
1408 if options.reset and options.delete_unversioned_trees:
1409 for status in scm.SVN.CaptureStatus(None, self.checkout_path):
1410 full_path = os.path.join(self.checkout_path, status[1])
1411 if (status[0][0] == '?'
1412 and os.path.isdir(full_path)
1413 and not os.path.islink(full_path)):
[email protected]fe0d1902014-04-08 20:50:441414 self.Print('_____ removing unversioned directory %s' % status[1])
[email protected]dc112ac2013-04-24 13:00:191415 gclient_utils.rmtree(full_path)
[email protected]2702bcd2013-09-24 19:10:071416 return self.Svnversion()
[email protected]5f3eee32009-09-17 00:34:301417
[email protected]4b5b1772010-04-08 01:52:561418 def updatesingle(self, options, args, file_list):
[email protected]4b5b1772010-04-08 01:52:561419 filename = args.pop()
[email protected]57564662010-04-14 02:35:121420 if scm.SVN.AssertVersion("1.5")[0]:
[email protected]8469bf92010-09-03 19:03:151421 if not os.path.exists(os.path.join(self.checkout_path, '.svn')):
[email protected]57564662010-04-14 02:35:121422 # Create an empty checkout and then update the one file we want. Future
1423 # operations will only apply to the one file we checked out.
[email protected]8469bf92010-09-03 19:03:151424 command = ["checkout", "--depth", "empty", self.url, self.checkout_path]
[email protected]669600d2010-09-01 19:06:311425 self._Run(command, options, cwd=self._root_dir)
[email protected]8469bf92010-09-03 19:03:151426 if os.path.exists(os.path.join(self.checkout_path, filename)):
1427 os.remove(os.path.join(self.checkout_path, filename))
[email protected]57564662010-04-14 02:35:121428 command = ["update", filename]
[email protected]669600d2010-09-01 19:06:311429 self._RunAndGetFileList(command, options, file_list)
[email protected]57564662010-04-14 02:35:121430 # After the initial checkout, we can use update as if it were any other
1431 # dep.
1432 self.update(options, args, file_list)
1433 else:
1434 # If the installed version of SVN doesn't support --depth, fallback to
1435 # just exporting the file. This has the downside that revision
1436 # information is not stored next to the file, so we will have to
1437 # re-export the file every time we sync.
[email protected]8469bf92010-09-03 19:03:151438 if not os.path.exists(self.checkout_path):
[email protected]6c48a302011-10-20 23:44:201439 gclient_utils.safe_makedirs(self.checkout_path)
[email protected]57564662010-04-14 02:35:121440 command = ["export", os.path.join(self.url, filename),
[email protected]8469bf92010-09-03 19:03:151441 os.path.join(self.checkout_path, filename)]
[email protected]8e0e9262010-08-17 19:20:271442 command = self._AddAdditionalUpdateFlags(command, options,
1443 options.revision)
[email protected]669600d2010-09-01 19:06:311444 self._Run(command, options, cwd=self._root_dir)
[email protected]4b5b1772010-04-08 01:52:561445
[email protected]396e1a62013-07-03 19:41:041446 def revert(self, options, _args, file_list):
[email protected]5f3eee32009-09-17 00:34:301447 """Reverts local modifications. Subversion specific.
1448
1449 All reverted files will be appended to file_list, even if Subversion
1450 doesn't know about them.
1451 """
[email protected]8469bf92010-09-03 19:03:151452 if not os.path.isdir(self.checkout_path):
[email protected]c0cc0872011-10-12 17:02:411453 if os.path.exists(self.checkout_path):
1454 gclient_utils.rmtree(self.checkout_path)
[email protected]5f3eee32009-09-17 00:34:301455 # svn revert won't work if the directory doesn't exist. It needs to
1456 # checkout instead.
[email protected]fe0d1902014-04-08 20:50:441457 self.Print('_____ %s is missing, synching instead' % self.relpath)
[email protected]5f3eee32009-09-17 00:34:301458 # Don't reuse the args.
1459 return self.update(options, [], file_list)
1460
[email protected]c0cc0872011-10-12 17:02:411461 if not os.path.isdir(os.path.join(self.checkout_path, '.svn')):
[email protected]50fd47f2014-02-13 01:03:191462 if os.path.isdir(os.path.join(self.checkout_path, '.git')):
[email protected]fe0d1902014-04-08 20:50:441463 self.Print('________ found .git directory; skipping %s' % self.relpath)
[email protected]50fd47f2014-02-13 01:03:191464 return
[email protected]6c2b49d2014-02-26 23:57:381465 if os.path.isdir(os.path.join(self.checkout_path, '.hg')):
[email protected]fe0d1902014-04-08 20:50:441466 self.Print('________ found .hg directory; skipping %s' % self.relpath)
[email protected]6c2b49d2014-02-26 23:57:381467 return
[email protected]c0cc0872011-10-12 17:02:411468 if not options.force:
1469 raise gclient_utils.Error('Invalid checkout path, aborting')
[email protected]fe0d1902014-04-08 20:50:441470 self.Print(
[email protected]c0cc0872011-10-12 17:02:411471 '\n_____ %s is not a valid svn checkout, synching instead' %
1472 self.relpath)
1473 gclient_utils.rmtree(self.checkout_path)
1474 # Don't reuse the args.
1475 return self.update(options, [], file_list)
1476
[email protected]07ab60e2011-02-08 21:54:001477 def printcb(file_status):
[email protected]396e1a62013-07-03 19:41:041478 if file_list is not None:
1479 file_list.append(file_status[1])
[email protected]aa3dd472009-09-21 19:02:481480 if logging.getLogger().isEnabledFor(logging.INFO):
[email protected]07ab60e2011-02-08 21:54:001481 logging.info('%s%s' % (file_status[0], file_status[1]))
[email protected]aa3dd472009-09-21 19:02:481482 else:
[email protected]fe0d1902014-04-08 20:50:441483 self.Print(os.path.join(self.checkout_path, file_status[1]))
[email protected]07ab60e2011-02-08 21:54:001484 scm.SVN.Revert(self.checkout_path, callback=printcb)
[email protected]aa3dd472009-09-21 19:02:481485
[email protected]8b322b32011-11-01 19:05:501486 # Revert() may delete the directory altogether.
1487 if not os.path.isdir(self.checkout_path):
1488 # Don't reuse the args.
1489 return self.update(options, [], file_list)
1490
[email protected]810a50b2009-10-05 23:03:181491 try:
1492 # svn revert is so broken we don't even use it. Using
1493 # "svn up --revision BASE" achieve the same effect.
[email protected]07ab60e2011-02-08 21:54:001494 # file_list will contain duplicates.
[email protected]669600d2010-09-01 19:06:311495 self._RunAndGetFileList(['update', '--revision', 'BASE'], options,
1496 file_list)
[email protected]810a50b2009-10-05 23:03:181497 except OSError, e:
[email protected]07ab60e2011-02-08 21:54:001498 # Maybe the directory disapeared meanwhile. Do not throw an exception.
[email protected]810a50b2009-10-05 23:03:181499 logging.error('Failed to update:\n%s' % str(e))
[email protected]5f3eee32009-09-17 00:34:301500
[email protected]396e1a62013-07-03 19:41:041501 def revinfo(self, _options, _args, _file_list):
[email protected]0f282062009-11-06 20:14:021502 """Display revision"""
[email protected]54019f32010-09-09 13:50:111503 try:
1504 return scm.SVN.CaptureRevision(self.checkout_path)
[email protected]31cb48a2011-04-04 18:01:361505 except (gclient_utils.Error, subprocess2.CalledProcessError):
[email protected]54019f32010-09-09 13:50:111506 return None
[email protected]0f282062009-11-06 20:14:021507
[email protected]cb5442b2009-09-22 16:51:241508 def runhooks(self, options, args, file_list):
1509 self.status(options, args, file_list)
1510
[email protected]5f3eee32009-09-17 00:34:301511 def status(self, options, args, file_list):
1512 """Display status information."""
[email protected]669600d2010-09-01 19:06:311513 command = ['status'] + args
[email protected]8469bf92010-09-03 19:03:151514 if not os.path.isdir(self.checkout_path):
[email protected]5f3eee32009-09-17 00:34:301515 # svn status won't work if the directory doesn't exist.
[email protected]fe0d1902014-04-08 20:50:441516 self.Print(('\n________ couldn\'t run \'%s\' in \'%s\':\n'
[email protected]77e4eca2010-09-21 13:23:071517 'The directory does not exist.') %
1518 (' '.join(command), self.checkout_path))
[email protected]5f3eee32009-09-17 00:34:301519 # There's no file list to retrieve.
1520 else:
[email protected]669600d2010-09-01 19:06:311521 self._RunAndGetFileList(command, options, file_list)
[email protected]e6f78352010-01-13 17:05:331522
[email protected]396e1a62013-07-03 19:41:041523 def GetUsableRev(self, rev, _options):
[email protected]e5d1e612011-12-19 19:49:191524 """Verifies the validity of the revision for this repository."""
1525 if not scm.SVN.IsValidRevision(url='%s@%s' % (self.url, rev)):
1526 raise gclient_utils.Error(
1527 ( '%s isn\'t a valid revision. Please check that your safesync_url is\n'
1528 'correct.') % rev)
1529 return rev
1530
[email protected]e6f78352010-01-13 17:05:331531 def FullUrlForRelativeUrl(self, url):
1532 # Find the forth '/' and strip from there. A bit hackish.
1533 return '/'.join(self.url.split('/')[:4]) + url
[email protected]99828122010-06-04 01:41:021534
[email protected]669600d2010-09-01 19:06:311535 def _Run(self, args, options, **kwargs):
1536 """Runs a commands that goes to stdout."""
[email protected]8469bf92010-09-03 19:03:151537 kwargs.setdefault('cwd', self.checkout_path)
[email protected]669600d2010-09-01 19:06:311538 gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args,
[email protected]77e4eca2010-09-21 13:23:071539 always=options.verbose, **kwargs)
[email protected]669600d2010-09-01 19:06:311540
[email protected]2702bcd2013-09-24 19:10:071541 def Svnversion(self):
1542 """Runs the lowest checked out revision in the current project."""
1543 info = scm.SVN.CaptureLocalInfo([], os.path.join(self.checkout_path, '.'))
1544 return info['Revision']
1545
[email protected]669600d2010-09-01 19:06:311546 def _RunAndGetFileList(self, args, options, file_list, cwd=None):
1547 """Runs a commands that goes to stdout and grabs the file listed."""
[email protected]8469bf92010-09-03 19:03:151548 cwd = cwd or self.checkout_path
[email protected]ce117f62011-01-17 20:04:251549 scm.SVN.RunAndGetFileList(
1550 options.verbose,
1551 args + ['--ignore-externals'],
1552 cwd=cwd,
[email protected]77e4eca2010-09-21 13:23:071553 file_list=file_list)
[email protected]669600d2010-09-01 19:06:311554
[email protected]6e29d572010-06-04 17:32:201555 @staticmethod
[email protected]8e0e9262010-08-17 19:20:271556 def _AddAdditionalUpdateFlags(command, options, revision):
[email protected]99828122010-06-04 01:41:021557 """Add additional flags to command depending on what options are set.
1558 command should be a list of strings that represents an svn command.
1559
1560 This method returns a new list to be used as a command."""
1561 new_command = command[:]
1562 if revision:
1563 new_command.extend(['--revision', str(revision).strip()])
[email protected]36ac2392011-10-12 16:36:111564 # We don't want interaction when jobs are used.
1565 if options.jobs > 1:
1566 new_command.append('--non-interactive')
[email protected]99828122010-06-04 01:41:021567 # --force was added to 'svn update' in svn 1.5.
[email protected]36ac2392011-10-12 16:36:111568 # --accept was added to 'svn update' in svn 1.6.
1569 if not scm.SVN.AssertVersion('1.5')[0]:
1570 return new_command
1571
1572 # It's annoying to have it block in the middle of a sync, just sensible
1573 # defaults.
1574 if options.force:
[email protected]99828122010-06-04 01:41:021575 new_command.append('--force')
[email protected]36ac2392011-10-12 16:36:111576 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1577 new_command.extend(('--accept', 'theirs-conflict'))
1578 elif options.manually_grab_svn_rev:
1579 new_command.append('--force')
1580 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1581 new_command.extend(('--accept', 'postpone'))
1582 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1583 new_command.extend(('--accept', 'postpone'))
[email protected]99828122010-06-04 01:41:021584 return new_command