blob: 40dccae0a0f80dcece07d01c907b56aa92503f11 [file] [log] [blame]
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +00001# Copyright (c) 2009 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
maruel@chromium.org5f3eee32009-09-17 00:34:30 +00004
maruel@chromium.orgd5800f12009-11-12 20:03:43 +00005"""Gclient-specific SCM-specific operations."""
maruel@chromium.org5f3eee32009-09-17 00:34:30 +00006
maruel@chromium.org754960e2009-09-21 12:31:05 +00007import logging
maruel@chromium.org5f3eee32009-09-17 00:34:30 +00008import os
maruel@chromium.orgee4071d2009-12-22 22:25:37 +00009import posixpath
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000010import re
11import subprocess
maruel@chromium.orgfd876172010-04-30 14:01:05 +000012import time
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000013
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +000014import scm
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000015import gclient_utils
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000016
17
maruel@chromium.orgee4071d2009-12-22 22:25:37 +000018class DiffFilterer(object):
19 """Simple class which tracks which file is being diffed and
20 replaces instances of its file name in the original and
msb@chromium.orgd6504212010-01-13 17:34:31 +000021 working copy lines of the svn/git diff output."""
maruel@chromium.orgee4071d2009-12-22 22:25:37 +000022 index_string = "Index: "
23 original_prefix = "--- "
24 working_prefix = "+++ "
25
26 def __init__(self, relpath):
27 # Note that we always use '/' as the path separator to be
28 # consistent with svn's cygwin-style output on Windows
29 self._relpath = relpath.replace("\\", "/")
30 self._current_file = ""
31 self._replacement_file = ""
32
33 def SetCurrentFile(self, file):
34 self._current_file = file
35 # Note that we always use '/' as the path separator to be
36 # consistent with svn's cygwin-style output on Windows
37 self._replacement_file = posixpath.join(self._relpath, file)
38
39 def ReplaceAndPrint(self, line):
40 print(line.replace(self._current_file, self._replacement_file))
41
42 def Filter(self, line):
43 if (line.startswith(self.index_string)):
44 self.SetCurrentFile(line[len(self.index_string):])
45 self.ReplaceAndPrint(line)
46 else:
47 if (line.startswith(self.original_prefix) or
48 line.startswith(self.working_prefix)):
49 self.ReplaceAndPrint(line)
50 else:
51 print line
52
53
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000054### SCM abstraction layer
55
msb@chromium.orgcb5442b2009-09-22 16:51:24 +000056# Factory Method for SCM wrapper creation
57
58def CreateSCM(url=None, root_dir=None, relpath=None, scm_name='svn'):
msb@chromium.orgcb5442b2009-09-22 16:51:24 +000059 scm_map = {
60 'svn' : SVNWrapper,
msb@chromium.orge28e4982009-09-25 20:51:45 +000061 'git' : GitWrapper,
msb@chromium.orgcb5442b2009-09-22 16:51:24 +000062 }
msb@chromium.orge28e4982009-09-25 20:51:45 +000063
msb@chromium.org1b8779a2009-11-19 18:11:39 +000064 orig_url = url
65
66 if url:
67 url, _ = gclient_utils.SplitUrlRevision(url)
68 if url.startswith('git:') or url.startswith('ssh:') or url.endswith('.git'):
69 scm_name = 'git'
msb@chromium.orge28e4982009-09-25 20:51:45 +000070
msb@chromium.orgcb5442b2009-09-22 16:51:24 +000071 if not scm_name in scm_map:
72 raise gclient_utils.Error('Unsupported scm %s' % scm_name)
msb@chromium.org1b8779a2009-11-19 18:11:39 +000073 return scm_map[scm_name](orig_url, root_dir, relpath, scm_name)
msb@chromium.orgcb5442b2009-09-22 16:51:24 +000074
75
76# SCMWrapper base class
77
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000078class SCMWrapper(object):
79 """Add necessary glue between all the supported SCM.
80
msb@chromium.orgd6504212010-01-13 17:34:31 +000081 This is the abstraction layer to bind to different SCM.
82 """
maruel@chromium.org5e73b0c2009-09-18 19:47:48 +000083 def __init__(self, url=None, root_dir=None, relpath=None,
84 scm_name='svn'):
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000085 self.scm_name = scm_name
86 self.url = url
maruel@chromium.org5e73b0c2009-09-18 19:47:48 +000087 self._root_dir = root_dir
88 if self._root_dir:
89 self._root_dir = self._root_dir.replace('/', os.sep)
90 self.relpath = relpath
91 if self.relpath:
92 self.relpath = self.relpath.replace('/', os.sep)
msb@chromium.orge28e4982009-09-25 20:51:45 +000093 if self.relpath and self._root_dir:
94 self.checkout_path = os.path.join(self._root_dir, self.relpath)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000095
maruel@chromium.org5f3eee32009-09-17 00:34:30 +000096 def RunCommand(self, command, options, args, file_list=None):
97 # file_list will have all files that are modified appended to it.
maruel@chromium.orgde754ac2009-09-17 18:04:50 +000098 if file_list is None:
99 file_list = []
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000100
tony@chromium.org4b5b1772010-04-08 01:52:56 +0000101 commands = ['cleanup', 'export', 'update', 'updatesingle', 'revert',
102 'revinfo', 'status', 'diff', 'pack', 'runhooks']
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000103
104 if not command in commands:
105 raise gclient_utils.Error('Unknown command %s' % command)
106
msb@chromium.orgcb5442b2009-09-22 16:51:24 +0000107 if not command in dir(self):
maruel@chromium.orgee4071d2009-12-22 22:25:37 +0000108 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % (
msb@chromium.orgcb5442b2009-09-22 16:51:24 +0000109 command, self.scm_name))
110
111 return getattr(self, command)(options, args, file_list)
112
113
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000114class GitWrapper(SCMWrapper):
msb@chromium.orge28e4982009-09-25 20:51:45 +0000115 """Wrapper for Git"""
116
117 def cleanup(self, options, args, file_list):
msb@chromium.orgd8a63782010-01-25 17:47:05 +0000118 """'Cleanup' the repo.
119
120 There's no real git equivalent for the svn cleanup command, do a no-op.
121 """
msb@chromium.org3904caa2010-01-25 17:37:46 +0000122 __pychecker__ = 'unusednames=options,args,file_list'
msb@chromium.orge28e4982009-09-25 20:51:45 +0000123
124 def diff(self, options, args, file_list):
msb@chromium.org3904caa2010-01-25 17:37:46 +0000125 __pychecker__ = 'unusednames=options,args,file_list'
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +0000126 merge_base = self._Run(['merge-base', 'HEAD', 'origin'])
127 self._Run(['diff', merge_base], redirect_stdout=False)
msb@chromium.orge28e4982009-09-25 20:51:45 +0000128
129 def export(self, options, args, file_list):
msb@chromium.orgd6504212010-01-13 17:34:31 +0000130 """Export a clean directory tree into the given path.
131
132 Exports into the specified directory, creating the path if it does
133 already exist.
134 """
msb@chromium.org3904caa2010-01-25 17:37:46 +0000135 __pychecker__ = 'unusednames=options,file_list'
msb@chromium.orge28e4982009-09-25 20:51:45 +0000136 assert len(args) == 1
137 export_path = os.path.abspath(os.path.join(args[0], self.relpath))
138 if not os.path.exists(export_path):
139 os.makedirs(export_path)
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +0000140 self._Run(['checkout-index', '-a', '--prefix=%s/' % export_path],
141 redirect_stdout=False)
msb@chromium.orge28e4982009-09-25 20:51:45 +0000142
maruel@chromium.orgee4071d2009-12-22 22:25:37 +0000143 def pack(self, options, args, file_list):
144 """Generates a patch file which can be applied to the root of the
msb@chromium.orgd6504212010-01-13 17:34:31 +0000145 repository.
146
147 The patch file is generated from a diff of the merge base of HEAD and
148 its upstream branch.
149 """
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000150 __pychecker__ = 'unusednames=options,args,file_list'
maruel@chromium.orgee4071d2009-12-22 22:25:37 +0000151 path = os.path.join(self._root_dir, self.relpath)
152 merge_base = self._Run(['merge-base', 'HEAD', 'origin'])
153 command = ['diff', merge_base]
154 filterer = DiffFilterer(self.relpath)
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000155 scm.GIT.RunAndFilterOutput(command, path, False, False, filterer.Filter)
maruel@chromium.orgee4071d2009-12-22 22:25:37 +0000156
msb@chromium.orge28e4982009-09-25 20:51:45 +0000157 def update(self, options, args, file_list):
158 """Runs git to update or transparently checkout the working copy.
159
160 All updated files will be appended to file_list.
161
162 Raises:
163 Error: if can't get URL for relative path.
164 """
165
166 if args:
167 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
168
nasser@codeaurora.orgece406f2010-02-23 17:29:15 +0000169 self._CheckMinVersion("1.6.6")
msb@chromium.org923a0372009-12-11 20:42:43 +0000170
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000171 default_rev = "refs/heads/master"
nasser@codeaurora.org7080e942010-03-15 15:06:16 +0000172 url, deps_revision = gclient_utils.SplitUrlRevision(self.url)
msb@chromium.orgac915bb2009-11-13 17:03:01 +0000173 rev_str = ""
nasser@codeaurora.org7080e942010-03-15 15:06:16 +0000174 revision = deps_revision
msb@chromium.orge28e4982009-09-25 20:51:45 +0000175 if options.revision:
msb@chromium.orgac915bb2009-11-13 17:03:01 +0000176 # Override the revision number.
177 revision = str(options.revision)
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000178 if not revision:
179 revision = default_rev
msb@chromium.orge28e4982009-09-25 20:51:45 +0000180
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000181 rev_str = ' at %s' % revision
182 files = []
183
184 printed_path = False
185 verbose = []
msb@chromium.orgb1a22bf2009-11-07 02:33:50 +0000186 if options.verbose:
msb@chromium.orgb1a22bf2009-11-07 02:33:50 +0000187 print("\n_____ %s%s" % (self.relpath, rev_str))
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000188 verbose = ['--verbose']
189 printed_path = True
190
191 if revision.startswith('refs/heads/'):
192 rev_type = "branch"
193 elif revision.startswith('origin/'):
194 # For compatability with old naming, translate 'origin' to 'refs/heads'
195 revision = revision.replace('origin/', 'refs/heads/')
196 rev_type = "branch"
197 else:
198 # hash is also a tag, only make a distinction at checkout
199 rev_type = "hash"
200
msb@chromium.orge28e4982009-09-25 20:51:45 +0000201 if not os.path.exists(self.checkout_path):
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000202 self._Clone(rev_type, revision, url, options.verbose)
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +0000203 files = self._Run(['ls-files']).split()
msb@chromium.orge28e4982009-09-25 20:51:45 +0000204 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000205 if not verbose:
206 # Make the output a little prettier. It's nice to have some whitespace
207 # between projects when cloning.
208 print ""
msb@chromium.orge28e4982009-09-25 20:51:45 +0000209 return
210
msb@chromium.orge4af1ab2010-01-13 21:26:09 +0000211 if not os.path.exists(os.path.join(self.checkout_path, '.git')):
212 raise gclient_utils.Error('\n____ %s%s\n'
213 '\tPath is not a git repo. No .git dir.\n'
214 '\tTo resolve:\n'
215 '\t\trm -rf %s\n'
216 '\tAnd run gclient sync again\n'
217 % (self.relpath, rev_str, self.relpath))
218
msb@chromium.org5bde4852009-12-14 16:47:12 +0000219 cur_branch = self._GetCurrentBranch()
220
221 # Check if we are in a rebase conflict
222 if cur_branch is None:
223 raise gclient_utils.Error('\n____ %s%s\n'
224 '\tAlready in a conflict, i.e. (no branch).\n'
225 '\tFix the conflict and run gclient again.\n'
226 '\tOr to abort run:\n\t\tgit-rebase --abort\n'
227 '\tSee man git-rebase for details.\n'
228 % (self.relpath, rev_str))
229
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000230 # Cases:
231 # 1) current branch based on a hash (could be git-svn)
232 # - try to rebase onto the new upstream (hash or branch)
233 # 2) current branch based on a remote branch with local committed changes,
234 # but the DEPS file switched to point to a hash
235 # - rebase those changes on top of the hash
236 # 3) current branch based on a remote with or without changes, no switch
237 # - see if we can FF, if not, prompt the user for rebase, merge, or stop
238 # 4) current branch based on a remote, switches to a new remote
239 # - exit
240
maruel@chromium.org81e012c2010-04-29 16:07:24 +0000241 # GetUpstreamBranch returns something like 'refs/remotes/origin/master' for
242 # a tracking branch
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000243 # or 'master' if not a tracking branch (it's based on a specific rev/hash)
244 # or it returns None if it couldn't find an upstream
maruel@chromium.org81e012c2010-04-29 16:07:24 +0000245 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path)
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000246 if not upstream_branch or not upstream_branch.startswith('refs/remotes'):
247 current_type = "hash"
248 logging.debug("Current branch is based off a specific rev and is not "
249 "tracking an upstream.")
250 elif upstream_branch.startswith('refs/remotes'):
251 current_type = "branch"
252 else:
253 raise gclient_utils.Error('Invalid Upstream')
254
maruel@chromium.org0b1c2462010-03-02 00:48:14 +0000255 # Update the remotes first so we have all the refs.
maruel@chromium.orgfd876172010-04-30 14:01:05 +0000256 for _ in range(10):
maruel@chromium.org0b1c2462010-03-02 00:48:14 +0000257 try:
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000258 remote_output, remote_err = scm.GIT.Capture(
maruel@chromium.org0b1c2462010-03-02 00:48:14 +0000259 ['remote'] + verbose + ['update'],
260 self.checkout_path,
261 print_error=False)
262 break
maruel@chromium.orgfd876172010-04-30 14:01:05 +0000263 except gclient_utils.CheckCallError:
maruel@chromium.org0b1c2462010-03-02 00:48:14 +0000264 # Hackish but at that point, git is known to work so just checking for
265 # 502 in stderr should be fine.
266 if '502' in e.stderr:
267 print str(e)
maruel@chromium.orgfd876172010-04-30 14:01:05 +0000268 print "Sleeping 15 seconds and retrying..."
269 time.sleep(15)
maruel@chromium.org0b1c2462010-03-02 00:48:14 +0000270 continue
maruel@chromium.orgfd876172010-04-30 14:01:05 +0000271 raise
maruel@chromium.org0b1c2462010-03-02 00:48:14 +0000272
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000273 if verbose:
274 print remote_output.strip()
275 # git remote update prints to stderr when used with --verbose
276 print remote_err.strip()
277
278 # This is a big hammer, debatable if it should even be here...
davemoore@chromium.org793796d2010-02-19 17:27:41 +0000279 if options.force or options.reset:
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000280 self._Run(['reset', '--hard', 'HEAD'], redirect_stdout=False)
281
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000282 if current_type == 'hash':
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000283 # case 1
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000284 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None:
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000285 # Our git-svn branch (upstream_branch) is our upstream
286 self._AttemptRebase(upstream_branch, files, verbose=options.verbose,
287 newbase=revision, printed_path=printed_path)
288 printed_path = True
289 else:
290 # Can't find a merge-base since we don't know our upstream. That makes
291 # this command VERY likely to produce a rebase failure. For now we
292 # assume origin is our upstream since that's what the old behavior was.
nasser@codeaurora.org3b29de12010-03-08 18:34:28 +0000293 upstream_branch = 'origin'
nasser@codeaurora.org7080e942010-03-15 15:06:16 +0000294 if options.revision or deps_revision:
nasser@codeaurora.org3b29de12010-03-08 18:34:28 +0000295 upstream_branch = revision
296 self._AttemptRebase(upstream_branch, files=files,
297 verbose=options.verbose, printed_path=printed_path)
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000298 printed_path = True
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000299 elif rev_type == 'hash':
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000300 # case 2
301 self._AttemptRebase(upstream_branch, files, verbose=options.verbose,
302 newbase=revision, printed_path=printed_path)
303 printed_path = True
304 elif revision.replace('heads', 'remotes/origin') != upstream_branch:
305 # case 4
306 new_base = revision.replace('heads', 'remotes/origin')
307 if not printed_path:
308 print("\n_____ %s%s" % (self.relpath, rev_str))
309 switch_error = ("Switching upstream branch from %s to %s\n"
310 % (upstream_branch, new_base) +
311 "Please merge or rebase manually:\n" +
312 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) +
313 "OR git checkout -b <some new branch> %s" % new_base)
314 raise gclient_utils.Error(switch_error)
315 else:
316 # case 3 - the default case
317 files = self._Run(['diff', upstream_branch, '--name-only']).split()
318 if verbose:
319 print "Trying fast-forward merge to branch : %s" % upstream_branch
320 try:
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000321 merge_output, merge_err = scm.GIT.Capture(['merge', '--ff-only',
322 upstream_branch],
323 self.checkout_path,
324 print_error=False)
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000325 except gclient_utils.CheckCallError, e:
326 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr):
327 if not printed_path:
328 print("\n_____ %s%s" % (self.relpath, rev_str))
329 printed_path = True
330 while True:
331 try:
332 action = str(raw_input("Cannot fast-forward merge, attempt to "
333 "rebase? (y)es / (q)uit / (s)kip : "))
334 except ValueError:
335 gclient_utils.Error('Invalid Character')
336 continue
337 if re.match(r'yes|y', action, re.I):
338 self._AttemptRebase(upstream_branch, files,
339 verbose=options.verbose,
340 printed_path=printed_path)
341 printed_path = True
342 break
343 elif re.match(r'quit|q', action, re.I):
344 raise gclient_utils.Error("Can't fast-forward, please merge or "
345 "rebase manually.\n"
346 "cd %s && git " % self.checkout_path
347 + "rebase %s" % upstream_branch)
348 elif re.match(r'skip|s', action, re.I):
349 print "Skipping %s" % self.relpath
350 return
351 else:
352 print "Input not recognized"
353 elif re.match("error: Your local changes to '.*' would be "
354 "overwritten by merge. Aborting.\nPlease, commit your "
355 "changes or stash them before you can merge.\n",
356 e.stderr):
357 if not printed_path:
358 print("\n_____ %s%s" % (self.relpath, rev_str))
359 printed_path = True
360 raise gclient_utils.Error(e.stderr)
361 else:
362 # Some other problem happened with the merge
363 logging.error("Error during fast-forward merge in %s!" % self.relpath)
364 print e.stderr
365 raise
366 else:
367 # Fast-forward merge was successful
368 if not re.match('Already up-to-date.', merge_output) or verbose:
369 if not printed_path:
370 print("\n_____ %s%s" % (self.relpath, rev_str))
371 printed_path = True
372 print merge_output.strip()
373 if merge_err:
374 print "Merge produced error output:\n%s" % merge_err.strip()
375 if not verbose:
376 # Make the output a little prettier. It's nice to have some
377 # whitespace between projects when syncing.
378 print ""
379
380 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
msb@chromium.org5bde4852009-12-14 16:47:12 +0000381
382 # If the rebase generated a conflict, abort and ask user to fix
383 if self._GetCurrentBranch() is None:
384 raise gclient_utils.Error('\n____ %s%s\n'
385 '\nConflict while rebasing this branch.\n'
386 'Fix the conflict and run gclient again.\n'
387 'See man git-rebase for details.\n'
388 % (self.relpath, rev_str))
389
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000390 if verbose:
391 print "Checked out revision %s" % self.revinfo(options, (), None)
msb@chromium.orge28e4982009-09-25 20:51:45 +0000392
393 def revert(self, options, args, file_list):
394 """Reverts local modifications.
395
396 All reverted files will be appended to file_list.
397 """
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000398 __pychecker__ = 'unusednames=args'
msb@chromium.org260c6532009-10-28 03:22:35 +0000399 path = os.path.join(self._root_dir, self.relpath)
400 if not os.path.isdir(path):
401 # revert won't work if the directory doesn't exist. It needs to
402 # checkout instead.
403 print("\n_____ %s is missing, synching instead" % self.relpath)
404 # Don't reuse the args.
405 return self.update(options, [], file_list)
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +0000406 merge_base = self._Run(['merge-base', 'HEAD', 'origin'])
407 files = self._Run(['diff', merge_base, '--name-only']).split()
408 self._Run(['reset', '--hard', merge_base], redirect_stdout=False)
msb@chromium.orge28e4982009-09-25 20:51:45 +0000409 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
410
msb@chromium.org0f282062009-11-06 20:14:02 +0000411 def revinfo(self, options, args, file_list):
412 """Display revision"""
msb@chromium.org3904caa2010-01-25 17:37:46 +0000413 __pychecker__ = 'unusednames=options,args,file_list'
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +0000414 return self._Run(['rev-parse', 'HEAD'])
msb@chromium.org0f282062009-11-06 20:14:02 +0000415
msb@chromium.orge28e4982009-09-25 20:51:45 +0000416 def runhooks(self, options, args, file_list):
417 self.status(options, args, file_list)
418
419 def status(self, options, args, file_list):
420 """Display status information."""
msb@chromium.org3904caa2010-01-25 17:37:46 +0000421 __pychecker__ = 'unusednames=options,args'
msb@chromium.orge28e4982009-09-25 20:51:45 +0000422 if not os.path.isdir(self.checkout_path):
423 print('\n________ couldn\'t run status in %s:\nThe directory '
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000424 'does not exist.' % self.checkout_path)
msb@chromium.orge28e4982009-09-25 20:51:45 +0000425 else:
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +0000426 merge_base = self._Run(['merge-base', 'HEAD', 'origin'])
427 self._Run(['diff', '--name-status', merge_base], redirect_stdout=False)
428 files = self._Run(['diff', '--name-only', merge_base]).split()
msb@chromium.orge28e4982009-09-25 20:51:45 +0000429 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
430
msb@chromium.orge6f78352010-01-13 17:05:33 +0000431 def FullUrlForRelativeUrl(self, url):
432 # Strip from last '/'
433 # Equivalent to unix basename
434 base_url = self.url
435 return base_url[:base_url.rfind('/')] + url
436
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000437 def _Clone(self, rev_type, revision, url, verbose=False):
438 """Clone a git repository from the given URL.
439
440 Once we've cloned the repo, we checkout a working branch based off the
441 specified revision."""
442 if not verbose:
443 # git clone doesn't seem to insert a newline properly before printing
444 # to stdout
445 print ""
446
447 clone_cmd = ['clone']
448 if verbose:
449 clone_cmd.append('--verbose')
450 clone_cmd.extend([url, self.checkout_path])
451
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000452 for _ in range(3):
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000453 try:
454 self._Run(clone_cmd, cwd=self._root_dir, redirect_stdout=False)
455 break
456 except gclient_utils.Error, e:
457 # TODO(maruel): Hackish, should be fixed by moving _Run() to
458 # CheckCall().
459 # Too bad we don't have access to the actual output.
460 # We should check for "transfer closed with NNN bytes remaining to
461 # read". In the meantime, just make sure .git exists.
462 if (e.args[0] == 'git command clone returned 128' and
463 os.path.exists(os.path.join(self.checkout_path, '.git'))):
464 print str(e)
465 print "Retrying..."
466 continue
467 raise e
468
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000469 if rev_type == "branch":
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000470 short_rev = revision.replace('refs/heads/', '')
471 new_branch = revision.replace('heads', 'remotes/origin')
472 elif revision.startswith('refs/tags/'):
473 short_rev = revision.replace('refs/tags/', '')
474 new_branch = revision
475 else:
476 # revision is a specific sha1 hash
477 short_rev = revision
478 new_branch = revision
479
480 cur_branch = self._GetCurrentBranch()
481 if cur_branch != short_rev:
482 self._Run(['checkout', '-b', short_rev, new_branch],
483 redirect_stdout=False)
484
485 def _AttemptRebase(self, upstream, files, verbose=False, newbase=None,
486 branch=None, printed_path=False):
487 """Attempt to rebase onto either upstream or, if specified, newbase."""
488 files.extend(self._Run(['diff', upstream, '--name-only']).split())
489 revision = upstream
490 if newbase:
491 revision = newbase
492 if not printed_path:
493 print "\n_____ %s : Attempting rebase onto %s..." % (self.relpath,
494 revision)
495 printed_path = True
496 else:
497 print "Attempting rebase onto %s..." % revision
498
499 # Build the rebase command here using the args
500 # git rebase [options] [--onto <newbase>] <upstream> [<branch>]
501 rebase_cmd = ['rebase']
502 if verbose:
503 rebase_cmd.append('--verbose')
504 if newbase:
505 rebase_cmd.extend(['--onto', newbase])
506 rebase_cmd.append(upstream)
507 if branch:
508 rebase_cmd.append(branch)
509
510 try:
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000511 rebase_output, rebase_err = scm.GIT.Capture(rebase_cmd,
512 self.checkout_path,
513 print_error=False)
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000514 except gclient_utils.CheckCallError, e:
515 if re.match(r'cannot rebase: you have unstaged changes', e.stderr) or \
516 re.match(r'cannot rebase: your index contains uncommitted changes',
517 e.stderr):
518 while True:
519 rebase_action = str(raw_input("Cannot rebase because of unstaged "
520 "changes.\n'git reset --hard HEAD' ?\n"
521 "WARNING: destroys any uncommitted "
522 "work in your current branch!"
523 " (y)es / (q)uit / (s)how : "))
524 if re.match(r'yes|y', rebase_action, re.I):
525 self._Run(['reset', '--hard', 'HEAD'], redirect_stdout=False)
526 # Should this be recursive?
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000527 rebase_output, rebase_err = scm.GIT.Capture(rebase_cmd,
528 self.checkout_path)
nasser@codeaurora.orgd90ba3f2010-02-23 14:42:57 +0000529 break
530 elif re.match(r'quit|q', rebase_action, re.I):
531 raise gclient_utils.Error("Please merge or rebase manually\n"
532 "cd %s && git " % self.checkout_path
533 + "%s" % ' '.join(rebase_cmd))
534 elif re.match(r'show|s', rebase_action, re.I):
535 print "\n%s" % e.stderr.strip()
536 continue
537 else:
538 gclient_utils.Error("Input not recognized")
539 continue
540 elif re.search(r'^CONFLICT', e.stdout, re.M):
541 raise gclient_utils.Error("Conflict while rebasing this branch.\n"
542 "Fix the conflict and run gclient again.\n"
543 "See 'man git-rebase' for details.\n")
544 else:
545 print e.stdout.strip()
546 print "Rebase produced error output:\n%s" % e.stderr.strip()
547 raise gclient_utils.Error("Unrecognized error, please merge or rebase "
548 "manually.\ncd %s && git " %
549 self.checkout_path
550 + "%s" % ' '.join(rebase_cmd))
551
552 print rebase_output.strip()
553 if rebase_err:
554 print "Rebase produced error output:\n%s" % rebase_err.strip()
555 if not verbose:
556 # Make the output a little prettier. It's nice to have some
557 # whitespace between projects when syncing.
558 print ""
559
msb@chromium.org923a0372009-12-11 20:42:43 +0000560 def _CheckMinVersion(self, min_version):
maruel@chromium.orgd0f854a2010-03-11 19:35:53 +0000561 (ok, current_version) = scm.GIT.AssertVersion(min_version)
562 if not ok:
563 raise gclient_utils.Error('git version %s < minimum required %s' %
564 (current_version, min_version))
msb@chromium.org923a0372009-12-11 20:42:43 +0000565
msb@chromium.org5bde4852009-12-14 16:47:12 +0000566 def _GetCurrentBranch(self):
567 # Returns name of current branch
568 # Returns None if inside a (no branch)
569 tokens = self._Run(['branch']).split()
570 branch = tokens[tokens.index('*') + 1]
571 if branch == '(no':
572 return None
573 return branch
574
maruel@chromium.org2de10252010-02-08 01:10:39 +0000575 def _Run(self, args, cwd=None, redirect_stdout=True):
576 # TODO(maruel): Merge with Capture or better gclient_utils.CheckCall().
maruel@chromium.orgffe96f02009-12-09 18:39:15 +0000577 if cwd is None:
578 cwd = self.checkout_path
maruel@chromium.org2de10252010-02-08 01:10:39 +0000579 stdout = None
msb@chromium.orge8e60e52009-11-02 21:50:56 +0000580 if redirect_stdout:
maruel@chromium.org2de10252010-02-08 01:10:39 +0000581 stdout = subprocess.PIPE
msb@chromium.orge28e4982009-09-25 20:51:45 +0000582 if cwd == None:
583 cwd = self.checkout_path
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000584 cmd = [scm.GIT.COMMAND]
msb@chromium.orge28e4982009-09-25 20:51:45 +0000585 cmd.extend(args)
maruel@chromium.orgf3909bf2010-01-08 01:14:51 +0000586 logging.debug(cmd)
587 try:
588 sp = subprocess.Popen(cmd, cwd=cwd, stdout=stdout)
589 output = sp.communicate()[0]
590 except OSError:
591 raise gclient_utils.Error("git command '%s' failed to run." %
592 ' '.join(cmd) + "\nCheck that you have git installed.")
maruel@chromium.org2de10252010-02-08 01:10:39 +0000593 if sp.returncode:
msb@chromium.orge28e4982009-09-25 20:51:45 +0000594 raise gclient_utils.Error('git command %s returned %d' %
595 (args[0], sp.returncode))
maruel@chromium.org5aeb7dd2009-11-17 18:09:01 +0000596 if output is not None:
msb@chromium.orge8e60e52009-11-02 21:50:56 +0000597 return output.strip()
msb@chromium.orge28e4982009-09-25 20:51:45 +0000598
599
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000600class SVNWrapper(SCMWrapper):
msb@chromium.orgcb5442b2009-09-22 16:51:24 +0000601 """ Wrapper for SVN """
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000602
603 def cleanup(self, options, args, file_list):
604 """Cleanup working copy."""
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000605 __pychecker__ = 'unusednames=file_list,options'
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000606 command = ['cleanup']
607 command.extend(args)
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000608 scm.SVN.Run(command, os.path.join(self._root_dir, self.relpath))
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000609
610 def diff(self, options, args, file_list):
611 # NOTE: This function does not currently modify file_list.
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000612 __pychecker__ = 'unusednames=file_list,options'
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000613 command = ['diff']
614 command.extend(args)
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000615 scm.SVN.Run(command, os.path.join(self._root_dir, self.relpath))
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000616
617 def export(self, options, args, file_list):
msb@chromium.orgd6504212010-01-13 17:34:31 +0000618 """Export a clean directory tree into the given path."""
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000619 __pychecker__ = 'unusednames=file_list,options'
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000620 assert len(args) == 1
621 export_path = os.path.abspath(os.path.join(args[0], self.relpath))
622 try:
623 os.makedirs(export_path)
624 except OSError:
625 pass
626 assert os.path.exists(export_path)
627 command = ['export', '--force', '.']
628 command.append(export_path)
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000629 scm.SVN.Run(command, os.path.join(self._root_dir, self.relpath))
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000630
maruel@chromium.orgee4071d2009-12-22 22:25:37 +0000631 def pack(self, options, args, file_list):
632 """Generates a patch file which can be applied to the root of the
633 repository."""
634 __pychecker__ = 'unusednames=file_list,options'
635 path = os.path.join(self._root_dir, self.relpath)
636 command = ['diff']
637 command.extend(args)
638
639 filterer = DiffFilterer(self.relpath)
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000640 scm.SVN.RunAndFilterOutput(command, path, False, False, filterer.Filter)
maruel@chromium.orgee4071d2009-12-22 22:25:37 +0000641
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000642 def update(self, options, args, file_list):
msb@chromium.orgd6504212010-01-13 17:34:31 +0000643 """Runs svn to update or transparently checkout the working copy.
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000644
645 All updated files will be appended to file_list.
646
647 Raises:
648 Error: if can't get URL for relative path.
649 """
650 # Only update if git is not controlling the directory.
651 checkout_path = os.path.join(self._root_dir, self.relpath)
652 git_path = os.path.join(self._root_dir, self.relpath, '.git')
653 if os.path.exists(git_path):
654 print("________ found .git directory; skipping %s" % self.relpath)
655 return
656
657 if args:
658 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
659
msb@chromium.orgac915bb2009-11-13 17:03:01 +0000660 url, revision = gclient_utils.SplitUrlRevision(self.url)
661 base_url = url
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000662 forced_revision = False
msb@chromium.orgac915bb2009-11-13 17:03:01 +0000663 rev_str = ""
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000664 if options.revision:
665 # Override the revision number.
msb@chromium.orgac915bb2009-11-13 17:03:01 +0000666 revision = str(options.revision)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000667 if revision:
msb@chromium.orgac915bb2009-11-13 17:03:01 +0000668 forced_revision = True
669 url = '%s@%s' % (url, revision)
msb@chromium.org770ff9e2009-09-23 17:18:18 +0000670 rev_str = ' at %s' % revision
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000671
672 if not os.path.exists(checkout_path):
673 # We need to checkout.
674 command = ['checkout', url, checkout_path]
675 if revision:
676 command.extend(['--revision', str(revision)])
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000677 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000678 return
679
680 # Get the existing scm url and the revision number of the current checkout.
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000681 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.')
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000682 if not from_info:
683 raise gclient_utils.Error("Can't update/checkout %r if an unversioned "
684 "directory is present. Delete the directory "
685 "and try again." %
686 checkout_path)
687
maruel@chromium.org7753d242009-10-07 17:40:24 +0000688 if options.manually_grab_svn_rev:
689 # Retrieve the current HEAD version because svn is slow at null updates.
690 if not revision:
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000691 from_info_live = scm.SVN.CaptureInfo(from_info['URL'], '.')
maruel@chromium.org7753d242009-10-07 17:40:24 +0000692 revision = str(from_info_live['Revision'])
693 rev_str = ' at %s' % revision
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000694
msb@chromium.orgac915bb2009-11-13 17:03:01 +0000695 if from_info['URL'] != base_url:
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000696 to_info = scm.SVN.CaptureInfo(url, '.')
maruel@chromium.orge2ce0c72009-09-23 16:14:18 +0000697 if not to_info.get('Repository Root') or not to_info.get('UUID'):
698 # The url is invalid or the server is not accessible, it's safer to bail
699 # out right now.
700 raise gclient_utils.Error('This url is unreachable: %s' % url)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000701 can_switch = ((from_info['Repository Root'] != to_info['Repository Root'])
702 and (from_info['UUID'] == to_info['UUID']))
703 if can_switch:
704 print("\n_____ relocating %s to a new checkout" % self.relpath)
705 # We have different roots, so check if we can switch --relocate.
706 # Subversion only permits this if the repository UUIDs match.
707 # Perform the switch --relocate, then rewrite the from_url
708 # to reflect where we "are now." (This is the same way that
709 # Subversion itself handles the metadata when switch --relocate
710 # is used.) This makes the checks below for whether we
711 # can update to a revision or have to switch to a different
712 # branch work as expected.
713 # TODO(maruel): TEST ME !
714 command = ["switch", "--relocate",
715 from_info['Repository Root'],
716 to_info['Repository Root'],
717 self.relpath]
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000718 scm.SVN.Run(command, self._root_dir)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000719 from_info['URL'] = from_info['URL'].replace(
720 from_info['Repository Root'],
721 to_info['Repository Root'])
722 else:
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000723 if scm.SVN.CaptureStatus(checkout_path):
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000724 raise gclient_utils.Error("Can't switch the checkout to %s; UUID "
725 "don't match and there is local changes "
726 "in %s. Delete the directory and "
727 "try again." % (url, checkout_path))
728 # Ok delete it.
729 print("\n_____ switching %s to a new checkout" % self.relpath)
bradnelson@google.com8f9c69f2009-09-17 00:48:28 +0000730 gclient_utils.RemoveDirectory(checkout_path)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000731 # We need to checkout.
732 command = ['checkout', url, checkout_path]
733 if revision:
734 command.extend(['--revision', str(revision)])
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000735 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000736 return
737
738
739 # If the provided url has a revision number that matches the revision
740 # number of the existing directory, then we don't need to bother updating.
maruel@chromium.org2e0c6852009-09-24 00:02:07 +0000741 if not options.force and str(from_info['Revision']) == revision:
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000742 if options.verbose or not forced_revision:
743 print("\n_____ %s%s" % (self.relpath, rev_str))
744 return
745
746 command = ["update", checkout_path]
747 if revision:
748 command.extend(['--revision', str(revision)])
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000749 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000750
tony@chromium.org4b5b1772010-04-08 01:52:56 +0000751 def updatesingle(self, options, args, file_list):
752 checkout_path = os.path.join(self._root_dir, self.relpath)
753 filename = args.pop()
tony@chromium.org57564662010-04-14 02:35:12 +0000754 if scm.SVN.AssertVersion("1.5")[0]:
755 if not os.path.exists(os.path.join(checkout_path, '.svn')):
756 # Create an empty checkout and then update the one file we want. Future
757 # operations will only apply to the one file we checked out.
758 command = ["checkout", "--depth", "empty", self.url, checkout_path]
759 scm.SVN.Run(command, self._root_dir)
760 if os.path.exists(os.path.join(checkout_path, filename)):
761 os.remove(os.path.join(checkout_path, filename))
762 command = ["update", filename]
763 scm.SVN.RunAndGetFileList(options, command, checkout_path, file_list)
764 # After the initial checkout, we can use update as if it were any other
765 # dep.
766 self.update(options, args, file_list)
767 else:
768 # If the installed version of SVN doesn't support --depth, fallback to
769 # just exporting the file. This has the downside that revision
770 # information is not stored next to the file, so we will have to
771 # re-export the file every time we sync.
772 if not os.path.exists(checkout_path):
773 os.makedirs(checkout_path)
774 command = ["export", os.path.join(self.url, filename),
775 os.path.join(checkout_path, filename)]
776 if options.revision:
777 command.extend(['--revision', str(options.revision)])
tony@chromium.org4b5b1772010-04-08 01:52:56 +0000778 scm.SVN.Run(command, self._root_dir)
tony@chromium.org4b5b1772010-04-08 01:52:56 +0000779
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000780 def revert(self, options, args, file_list):
781 """Reverts local modifications. Subversion specific.
782
783 All reverted files will be appended to file_list, even if Subversion
784 doesn't know about them.
785 """
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000786 __pychecker__ = 'unusednames=args'
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000787 path = os.path.join(self._root_dir, self.relpath)
788 if not os.path.isdir(path):
789 # svn revert won't work if the directory doesn't exist. It needs to
790 # checkout instead.
791 print("\n_____ %s is missing, synching instead" % self.relpath)
792 # Don't reuse the args.
793 return self.update(options, [], file_list)
794
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000795 for file_status in scm.SVN.CaptureStatus(path):
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000796 file_path = os.path.join(path, file_status[1])
797 if file_status[0][0] == 'X':
maruel@chromium.org754960e2009-09-21 12:31:05 +0000798 # Ignore externals.
maruel@chromium.orgaa3dd472009-09-21 19:02:48 +0000799 logging.info('Ignoring external %s' % file_path)
maruel@chromium.org754960e2009-09-21 12:31:05 +0000800 continue
801
maruel@chromium.orgaa3dd472009-09-21 19:02:48 +0000802 if logging.getLogger().isEnabledFor(logging.INFO):
803 logging.info('%s%s' % (file[0], file[1]))
804 else:
805 print(file_path)
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000806 if file_status[0].isspace():
maruel@chromium.orgaa3dd472009-09-21 19:02:48 +0000807 logging.error('No idea what is the status of %s.\n'
808 'You just found a bug in gclient, please ping '
809 'maruel@chromium.org ASAP!' % file_path)
810 # svn revert is really stupid. It fails on inconsistent line-endings,
811 # on switched directories, etc. So take no chance and delete everything!
812 try:
813 if not os.path.exists(file_path):
814 pass
maruel@chromium.orgd2e78ff2010-01-11 20:37:19 +0000815 elif os.path.isfile(file_path) or os.path.islink(file_path):
maruel@chromium.org754960e2009-09-21 12:31:05 +0000816 logging.info('os.remove(%s)' % file_path)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000817 os.remove(file_path)
maruel@chromium.orgaa3dd472009-09-21 19:02:48 +0000818 elif os.path.isdir(file_path):
maruel@chromium.org754960e2009-09-21 12:31:05 +0000819 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path)
bradnelson@google.com8f9c69f2009-09-17 00:48:28 +0000820 gclient_utils.RemoveDirectory(file_path)
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000821 else:
maruel@chromium.orgaa3dd472009-09-21 19:02:48 +0000822 logging.error('no idea what is %s.\nYou just found a bug in gclient'
823 ', please ping maruel@chromium.org ASAP!' % file_path)
824 except EnvironmentError:
825 logging.error('Failed to remove %s.' % file_path)
826
maruel@chromium.org810a50b2009-10-05 23:03:18 +0000827 try:
828 # svn revert is so broken we don't even use it. Using
829 # "svn up --revision BASE" achieve the same effect.
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000830 scm.SVN.RunAndGetFileList(options, ['update', '--revision', 'BASE'], path,
831 file_list)
maruel@chromium.org810a50b2009-10-05 23:03:18 +0000832 except OSError, e:
833 # Maybe the directory disapeared meanwhile. We don't want it to throw an
834 # exception.
835 logging.error('Failed to update:\n%s' % str(e))
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000836
msb@chromium.org0f282062009-11-06 20:14:02 +0000837 def revinfo(self, options, args, file_list):
838 """Display revision"""
maruel@chromium.orge3608df2009-11-10 20:22:57 +0000839 __pychecker__ = 'unusednames=args,file_list,options'
nasser@codeaurora.org5d63eb82010-03-24 23:22:09 +0000840 return scm.SVN.CaptureBaseRevision(self.checkout_path)
msb@chromium.org0f282062009-11-06 20:14:02 +0000841
msb@chromium.orgcb5442b2009-09-22 16:51:24 +0000842 def runhooks(self, options, args, file_list):
843 self.status(options, args, file_list)
844
maruel@chromium.org5f3eee32009-09-17 00:34:30 +0000845 def status(self, options, args, file_list):
846 """Display status information."""
847 path = os.path.join(self._root_dir, self.relpath)
848 command = ['status']
849 command.extend(args)
850 if not os.path.isdir(path):
851 # svn status won't work if the directory doesn't exist.
852 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory "
853 "does not exist."
854 % (' '.join(command), path))
855 # There's no file list to retrieve.
856 else:
maruel@chromium.org55e724e2010-03-11 19:36:49 +0000857 scm.SVN.RunAndGetFileList(options, command, path, file_list)
msb@chromium.orge6f78352010-01-13 17:05:33 +0000858
859 def FullUrlForRelativeUrl(self, url):
860 # Find the forth '/' and strip from there. A bit hackish.
861 return '/'.join(self.url.split('/')[:4]) + url