OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 rev_str = ' at %s' % revision | 179 rev_str = ' at %s' % revision |
180 files = [] | 180 files = [] |
181 | 181 |
182 printed_path = False | 182 printed_path = False |
183 verbose = [] | 183 verbose = [] |
184 if options.verbose: | 184 if options.verbose: |
185 print('\n_____ %s%s' % (self.relpath, rev_str)) | 185 print('\n_____ %s%s' % (self.relpath, rev_str)) |
186 verbose = ['--verbose'] | 186 verbose = ['--verbose'] |
187 printed_path = True | 187 printed_path = True |
188 | 188 |
189 # See if the url has changed | |
190 current_url = self._Capture(['config', 'remote.origin.url']) | |
191 if current_url != url: | |
192 print('_____ switching %s to a new upstream' % self.relpath) | |
193 # Make sure it's clean | |
194 self._CheckClean(rev_str) | |
195 # Switch over to the new upstream | |
196 self._Run(['remote', 'set-url', 'origin', url], options) | |
197 quiet = [] | |
198 if not options.verbose: | |
199 quiet = ['--quiet'] | |
200 self._Run(['fetch', 'origin', '--prune'] + quiet, options) | |
201 self._Run(['reset', '--hard', 'origin/master'] + quiet, options) | |
202 files = self._Capture(['ls-files']).splitlines() | |
203 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | |
204 return | |
205 | |
206 if revision.startswith('refs/heads/'): | 189 if revision.startswith('refs/heads/'): |
207 rev_type = "branch" | 190 rev_type = "branch" |
208 elif revision.startswith('origin/'): | 191 elif revision.startswith('origin/'): |
209 # For compatability with old naming, translate 'origin' to 'refs/heads' | 192 # For compatability with old naming, translate 'origin' to 'refs/heads' |
210 revision = revision.replace('origin/', 'refs/heads/') | 193 revision = revision.replace('origin/', 'refs/heads/') |
211 rev_type = "branch" | 194 rev_type = "branch" |
212 else: | 195 else: |
213 # hash is also a tag, only make a distinction at checkout | 196 # hash is also a tag, only make a distinction at checkout |
214 rev_type = "hash" | 197 rev_type = "hash" |
215 | 198 |
216 if not os.path.exists(self.checkout_path): | 199 if not os.path.exists(self.checkout_path): |
217 self._Clone(revision, url, options) | 200 self._Clone(revision, url, options) |
218 files = self._Capture(['ls-files']).splitlines() | 201 files = self._Capture(['ls-files']).splitlines() |
219 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 202 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
220 if not verbose: | 203 if not verbose: |
221 # Make the output a little prettier. It's nice to have some whitespace | 204 # Make the output a little prettier. It's nice to have some whitespace |
222 # between projects when cloning. | 205 # between projects when cloning. |
223 print('') | 206 print('') |
224 return | 207 return |
225 | 208 |
226 if not os.path.exists(os.path.join(self.checkout_path, '.git')): | 209 if not os.path.exists(os.path.join(self.checkout_path, '.git')): |
227 raise gclient_utils.Error('\n____ %s%s\n' | 210 raise gclient_utils.Error('\n____ %s%s\n' |
228 '\tPath is not a git repo. No .git dir.\n' | 211 '\tPath is not a git repo. No .git dir.\n' |
229 '\tTo resolve:\n' | 212 '\tTo resolve:\n' |
230 '\t\trm -rf %s\n' | 213 '\t\trm -rf %s\n' |
231 '\tAnd run gclient sync again\n' | 214 '\tAnd run gclient sync again\n' |
232 % (self.relpath, rev_str, self.relpath)) | 215 % (self.relpath, rev_str, self.relpath)) |
233 | 216 |
| 217 # See if the url has changed |
| 218 current_url = self._Capture(['config', 'remote.origin.url']) |
| 219 if current_url != url: |
| 220 print('_____ switching %s to a new upstream' % self.relpath) |
| 221 # Make sure it's clean |
| 222 self._CheckClean(rev_str) |
| 223 # Switch over to the new upstream |
| 224 self._Run(['remote', 'set-url', 'origin', url], options) |
| 225 quiet = [] |
| 226 if not options.verbose: |
| 227 quiet = ['--quiet'] |
| 228 self._Run(['fetch', 'origin', '--prune'] + quiet, options) |
| 229 self._Run(['reset', '--hard', 'origin/master'] + quiet, options) |
| 230 files = self._Capture(['ls-files']).splitlines() |
| 231 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
| 232 return |
| 233 |
234 cur_branch = self._GetCurrentBranch() | 234 cur_branch = self._GetCurrentBranch() |
235 | 235 |
236 # Cases: | 236 # Cases: |
237 # 0) HEAD is detached. Probably from our initial clone. | 237 # 0) HEAD is detached. Probably from our initial clone. |
238 # - make sure HEAD is contained by a named ref, then update. | 238 # - make sure HEAD is contained by a named ref, then update. |
239 # Cases 1-4. HEAD is a branch. | 239 # Cases 1-4. HEAD is a branch. |
240 # 1) current branch is not tracking a remote branch (could be git-svn) | 240 # 1) current branch is not tracking a remote branch (could be git-svn) |
241 # - try to rebase onto the new hash or branch | 241 # - try to rebase onto the new hash or branch |
242 # 2) current branch is tracking a remote branch with local committed | 242 # 2) current branch is tracking a remote branch with local committed |
243 # changes, but the DEPS file switched to point to a hash | 243 # changes, but the DEPS file switched to point to a hash |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 | 921 |
922 This method returns a new list to be used as a command.""" | 922 This method returns a new list to be used as a command.""" |
923 new_command = command[:] | 923 new_command = command[:] |
924 if revision: | 924 if revision: |
925 new_command.extend(['--revision', str(revision).strip()]) | 925 new_command.extend(['--revision', str(revision).strip()]) |
926 # --force was added to 'svn update' in svn 1.5. | 926 # --force was added to 'svn update' in svn 1.5. |
927 if ((options.force or options.manually_grab_svn_rev) and | 927 if ((options.force or options.manually_grab_svn_rev) and |
928 scm.SVN.AssertVersion("1.5")[0]): | 928 scm.SVN.AssertVersion("1.5")[0]): |
929 new_command.append('--force') | 929 new_command.append('--force') |
930 return new_command | 930 return new_command |
OLD | NEW |