scherkus@chromium.org | 95f0f4e | 2010-05-22 00:55:26 +0000 | [diff] [blame] | 1 | # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
maruel@chromium.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 4 | |
maruel@chromium.org | d5800f1 | 2009-11-12 20:03:43 +0000 | [diff] [blame] | 5 | """Gclient-specific SCM-specific operations.""" |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 6 | |
maruel@chromium.org | 754960e | 2009-09-21 12:31:05 +0000 | [diff] [blame] | 7 | import logging |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 8 | import os |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 9 | import posixpath |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 10 | import re |
| 11 | import subprocess |
maruel@chromium.org | fd87617 | 2010-04-30 14:01:05 +0000 | [diff] [blame] | 12 | import time |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 13 | |
maruel@chromium.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 14 | import scm |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 15 | import gclient_utils |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 16 | |
| 17 | |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 18 | class 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.org | d650421 | 2010-01-13 17:34:31 +0000 | [diff] [blame] | 21 | working copy lines of the svn/git diff output.""" |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 22 | 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.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 54 | ### SCM abstraction layer |
| 55 | |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 56 | # Factory Method for SCM wrapper creation |
| 57 | |
| 58 | def CreateSCM(url=None, root_dir=None, relpath=None, scm_name='svn'): |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 59 | scm_map = { |
| 60 | 'svn' : SVNWrapper, |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 61 | 'git' : GitWrapper, |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 62 | } |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 63 | |
msb@chromium.org | 1b8779a | 2009-11-19 18:11:39 +0000 | [diff] [blame] | 64 | 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.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 70 | |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 71 | if not scm_name in scm_map: |
| 72 | raise gclient_utils.Error('Unsupported scm %s' % scm_name) |
msb@chromium.org | 1b8779a | 2009-11-19 18:11:39 +0000 | [diff] [blame] | 73 | return scm_map[scm_name](orig_url, root_dir, relpath, scm_name) |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 74 | |
| 75 | |
| 76 | # SCMWrapper base class |
| 77 | |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 78 | class SCMWrapper(object): |
| 79 | """Add necessary glue between all the supported SCM. |
| 80 | |
msb@chromium.org | d650421 | 2010-01-13 17:34:31 +0000 | [diff] [blame] | 81 | This is the abstraction layer to bind to different SCM. |
| 82 | """ |
maruel@chromium.org | 5e73b0c | 2009-09-18 19:47:48 +0000 | [diff] [blame] | 83 | def __init__(self, url=None, root_dir=None, relpath=None, |
| 84 | scm_name='svn'): |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 85 | self.scm_name = scm_name |
| 86 | self.url = url |
maruel@chromium.org | 5e73b0c | 2009-09-18 19:47:48 +0000 | [diff] [blame] | 87 | 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.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 93 | if self.relpath and self._root_dir: |
| 94 | self.checkout_path = os.path.join(self._root_dir, self.relpath) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 95 | |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 96 | def RunCommand(self, command, options, args, file_list=None): |
| 97 | # file_list will have all files that are modified appended to it. |
maruel@chromium.org | de754ac | 2009-09-17 18:04:50 +0000 | [diff] [blame] | 98 | if file_list is None: |
| 99 | file_list = [] |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 100 | |
tony@chromium.org | 4b5b177 | 2010-04-08 01:52:56 +0000 | [diff] [blame] | 101 | commands = ['cleanup', 'export', 'update', 'updatesingle', 'revert', |
| 102 | 'revinfo', 'status', 'diff', 'pack', 'runhooks'] |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 103 | |
| 104 | if not command in commands: |
| 105 | raise gclient_utils.Error('Unknown command %s' % command) |
| 106 | |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 107 | if not command in dir(self): |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 108 | raise gclient_utils.Error('Command %s not implemented in %s wrapper' % ( |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 109 | command, self.scm_name)) |
| 110 | |
| 111 | return getattr(self, command)(options, args, file_list) |
| 112 | |
| 113 | |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 114 | class GitWrapper(SCMWrapper): |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 115 | """Wrapper for Git""" |
| 116 | |
| 117 | def cleanup(self, options, args, file_list): |
msb@chromium.org | d8a6378 | 2010-01-25 17:47:05 +0000 | [diff] [blame] | 118 | """'Cleanup' the repo. |
| 119 | |
| 120 | There's no real git equivalent for the svn cleanup command, do a no-op. |
| 121 | """ |
msb@chromium.org | 3904caa | 2010-01-25 17:37:46 +0000 | [diff] [blame] | 122 | __pychecker__ = 'unusednames=options,args,file_list' |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 123 | |
| 124 | def diff(self, options, args, file_list): |
msb@chromium.org | 3904caa | 2010-01-25 17:37:46 +0000 | [diff] [blame] | 125 | __pychecker__ = 'unusednames=options,args,file_list' |
maruel@chromium.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 126 | merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
| 127 | self._Run(['diff', merge_base], redirect_stdout=False) |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 128 | |
| 129 | def export(self, options, args, file_list): |
msb@chromium.org | d650421 | 2010-01-13 17:34:31 +0000 | [diff] [blame] | 130 | """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.org | 3904caa | 2010-01-25 17:37:46 +0000 | [diff] [blame] | 135 | __pychecker__ = 'unusednames=options,file_list' |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 136 | 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.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 140 | self._Run(['checkout-index', '-a', '--prefix=%s/' % export_path], |
| 141 | redirect_stdout=False) |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 142 | |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 143 | def pack(self, options, args, file_list): |
| 144 | """Generates a patch file which can be applied to the root of the |
msb@chromium.org | d650421 | 2010-01-13 17:34:31 +0000 | [diff] [blame] | 145 | 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.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 150 | __pychecker__ = 'unusednames=options,args,file_list' |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 151 | 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.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 155 | scm.GIT.RunAndFilterOutput(command, path, False, False, filterer.Filter) |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 156 | |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 157 | 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.org | ece406f | 2010-02-23 17:29:15 +0000 | [diff] [blame] | 169 | self._CheckMinVersion("1.6.6") |
msb@chromium.org | 923a037 | 2009-12-11 20:42:43 +0000 | [diff] [blame] | 170 | |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 171 | default_rev = "refs/heads/master" |
nasser@codeaurora.org | 7080e94 | 2010-03-15 15:06:16 +0000 | [diff] [blame] | 172 | url, deps_revision = gclient_utils.SplitUrlRevision(self.url) |
msb@chromium.org | ac915bb | 2009-11-13 17:03:01 +0000 | [diff] [blame] | 173 | rev_str = "" |
nasser@codeaurora.org | 7080e94 | 2010-03-15 15:06:16 +0000 | [diff] [blame] | 174 | revision = deps_revision |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 175 | if options.revision: |
msb@chromium.org | ac915bb | 2009-11-13 17:03:01 +0000 | [diff] [blame] | 176 | # Override the revision number. |
| 177 | revision = str(options.revision) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 178 | if not revision: |
| 179 | revision = default_rev |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 180 | |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 181 | rev_str = ' at %s' % revision |
| 182 | files = [] |
| 183 | |
| 184 | printed_path = False |
| 185 | verbose = [] |
msb@chromium.org | b1a22bf | 2009-11-07 02:33:50 +0000 | [diff] [blame] | 186 | if options.verbose: |
msb@chromium.org | b1a22bf | 2009-11-07 02:33:50 +0000 | [diff] [blame] | 187 | print("\n_____ %s%s" % (self.relpath, rev_str)) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 188 | 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.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 201 | if not os.path.exists(self.checkout_path): |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 202 | self._Clone(revision, url, options.verbose) |
maruel@chromium.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 203 | files = self._Run(['ls-files']).split() |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 204 | file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 205 | 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.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 209 | return |
| 210 | |
msb@chromium.org | e4af1ab | 2010-01-13 21:26:09 +0000 | [diff] [blame] | 211 | 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.org | 5bde485 | 2009-12-14 16:47:12 +0000 | [diff] [blame] | 219 | cur_branch = self._GetCurrentBranch() |
| 220 | |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 221 | # Cases: |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 222 | # 0) HEAD is detached. Probably from our initial clone. |
| 223 | # - make sure HEAD is contained by a named ref, then update. |
| 224 | # Cases 1-4. HEAD is a branch. |
| 225 | # 1) current branch is not tracking a remote branch (could be git-svn) |
| 226 | # - try to rebase onto the new hash or branch |
| 227 | # 2) current branch is tracking a remote branch with local committed |
| 228 | # changes, but the DEPS file switched to point to a hash |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 229 | # - rebase those changes on top of the hash |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 230 | # 3) current branch is tracking a remote branch w/or w/out changes, |
| 231 | # no switch |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 232 | # - see if we can FF, if not, prompt the user for rebase, merge, or stop |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 233 | # 4) current branch is tracking a remote branch, switches to a different |
| 234 | # remote branch |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 235 | # - exit |
| 236 | |
maruel@chromium.org | 81e012c | 2010-04-29 16:07:24 +0000 | [diff] [blame] | 237 | # GetUpstreamBranch returns something like 'refs/remotes/origin/master' for |
| 238 | # a tracking branch |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 239 | # or 'master' if not a tracking branch (it's based on a specific rev/hash) |
| 240 | # or it returns None if it couldn't find an upstream |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 241 | if cur_branch is None: |
| 242 | upstream_branch = None |
| 243 | current_type = "detached" |
| 244 | logging.debug("Detached HEAD") |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 245 | else: |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 246 | upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path) |
| 247 | if not upstream_branch or not upstream_branch.startswith('refs/remotes'): |
| 248 | current_type = "hash" |
| 249 | logging.debug("Current branch is not tracking an upstream (remote)" |
| 250 | " branch.") |
| 251 | elif upstream_branch.startswith('refs/remotes'): |
| 252 | current_type = "branch" |
| 253 | else: |
| 254 | raise gclient_utils.Error('Invalid Upstream: %s' % upstream_branch) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 255 | |
maruel@chromium.org | 0b1c246 | 2010-03-02 00:48:14 +0000 | [diff] [blame] | 256 | # Update the remotes first so we have all the refs. |
maruel@chromium.org | fd87617 | 2010-04-30 14:01:05 +0000 | [diff] [blame] | 257 | for _ in range(10): |
maruel@chromium.org | 0b1c246 | 2010-03-02 00:48:14 +0000 | [diff] [blame] | 258 | try: |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 259 | remote_output, remote_err = scm.GIT.Capture( |
maruel@chromium.org | 0b1c246 | 2010-03-02 00:48:14 +0000 | [diff] [blame] | 260 | ['remote'] + verbose + ['update'], |
| 261 | self.checkout_path, |
| 262 | print_error=False) |
| 263 | break |
maruel@chromium.org | 982984e | 2010-05-11 20:57:49 +0000 | [diff] [blame] | 264 | except gclient_utils.CheckCallError, e: |
maruel@chromium.org | 0b1c246 | 2010-03-02 00:48:14 +0000 | [diff] [blame] | 265 | # Hackish but at that point, git is known to work so just checking for |
| 266 | # 502 in stderr should be fine. |
| 267 | if '502' in e.stderr: |
| 268 | print str(e) |
maruel@chromium.org | fd87617 | 2010-04-30 14:01:05 +0000 | [diff] [blame] | 269 | print "Sleeping 15 seconds and retrying..." |
| 270 | time.sleep(15) |
maruel@chromium.org | 0b1c246 | 2010-03-02 00:48:14 +0000 | [diff] [blame] | 271 | continue |
maruel@chromium.org | fd87617 | 2010-04-30 14:01:05 +0000 | [diff] [blame] | 272 | raise |
maruel@chromium.org | 0b1c246 | 2010-03-02 00:48:14 +0000 | [diff] [blame] | 273 | |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 274 | if verbose: |
| 275 | print remote_output.strip() |
| 276 | # git remote update prints to stderr when used with --verbose |
| 277 | print remote_err.strip() |
| 278 | |
| 279 | # This is a big hammer, debatable if it should even be here... |
davemoore@chromium.org | 793796d | 2010-02-19 17:27:41 +0000 | [diff] [blame] | 280 | if options.force or options.reset: |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 281 | self._Run(['reset', '--hard', 'HEAD'], redirect_stdout=False) |
| 282 | |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 283 | if current_type == 'detached': |
| 284 | # case 0 |
| 285 | self._CheckClean(rev_str) |
| 286 | self._CheckDetachedHead(rev_str) |
| 287 | self._Run(['checkout', '--quiet', '%s^0' % revision]) |
| 288 | if not printed_path: |
| 289 | print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 290 | elif current_type == 'hash': |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 291 | # case 1 |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 292 | if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None: |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 293 | # Our git-svn branch (upstream_branch) is our upstream |
| 294 | self._AttemptRebase(upstream_branch, files, verbose=options.verbose, |
| 295 | newbase=revision, printed_path=printed_path) |
| 296 | printed_path = True |
| 297 | else: |
| 298 | # Can't find a merge-base since we don't know our upstream. That makes |
| 299 | # this command VERY likely to produce a rebase failure. For now we |
| 300 | # assume origin is our upstream since that's what the old behavior was. |
nasser@codeaurora.org | 3b29de1 | 2010-03-08 18:34:28 +0000 | [diff] [blame] | 301 | upstream_branch = 'origin' |
nasser@codeaurora.org | 7080e94 | 2010-03-15 15:06:16 +0000 | [diff] [blame] | 302 | if options.revision or deps_revision: |
nasser@codeaurora.org | 3b29de1 | 2010-03-08 18:34:28 +0000 | [diff] [blame] | 303 | upstream_branch = revision |
| 304 | self._AttemptRebase(upstream_branch, files=files, |
| 305 | verbose=options.verbose, printed_path=printed_path) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 306 | printed_path = True |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 307 | elif rev_type == 'hash': |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 308 | # case 2 |
| 309 | self._AttemptRebase(upstream_branch, files, verbose=options.verbose, |
| 310 | newbase=revision, printed_path=printed_path) |
| 311 | printed_path = True |
| 312 | elif revision.replace('heads', 'remotes/origin') != upstream_branch: |
| 313 | # case 4 |
| 314 | new_base = revision.replace('heads', 'remotes/origin') |
| 315 | if not printed_path: |
| 316 | print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 317 | switch_error = ("Switching upstream branch from %s to %s\n" |
| 318 | % (upstream_branch, new_base) + |
| 319 | "Please merge or rebase manually:\n" + |
| 320 | "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + |
| 321 | "OR git checkout -b <some new branch> %s" % new_base) |
| 322 | raise gclient_utils.Error(switch_error) |
| 323 | else: |
| 324 | # case 3 - the default case |
| 325 | files = self._Run(['diff', upstream_branch, '--name-only']).split() |
| 326 | if verbose: |
| 327 | print "Trying fast-forward merge to branch : %s" % upstream_branch |
| 328 | try: |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 329 | merge_output, merge_err = scm.GIT.Capture(['merge', '--ff-only', |
| 330 | upstream_branch], |
| 331 | self.checkout_path, |
| 332 | print_error=False) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 333 | except gclient_utils.CheckCallError, e: |
| 334 | if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): |
| 335 | if not printed_path: |
| 336 | print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 337 | printed_path = True |
| 338 | while True: |
| 339 | try: |
| 340 | action = str(raw_input("Cannot fast-forward merge, attempt to " |
| 341 | "rebase? (y)es / (q)uit / (s)kip : ")) |
| 342 | except ValueError: |
| 343 | gclient_utils.Error('Invalid Character') |
| 344 | continue |
| 345 | if re.match(r'yes|y', action, re.I): |
| 346 | self._AttemptRebase(upstream_branch, files, |
| 347 | verbose=options.verbose, |
| 348 | printed_path=printed_path) |
| 349 | printed_path = True |
| 350 | break |
| 351 | elif re.match(r'quit|q', action, re.I): |
| 352 | raise gclient_utils.Error("Can't fast-forward, please merge or " |
| 353 | "rebase manually.\n" |
| 354 | "cd %s && git " % self.checkout_path |
| 355 | + "rebase %s" % upstream_branch) |
| 356 | elif re.match(r'skip|s', action, re.I): |
| 357 | print "Skipping %s" % self.relpath |
| 358 | return |
| 359 | else: |
| 360 | print "Input not recognized" |
| 361 | elif re.match("error: Your local changes to '.*' would be " |
| 362 | "overwritten by merge. Aborting.\nPlease, commit your " |
| 363 | "changes or stash them before you can merge.\n", |
| 364 | e.stderr): |
| 365 | if not printed_path: |
| 366 | print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 367 | printed_path = True |
| 368 | raise gclient_utils.Error(e.stderr) |
| 369 | else: |
| 370 | # Some other problem happened with the merge |
| 371 | logging.error("Error during fast-forward merge in %s!" % self.relpath) |
| 372 | print e.stderr |
| 373 | raise |
| 374 | else: |
| 375 | # Fast-forward merge was successful |
| 376 | if not re.match('Already up-to-date.', merge_output) or verbose: |
| 377 | if not printed_path: |
| 378 | print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 379 | printed_path = True |
| 380 | print merge_output.strip() |
| 381 | if merge_err: |
| 382 | print "Merge produced error output:\n%s" % merge_err.strip() |
| 383 | if not verbose: |
| 384 | # Make the output a little prettier. It's nice to have some |
| 385 | # whitespace between projects when syncing. |
| 386 | print "" |
| 387 | |
| 388 | file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
msb@chromium.org | 5bde485 | 2009-12-14 16:47:12 +0000 | [diff] [blame] | 389 | |
| 390 | # If the rebase generated a conflict, abort and ask user to fix |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 391 | if self._IsRebasing(): |
msb@chromium.org | 5bde485 | 2009-12-14 16:47:12 +0000 | [diff] [blame] | 392 | raise gclient_utils.Error('\n____ %s%s\n' |
| 393 | '\nConflict while rebasing this branch.\n' |
| 394 | 'Fix the conflict and run gclient again.\n' |
| 395 | 'See man git-rebase for details.\n' |
| 396 | % (self.relpath, rev_str)) |
| 397 | |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 398 | if verbose: |
| 399 | print "Checked out revision %s" % self.revinfo(options, (), None) |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 400 | |
| 401 | def revert(self, options, args, file_list): |
| 402 | """Reverts local modifications. |
| 403 | |
| 404 | All reverted files will be appended to file_list. |
| 405 | """ |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 406 | __pychecker__ = 'unusednames=args' |
msb@chromium.org | 260c653 | 2009-10-28 03:22:35 +0000 | [diff] [blame] | 407 | path = os.path.join(self._root_dir, self.relpath) |
| 408 | if not os.path.isdir(path): |
| 409 | # revert won't work if the directory doesn't exist. It needs to |
| 410 | # checkout instead. |
| 411 | print("\n_____ %s is missing, synching instead" % self.relpath) |
| 412 | # Don't reuse the args. |
| 413 | return self.update(options, [], file_list) |
nasser@codeaurora.org | b2b4631 | 2010-04-30 20:58:03 +0000 | [diff] [blame] | 414 | |
| 415 | default_rev = "refs/heads/master" |
| 416 | url, deps_revision = gclient_utils.SplitUrlRevision(self.url) |
| 417 | if not deps_revision: |
| 418 | deps_revision = default_rev |
| 419 | if deps_revision.startswith('refs/heads/'): |
| 420 | deps_revision = deps_revision.replace('refs/heads/', 'origin/') |
| 421 | |
| 422 | files = self._Run(['diff', deps_revision, '--name-only']).split() |
| 423 | self._Run(['reset', '--hard', deps_revision], redirect_stdout=False) |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 424 | file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
| 425 | |
msb@chromium.org | 0f28206 | 2009-11-06 20:14:02 +0000 | [diff] [blame] | 426 | def revinfo(self, options, args, file_list): |
| 427 | """Display revision""" |
msb@chromium.org | 3904caa | 2010-01-25 17:37:46 +0000 | [diff] [blame] | 428 | __pychecker__ = 'unusednames=options,args,file_list' |
maruel@chromium.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 429 | return self._Run(['rev-parse', 'HEAD']) |
msb@chromium.org | 0f28206 | 2009-11-06 20:14:02 +0000 | [diff] [blame] | 430 | |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 431 | def runhooks(self, options, args, file_list): |
| 432 | self.status(options, args, file_list) |
| 433 | |
| 434 | def status(self, options, args, file_list): |
| 435 | """Display status information.""" |
msb@chromium.org | 3904caa | 2010-01-25 17:37:46 +0000 | [diff] [blame] | 436 | __pychecker__ = 'unusednames=options,args' |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 437 | if not os.path.isdir(self.checkout_path): |
| 438 | print('\n________ couldn\'t run status in %s:\nThe directory ' |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 439 | 'does not exist.' % self.checkout_path) |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 440 | else: |
maruel@chromium.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 441 | merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
| 442 | self._Run(['diff', '--name-status', merge_base], redirect_stdout=False) |
| 443 | files = self._Run(['diff', '--name-only', merge_base]).split() |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 444 | file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
| 445 | |
msb@chromium.org | e6f7835 | 2010-01-13 17:05:33 +0000 | [diff] [blame] | 446 | def FullUrlForRelativeUrl(self, url): |
| 447 | # Strip from last '/' |
| 448 | # Equivalent to unix basename |
| 449 | base_url = self.url |
| 450 | return base_url[:base_url.rfind('/')] + url |
| 451 | |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 452 | def _Clone(self, revision, url, verbose=False): |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 453 | """Clone a git repository from the given URL. |
| 454 | |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 455 | Once we've cloned the repo, we checkout a working branch if the specified |
| 456 | revision is a branch head. If it is a tag or a specific commit, then we |
| 457 | leave HEAD detached as it makes future updates simpler -- in this case the |
| 458 | user should first create a new branch or switch to an existing branch before |
| 459 | making changes in the repo.""" |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 460 | if not verbose: |
| 461 | # git clone doesn't seem to insert a newline properly before printing |
| 462 | # to stdout |
| 463 | print "" |
| 464 | |
| 465 | clone_cmd = ['clone'] |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 466 | if revision.startswith('refs/heads/'): |
| 467 | clone_cmd.extend(['-b', revision.replace('refs/heads/', '')]) |
| 468 | detach_head = False |
| 469 | else: |
| 470 | clone_cmd.append('--no-checkout') |
| 471 | detach_head = True |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 472 | if verbose: |
| 473 | clone_cmd.append('--verbose') |
| 474 | clone_cmd.extend([url, self.checkout_path]) |
| 475 | |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 476 | for _ in range(3): |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 477 | try: |
| 478 | self._Run(clone_cmd, cwd=self._root_dir, redirect_stdout=False) |
| 479 | break |
| 480 | except gclient_utils.Error, e: |
| 481 | # TODO(maruel): Hackish, should be fixed by moving _Run() to |
| 482 | # CheckCall(). |
| 483 | # Too bad we don't have access to the actual output. |
| 484 | # We should check for "transfer closed with NNN bytes remaining to |
| 485 | # read". In the meantime, just make sure .git exists. |
| 486 | if (e.args[0] == 'git command clone returned 128' and |
| 487 | os.path.exists(os.path.join(self.checkout_path, '.git'))): |
| 488 | print str(e) |
| 489 | print "Retrying..." |
| 490 | continue |
| 491 | raise e |
| 492 | |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 493 | if detach_head: |
| 494 | # Squelch git's very verbose detached HEAD warning and use our own |
| 495 | self._Run(['checkout', '--quiet', '%s^0' % revision]) |
| 496 | print \ |
| 497 | "Checked out %s to a detached HEAD. Before making any commits\n" \ |
| 498 | "in this repo, you should use 'git checkout <branch>' to switch to\n" \ |
| 499 | "an existing branch or use 'git checkout origin -b <branch>' to\n" \ |
| 500 | "create a new branch for your work." % revision |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 501 | |
| 502 | def _AttemptRebase(self, upstream, files, verbose=False, newbase=None, |
| 503 | branch=None, printed_path=False): |
| 504 | """Attempt to rebase onto either upstream or, if specified, newbase.""" |
| 505 | files.extend(self._Run(['diff', upstream, '--name-only']).split()) |
| 506 | revision = upstream |
| 507 | if newbase: |
| 508 | revision = newbase |
| 509 | if not printed_path: |
| 510 | print "\n_____ %s : Attempting rebase onto %s..." % (self.relpath, |
| 511 | revision) |
| 512 | printed_path = True |
| 513 | else: |
| 514 | print "Attempting rebase onto %s..." % revision |
| 515 | |
| 516 | # Build the rebase command here using the args |
| 517 | # git rebase [options] [--onto <newbase>] <upstream> [<branch>] |
| 518 | rebase_cmd = ['rebase'] |
| 519 | if verbose: |
| 520 | rebase_cmd.append('--verbose') |
| 521 | if newbase: |
| 522 | rebase_cmd.extend(['--onto', newbase]) |
| 523 | rebase_cmd.append(upstream) |
| 524 | if branch: |
| 525 | rebase_cmd.append(branch) |
| 526 | |
| 527 | try: |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 528 | rebase_output, rebase_err = scm.GIT.Capture(rebase_cmd, |
| 529 | self.checkout_path, |
| 530 | print_error=False) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 531 | except gclient_utils.CheckCallError, e: |
| 532 | if re.match(r'cannot rebase: you have unstaged changes', e.stderr) or \ |
| 533 | re.match(r'cannot rebase: your index contains uncommitted changes', |
| 534 | e.stderr): |
| 535 | while True: |
| 536 | rebase_action = str(raw_input("Cannot rebase because of unstaged " |
| 537 | "changes.\n'git reset --hard HEAD' ?\n" |
| 538 | "WARNING: destroys any uncommitted " |
| 539 | "work in your current branch!" |
| 540 | " (y)es / (q)uit / (s)how : ")) |
| 541 | if re.match(r'yes|y', rebase_action, re.I): |
| 542 | self._Run(['reset', '--hard', 'HEAD'], redirect_stdout=False) |
| 543 | # Should this be recursive? |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 544 | rebase_output, rebase_err = scm.GIT.Capture(rebase_cmd, |
| 545 | self.checkout_path) |
nasser@codeaurora.org | d90ba3f | 2010-02-23 14:42:57 +0000 | [diff] [blame] | 546 | break |
| 547 | elif re.match(r'quit|q', rebase_action, re.I): |
| 548 | raise gclient_utils.Error("Please merge or rebase manually\n" |
| 549 | "cd %s && git " % self.checkout_path |
| 550 | + "%s" % ' '.join(rebase_cmd)) |
| 551 | elif re.match(r'show|s', rebase_action, re.I): |
| 552 | print "\n%s" % e.stderr.strip() |
| 553 | continue |
| 554 | else: |
| 555 | gclient_utils.Error("Input not recognized") |
| 556 | continue |
| 557 | elif re.search(r'^CONFLICT', e.stdout, re.M): |
| 558 | raise gclient_utils.Error("Conflict while rebasing this branch.\n" |
| 559 | "Fix the conflict and run gclient again.\n" |
| 560 | "See 'man git-rebase' for details.\n") |
| 561 | else: |
| 562 | print e.stdout.strip() |
| 563 | print "Rebase produced error output:\n%s" % e.stderr.strip() |
| 564 | raise gclient_utils.Error("Unrecognized error, please merge or rebase " |
| 565 | "manually.\ncd %s && git " % |
| 566 | self.checkout_path |
| 567 | + "%s" % ' '.join(rebase_cmd)) |
| 568 | |
| 569 | print rebase_output.strip() |
| 570 | if rebase_err: |
| 571 | print "Rebase produced error output:\n%s" % rebase_err.strip() |
| 572 | if not verbose: |
| 573 | # Make the output a little prettier. It's nice to have some |
| 574 | # whitespace between projects when syncing. |
| 575 | print "" |
| 576 | |
msb@chromium.org | 923a037 | 2009-12-11 20:42:43 +0000 | [diff] [blame] | 577 | def _CheckMinVersion(self, min_version): |
maruel@chromium.org | d0f854a | 2010-03-11 19:35:53 +0000 | [diff] [blame] | 578 | (ok, current_version) = scm.GIT.AssertVersion(min_version) |
| 579 | if not ok: |
| 580 | raise gclient_utils.Error('git version %s < minimum required %s' % |
| 581 | (current_version, min_version)) |
msb@chromium.org | 923a037 | 2009-12-11 20:42:43 +0000 | [diff] [blame] | 582 | |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 583 | def _IsRebasing(self): |
| 584 | # Check for any of REBASE-i/REBASE-m/REBASE/AM. Unfortunately git doesn't |
| 585 | # have a plumbing command to determine whether a rebase is in progress, so |
| 586 | # for now emualate (more-or-less) git-rebase.sh / git-completion.bash |
| 587 | g = os.path.join(self.checkout_path, '.git') |
| 588 | return ( |
| 589 | os.path.isdir(os.path.join(g, "rebase-merge")) or |
| 590 | os.path.isdir(os.path.join(g, "rebase-apply"))) |
| 591 | |
| 592 | def _CheckClean(self, rev_str): |
| 593 | # Make sure the tree is clean; see git-rebase.sh for reference |
| 594 | try: |
| 595 | scm.GIT.Capture(['update-index', '--ignore-submodules', '--refresh'], |
| 596 | self.checkout_path, print_error=False) |
| 597 | except gclient_utils.CheckCallError, e: |
| 598 | raise gclient_utils.Error('\n____ %s%s\n' |
| 599 | '\tYou have unstaged changes.\n' |
| 600 | '\tPlease commit, stash, or reset.\n' |
| 601 | % (self.relpath, rev_str)) |
| 602 | try: |
| 603 | scm.GIT.Capture(['diff-index', '--cached', '--name-status', '-r', |
| 604 | '--ignore-submodules', 'HEAD', '--'], self.checkout_path, |
| 605 | print_error=False) |
| 606 | except gclient_utils.CheckCallError, e: |
| 607 | raise gclient_utils.Error('\n____ %s%s\n' |
| 608 | '\tYour index contains uncommitted changes\n' |
| 609 | '\tPlease commit, stash, or reset.\n' |
| 610 | % (self.relpath, rev_str)) |
| 611 | |
| 612 | def _CheckDetachedHead(self, rev_str): |
| 613 | # HEAD is detached. Make sure it is safe to move away from (i.e., it is |
| 614 | # reference by a commit). If not, error out -- most likely a rebase is |
| 615 | # in progress, try to detect so we can give a better error. |
| 616 | try: |
| 617 | out, err = scm.GIT.Capture( |
| 618 | ['name-rev', '--no-undefined', 'HEAD'], |
| 619 | self.checkout_path, |
| 620 | print_error=False) |
| 621 | except gclient_utils.CheckCallError, e: |
| 622 | # Commit is not contained by any rev. See if the user is rebasing: |
| 623 | if self._IsRebasing(): |
| 624 | # Punt to the user |
| 625 | raise gclient_utils.Error('\n____ %s%s\n' |
| 626 | '\tAlready in a conflict, i.e. (no branch).\n' |
| 627 | '\tFix the conflict and run gclient again.\n' |
| 628 | '\tOr to abort run:\n\t\tgit-rebase --abort\n' |
| 629 | '\tSee man git-rebase for details.\n' |
| 630 | % (self.relpath, rev_str)) |
| 631 | # Let's just save off the commit so we can proceed. |
| 632 | name = "saved-by-gclient-" + self._Run(["rev-parse", "--short", "HEAD"]) |
| 633 | self._Run(["branch", name]) |
| 634 | print ("\n_____ found an unreferenced commit and saved it as '%s'" % name) |
| 635 | |
msb@chromium.org | 5bde485 | 2009-12-14 16:47:12 +0000 | [diff] [blame] | 636 | def _GetCurrentBranch(self): |
msb@chromium.org | 786fb68 | 2010-06-02 15:16:23 +0000 | [diff] [blame] | 637 | # Returns name of current branch or None for detached HEAD |
| 638 | branch = self._Run(['rev-parse', '--abbrev-ref=strict', 'HEAD']) |
| 639 | if branch == 'HEAD': |
msb@chromium.org | 5bde485 | 2009-12-14 16:47:12 +0000 | [diff] [blame] | 640 | return None |
| 641 | return branch |
| 642 | |
maruel@chromium.org | 2de1025 | 2010-02-08 01:10:39 +0000 | [diff] [blame] | 643 | def _Run(self, args, cwd=None, redirect_stdout=True): |
| 644 | # TODO(maruel): Merge with Capture or better gclient_utils.CheckCall(). |
maruel@chromium.org | ffe96f0 | 2009-12-09 18:39:15 +0000 | [diff] [blame] | 645 | if cwd is None: |
| 646 | cwd = self.checkout_path |
maruel@chromium.org | 2de1025 | 2010-02-08 01:10:39 +0000 | [diff] [blame] | 647 | stdout = None |
msb@chromium.org | e8e60e5 | 2009-11-02 21:50:56 +0000 | [diff] [blame] | 648 | if redirect_stdout: |
maruel@chromium.org | 2de1025 | 2010-02-08 01:10:39 +0000 | [diff] [blame] | 649 | stdout = subprocess.PIPE |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 650 | if cwd == None: |
| 651 | cwd = self.checkout_path |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 652 | cmd = [scm.GIT.COMMAND] |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 653 | cmd.extend(args) |
maruel@chromium.org | f3909bf | 2010-01-08 01:14:51 +0000 | [diff] [blame] | 654 | logging.debug(cmd) |
| 655 | try: |
| 656 | sp = subprocess.Popen(cmd, cwd=cwd, stdout=stdout) |
| 657 | output = sp.communicate()[0] |
| 658 | except OSError: |
| 659 | raise gclient_utils.Error("git command '%s' failed to run." % |
| 660 | ' '.join(cmd) + "\nCheck that you have git installed.") |
maruel@chromium.org | 2de1025 | 2010-02-08 01:10:39 +0000 | [diff] [blame] | 661 | if sp.returncode: |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 662 | raise gclient_utils.Error('git command %s returned %d' % |
| 663 | (args[0], sp.returncode)) |
maruel@chromium.org | 5aeb7dd | 2009-11-17 18:09:01 +0000 | [diff] [blame] | 664 | if output is not None: |
msb@chromium.org | e8e60e5 | 2009-11-02 21:50:56 +0000 | [diff] [blame] | 665 | return output.strip() |
msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame] | 666 | |
| 667 | |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 668 | class SVNWrapper(SCMWrapper): |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 669 | """ Wrapper for SVN """ |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 670 | |
| 671 | def cleanup(self, options, args, file_list): |
| 672 | """Cleanup working copy.""" |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 673 | __pychecker__ = 'unusednames=file_list,options' |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 674 | command = ['cleanup'] |
| 675 | command.extend(args) |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 676 | scm.SVN.Run(command, os.path.join(self._root_dir, self.relpath)) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 677 | |
| 678 | def diff(self, options, args, file_list): |
| 679 | # NOTE: This function does not currently modify file_list. |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 680 | __pychecker__ = 'unusednames=file_list,options' |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 681 | command = ['diff'] |
| 682 | command.extend(args) |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 683 | scm.SVN.Run(command, os.path.join(self._root_dir, self.relpath)) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 684 | |
| 685 | def export(self, options, args, file_list): |
msb@chromium.org | d650421 | 2010-01-13 17:34:31 +0000 | [diff] [blame] | 686 | """Export a clean directory tree into the given path.""" |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 687 | __pychecker__ = 'unusednames=file_list,options' |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 688 | assert len(args) == 1 |
| 689 | export_path = os.path.abspath(os.path.join(args[0], self.relpath)) |
| 690 | try: |
| 691 | os.makedirs(export_path) |
| 692 | except OSError: |
| 693 | pass |
| 694 | assert os.path.exists(export_path) |
| 695 | command = ['export', '--force', '.'] |
| 696 | command.append(export_path) |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 697 | scm.SVN.Run(command, os.path.join(self._root_dir, self.relpath)) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 698 | |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 699 | def pack(self, options, args, file_list): |
| 700 | """Generates a patch file which can be applied to the root of the |
| 701 | repository.""" |
| 702 | __pychecker__ = 'unusednames=file_list,options' |
| 703 | path = os.path.join(self._root_dir, self.relpath) |
| 704 | command = ['diff'] |
| 705 | command.extend(args) |
| 706 | |
| 707 | filterer = DiffFilterer(self.relpath) |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 708 | scm.SVN.RunAndFilterOutput(command, path, False, False, filterer.Filter) |
maruel@chromium.org | ee4071d | 2009-12-22 22:25:37 +0000 | [diff] [blame] | 709 | |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 710 | def update(self, options, args, file_list): |
msb@chromium.org | d650421 | 2010-01-13 17:34:31 +0000 | [diff] [blame] | 711 | """Runs svn to update or transparently checkout the working copy. |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 712 | |
| 713 | All updated files will be appended to file_list. |
| 714 | |
| 715 | Raises: |
| 716 | Error: if can't get URL for relative path. |
| 717 | """ |
| 718 | # Only update if git is not controlling the directory. |
| 719 | checkout_path = os.path.join(self._root_dir, self.relpath) |
| 720 | git_path = os.path.join(self._root_dir, self.relpath, '.git') |
| 721 | if os.path.exists(git_path): |
| 722 | print("________ found .git directory; skipping %s" % self.relpath) |
| 723 | return |
| 724 | |
| 725 | if args: |
| 726 | raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) |
| 727 | |
msb@chromium.org | ac915bb | 2009-11-13 17:03:01 +0000 | [diff] [blame] | 728 | url, revision = gclient_utils.SplitUrlRevision(self.url) |
| 729 | base_url = url |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 730 | forced_revision = False |
msb@chromium.org | ac915bb | 2009-11-13 17:03:01 +0000 | [diff] [blame] | 731 | rev_str = "" |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 732 | if options.revision: |
| 733 | # Override the revision number. |
msb@chromium.org | ac915bb | 2009-11-13 17:03:01 +0000 | [diff] [blame] | 734 | revision = str(options.revision) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 735 | if revision: |
msb@chromium.org | ac915bb | 2009-11-13 17:03:01 +0000 | [diff] [blame] | 736 | forced_revision = True |
| 737 | url = '%s@%s' % (url, revision) |
msb@chromium.org | 770ff9e | 2009-09-23 17:18:18 +0000 | [diff] [blame] | 738 | rev_str = ' at %s' % revision |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 739 | |
| 740 | if not os.path.exists(checkout_path): |
| 741 | # We need to checkout. |
| 742 | command = ['checkout', url, checkout_path] |
tony@chromium.org | 9982812 | 2010-06-04 01:41:02 +0000 | [diff] [blame] | 743 | command = self.AddAdditionalFlags(command, options, revision) |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 744 | scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 745 | return |
| 746 | |
| 747 | # Get the existing scm url and the revision number of the current checkout. |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 748 | from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 749 | if not from_info: |
| 750 | raise gclient_utils.Error("Can't update/checkout %r if an unversioned " |
| 751 | "directory is present. Delete the directory " |
| 752 | "and try again." % |
| 753 | checkout_path) |
| 754 | |
maruel@chromium.org | 7753d24 | 2009-10-07 17:40:24 +0000 | [diff] [blame] | 755 | if options.manually_grab_svn_rev: |
| 756 | # Retrieve the current HEAD version because svn is slow at null updates. |
| 757 | if not revision: |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 758 | from_info_live = scm.SVN.CaptureInfo(from_info['URL'], '.') |
maruel@chromium.org | 7753d24 | 2009-10-07 17:40:24 +0000 | [diff] [blame] | 759 | revision = str(from_info_live['Revision']) |
| 760 | rev_str = ' at %s' % revision |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 761 | |
msb@chromium.org | ac915bb | 2009-11-13 17:03:01 +0000 | [diff] [blame] | 762 | if from_info['URL'] != base_url: |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 763 | to_info = scm.SVN.CaptureInfo(url, '.') |
maruel@chromium.org | e2ce0c7 | 2009-09-23 16:14:18 +0000 | [diff] [blame] | 764 | if not to_info.get('Repository Root') or not to_info.get('UUID'): |
| 765 | # The url is invalid or the server is not accessible, it's safer to bail |
| 766 | # out right now. |
| 767 | raise gclient_utils.Error('This url is unreachable: %s' % url) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 768 | can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) |
| 769 | and (from_info['UUID'] == to_info['UUID'])) |
| 770 | if can_switch: |
| 771 | print("\n_____ relocating %s to a new checkout" % self.relpath) |
| 772 | # We have different roots, so check if we can switch --relocate. |
| 773 | # Subversion only permits this if the repository UUIDs match. |
| 774 | # Perform the switch --relocate, then rewrite the from_url |
| 775 | # to reflect where we "are now." (This is the same way that |
| 776 | # Subversion itself handles the metadata when switch --relocate |
| 777 | # is used.) This makes the checks below for whether we |
| 778 | # can update to a revision or have to switch to a different |
| 779 | # branch work as expected. |
| 780 | # TODO(maruel): TEST ME ! |
| 781 | command = ["switch", "--relocate", |
| 782 | from_info['Repository Root'], |
| 783 | to_info['Repository Root'], |
| 784 | self.relpath] |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 785 | scm.SVN.Run(command, self._root_dir) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 786 | from_info['URL'] = from_info['URL'].replace( |
| 787 | from_info['Repository Root'], |
| 788 | to_info['Repository Root']) |
| 789 | else: |
tony@chromium.org | 9292041 | 2010-06-04 05:08:56 +0000 | [diff] [blame] | 790 | if scm.SVN.CaptureStatus(checkout_path) and not options.force: |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 791 | raise gclient_utils.Error("Can't switch the checkout to %s; UUID " |
| 792 | "don't match and there is local changes " |
| 793 | "in %s. Delete the directory and " |
| 794 | "try again." % (url, checkout_path)) |
| 795 | # Ok delete it. |
| 796 | print("\n_____ switching %s to a new checkout" % self.relpath) |
bradnelson@google.com | 8f9c69f | 2009-09-17 00:48:28 +0000 | [diff] [blame] | 797 | gclient_utils.RemoveDirectory(checkout_path) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 798 | # We need to checkout. |
| 799 | command = ['checkout', url, checkout_path] |
tony@chromium.org | 9982812 | 2010-06-04 01:41:02 +0000 | [diff] [blame] | 800 | command = self.AddAdditionalFlags(command, options, revision) |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 801 | scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 802 | return |
| 803 | |
| 804 | |
| 805 | # If the provided url has a revision number that matches the revision |
| 806 | # number of the existing directory, then we don't need to bother updating. |
maruel@chromium.org | 2e0c685 | 2009-09-24 00:02:07 +0000 | [diff] [blame] | 807 | if not options.force and str(from_info['Revision']) == revision: |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 808 | if options.verbose or not forced_revision: |
| 809 | print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 810 | return |
| 811 | |
| 812 | command = ["update", checkout_path] |
tony@chromium.org | 9982812 | 2010-06-04 01:41:02 +0000 | [diff] [blame] | 813 | command = self.AddAdditionalFlags(command, options, revision) |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 814 | scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 815 | |
tony@chromium.org | 4b5b177 | 2010-04-08 01:52:56 +0000 | [diff] [blame] | 816 | def updatesingle(self, options, args, file_list): |
| 817 | checkout_path = os.path.join(self._root_dir, self.relpath) |
| 818 | filename = args.pop() |
tony@chromium.org | 5756466 | 2010-04-14 02:35:12 +0000 | [diff] [blame] | 819 | if scm.SVN.AssertVersion("1.5")[0]: |
| 820 | if not os.path.exists(os.path.join(checkout_path, '.svn')): |
| 821 | # Create an empty checkout and then update the one file we want. Future |
| 822 | # operations will only apply to the one file we checked out. |
| 823 | command = ["checkout", "--depth", "empty", self.url, checkout_path] |
| 824 | scm.SVN.Run(command, self._root_dir) |
| 825 | if os.path.exists(os.path.join(checkout_path, filename)): |
| 826 | os.remove(os.path.join(checkout_path, filename)) |
| 827 | command = ["update", filename] |
| 828 | scm.SVN.RunAndGetFileList(options, command, checkout_path, file_list) |
| 829 | # After the initial checkout, we can use update as if it were any other |
| 830 | # dep. |
| 831 | self.update(options, args, file_list) |
| 832 | else: |
| 833 | # If the installed version of SVN doesn't support --depth, fallback to |
| 834 | # just exporting the file. This has the downside that revision |
| 835 | # information is not stored next to the file, so we will have to |
| 836 | # re-export the file every time we sync. |
| 837 | if not os.path.exists(checkout_path): |
| 838 | os.makedirs(checkout_path) |
| 839 | command = ["export", os.path.join(self.url, filename), |
| 840 | os.path.join(checkout_path, filename)] |
tony@chromium.org | 9982812 | 2010-06-04 01:41:02 +0000 | [diff] [blame] | 841 | command = self.AddAdditionalFlags(command, options, options.revision) |
tony@chromium.org | 4b5b177 | 2010-04-08 01:52:56 +0000 | [diff] [blame] | 842 | scm.SVN.Run(command, self._root_dir) |
tony@chromium.org | 4b5b177 | 2010-04-08 01:52:56 +0000 | [diff] [blame] | 843 | |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 844 | def revert(self, options, args, file_list): |
| 845 | """Reverts local modifications. Subversion specific. |
| 846 | |
| 847 | All reverted files will be appended to file_list, even if Subversion |
| 848 | doesn't know about them. |
| 849 | """ |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 850 | __pychecker__ = 'unusednames=args' |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 851 | path = os.path.join(self._root_dir, self.relpath) |
| 852 | if not os.path.isdir(path): |
| 853 | # svn revert won't work if the directory doesn't exist. It needs to |
| 854 | # checkout instead. |
| 855 | print("\n_____ %s is missing, synching instead" % self.relpath) |
| 856 | # Don't reuse the args. |
| 857 | return self.update(options, [], file_list) |
| 858 | |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 859 | for file_status in scm.SVN.CaptureStatus(path): |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 860 | file_path = os.path.join(path, file_status[1]) |
| 861 | if file_status[0][0] == 'X': |
maruel@chromium.org | 754960e | 2009-09-21 12:31:05 +0000 | [diff] [blame] | 862 | # Ignore externals. |
maruel@chromium.org | aa3dd47 | 2009-09-21 19:02:48 +0000 | [diff] [blame] | 863 | logging.info('Ignoring external %s' % file_path) |
maruel@chromium.org | 754960e | 2009-09-21 12:31:05 +0000 | [diff] [blame] | 864 | continue |
| 865 | |
maruel@chromium.org | aa3dd47 | 2009-09-21 19:02:48 +0000 | [diff] [blame] | 866 | if logging.getLogger().isEnabledFor(logging.INFO): |
| 867 | logging.info('%s%s' % (file[0], file[1])) |
| 868 | else: |
| 869 | print(file_path) |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 870 | if file_status[0].isspace(): |
maruel@chromium.org | aa3dd47 | 2009-09-21 19:02:48 +0000 | [diff] [blame] | 871 | logging.error('No idea what is the status of %s.\n' |
| 872 | 'You just found a bug in gclient, please ping ' |
| 873 | 'maruel@chromium.org ASAP!' % file_path) |
| 874 | # svn revert is really stupid. It fails on inconsistent line-endings, |
| 875 | # on switched directories, etc. So take no chance and delete everything! |
| 876 | try: |
| 877 | if not os.path.exists(file_path): |
| 878 | pass |
maruel@chromium.org | d2e78ff | 2010-01-11 20:37:19 +0000 | [diff] [blame] | 879 | elif os.path.isfile(file_path) or os.path.islink(file_path): |
maruel@chromium.org | 754960e | 2009-09-21 12:31:05 +0000 | [diff] [blame] | 880 | logging.info('os.remove(%s)' % file_path) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 881 | os.remove(file_path) |
maruel@chromium.org | aa3dd47 | 2009-09-21 19:02:48 +0000 | [diff] [blame] | 882 | elif os.path.isdir(file_path): |
maruel@chromium.org | 754960e | 2009-09-21 12:31:05 +0000 | [diff] [blame] | 883 | logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) |
bradnelson@google.com | 8f9c69f | 2009-09-17 00:48:28 +0000 | [diff] [blame] | 884 | gclient_utils.RemoveDirectory(file_path) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 885 | else: |
maruel@chromium.org | aa3dd47 | 2009-09-21 19:02:48 +0000 | [diff] [blame] | 886 | logging.error('no idea what is %s.\nYou just found a bug in gclient' |
| 887 | ', please ping maruel@chromium.org ASAP!' % file_path) |
| 888 | except EnvironmentError: |
| 889 | logging.error('Failed to remove %s.' % file_path) |
| 890 | |
maruel@chromium.org | 810a50b | 2009-10-05 23:03:18 +0000 | [diff] [blame] | 891 | try: |
| 892 | # svn revert is so broken we don't even use it. Using |
| 893 | # "svn up --revision BASE" achieve the same effect. |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 894 | scm.SVN.RunAndGetFileList(options, ['update', '--revision', 'BASE'], path, |
| 895 | file_list) |
maruel@chromium.org | 810a50b | 2009-10-05 23:03:18 +0000 | [diff] [blame] | 896 | except OSError, e: |
| 897 | # Maybe the directory disapeared meanwhile. We don't want it to throw an |
| 898 | # exception. |
| 899 | logging.error('Failed to update:\n%s' % str(e)) |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 900 | |
msb@chromium.org | 0f28206 | 2009-11-06 20:14:02 +0000 | [diff] [blame] | 901 | def revinfo(self, options, args, file_list): |
| 902 | """Display revision""" |
maruel@chromium.org | e3608df | 2009-11-10 20:22:57 +0000 | [diff] [blame] | 903 | __pychecker__ = 'unusednames=args,file_list,options' |
nasser@codeaurora.org | 5d63eb8 | 2010-03-24 23:22:09 +0000 | [diff] [blame] | 904 | return scm.SVN.CaptureBaseRevision(self.checkout_path) |
msb@chromium.org | 0f28206 | 2009-11-06 20:14:02 +0000 | [diff] [blame] | 905 | |
msb@chromium.org | cb5442b | 2009-09-22 16:51:24 +0000 | [diff] [blame] | 906 | def runhooks(self, options, args, file_list): |
| 907 | self.status(options, args, file_list) |
| 908 | |
maruel@chromium.org | 5f3eee3 | 2009-09-17 00:34:30 +0000 | [diff] [blame] | 909 | def status(self, options, args, file_list): |
| 910 | """Display status information.""" |
| 911 | path = os.path.join(self._root_dir, self.relpath) |
| 912 | command = ['status'] |
| 913 | command.extend(args) |
| 914 | if not os.path.isdir(path): |
| 915 | # svn status won't work if the directory doesn't exist. |
| 916 | print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
| 917 | "does not exist." |
| 918 | % (' '.join(command), path)) |
| 919 | # There's no file list to retrieve. |
| 920 | else: |
maruel@chromium.org | 55e724e | 2010-03-11 19:36:49 +0000 | [diff] [blame] | 921 | scm.SVN.RunAndGetFileList(options, command, path, file_list) |
msb@chromium.org | e6f7835 | 2010-01-13 17:05:33 +0000 | [diff] [blame] | 922 | |
| 923 | def FullUrlForRelativeUrl(self, url): |
| 924 | # Find the forth '/' and strip from there. A bit hackish. |
| 925 | return '/'.join(self.url.split('/')[:4]) + url |
tony@chromium.org | 9982812 | 2010-06-04 01:41:02 +0000 | [diff] [blame] | 926 | |
| 927 | def AddAdditionalFlags(self, command, options, revision): |
| 928 | """Add additional flags to command depending on what options are set. |
| 929 | command should be a list of strings that represents an svn command. |
| 930 | |
| 931 | This method returns a new list to be used as a command.""" |
| 932 | new_command = command[:] |
| 933 | if revision: |
| 934 | new_command.extend(['--revision', str(revision).strip()]) |
| 935 | # --force was added to 'svn update' in svn 1.5. |
| 936 | if options.force and scm.SVN.AssertVersion("1.5")[0]: |
| 937 | new_command.append('--force') |
| 938 | return new_command |