OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 collections | 7 import collections |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import posixpath | 10 import posixpath |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 if not match: | 181 if not match: |
182 self.last_time = 0 | 182 self.last_time = 0 |
183 if (now - self.last_time) >= self.time_throttle: | 183 if (now - self.last_time) >= self.time_throttle: |
184 self.last_time = now | 184 self.last_time = now |
185 print line | 185 print line |
186 | 186 |
187 | 187 |
188 class GitWrapper(SCMWrapper): | 188 class GitWrapper(SCMWrapper): |
189 """Wrapper for Git""" | 189 """Wrapper for Git""" |
190 name = 'git' | 190 name = 'git' |
| 191 remote = 'origin' |
191 | 192 |
192 cache_dir = None | 193 cache_dir = None |
193 # If a given cache is used in a solution more than once, prevent multiple | 194 # If a given cache is used in a solution more than once, prevent multiple |
194 # threads from updating it simultaneously. | 195 # threads from updating it simultaneously. |
195 cache_locks = collections.defaultdict(threading.Lock) | 196 cache_locks = collections.defaultdict(threading.Lock) |
196 | 197 |
197 def __init__(self, url=None, root_dir=None, relpath=None): | 198 def __init__(self, url=None, root_dir=None, relpath=None): |
198 """Removes 'git+' fake prefix from git URL.""" | 199 """Removes 'git+' fake prefix from git URL.""" |
199 if url.startswith('git+http://') or url.startswith('git+https://'): | 200 if url.startswith('git+http://') or url.startswith('git+https://'): |
200 url = url[4:] | 201 url = url[4:] |
(...skipping 22 matching lines...) Expand all Loading... |
223 return self._Capture(['log', '-n', '1', '--format=%ai']) | 224 return self._Capture(['log', '-n', '1', '--format=%ai']) |
224 | 225 |
225 @staticmethod | 226 @staticmethod |
226 def cleanup(options, args, file_list): | 227 def cleanup(options, args, file_list): |
227 """'Cleanup' the repo. | 228 """'Cleanup' the repo. |
228 | 229 |
229 There's no real git equivalent for the svn cleanup command, do a no-op. | 230 There's no real git equivalent for the svn cleanup command, do a no-op. |
230 """ | 231 """ |
231 | 232 |
232 def diff(self, options, _args, _file_list): | 233 def diff(self, options, _args, _file_list): |
233 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) | 234 merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) |
234 self._Run(['diff', merge_base], options) | 235 self._Run(['diff', merge_base], options) |
235 | 236 |
236 def pack(self, _options, _args, _file_list): | 237 def pack(self, _options, _args, _file_list): |
237 """Generates a patch file which can be applied to the root of the | 238 """Generates a patch file which can be applied to the root of the |
238 repository. | 239 repository. |
239 | 240 |
240 The patch file is generated from a diff of the merge base of HEAD and | 241 The patch file is generated from a diff of the merge base of HEAD and |
241 its upstream branch. | 242 its upstream branch. |
242 """ | 243 """ |
243 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) | 244 merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) |
244 gclient_utils.CheckCallAndFilter( | 245 gclient_utils.CheckCallAndFilter( |
245 ['git', 'diff', merge_base], | 246 ['git', 'diff', merge_base], |
246 cwd=self.checkout_path, | 247 cwd=self.checkout_path, |
247 filter_fn=GitDiffFilterer(self.relpath).Filter) | 248 filter_fn=GitDiffFilterer(self.relpath).Filter) |
248 | 249 |
249 def UpdateSubmoduleConfig(self): | 250 def UpdateSubmoduleConfig(self): |
250 submod_cmd = ['git', 'config', '-f', '$toplevel/.git/config', | 251 submod_cmd = ['git', 'config', '-f', '$toplevel/.git/config', |
251 'submodule.$name.ignore', '||', | 252 'submodule.$name.ignore', '||', |
252 'git', 'config', '-f', '$toplevel/.git/config', | 253 'git', 'config', '-f', '$toplevel/.git/config', |
253 'submodule.$name.ignore', 'all'] | 254 'submodule.$name.ignore', 'all'] |
(...skipping 19 matching lines...) Expand all Loading... |
273 gclient_utils.CheckCallAndFilter(cmd4, **kwargs) | 274 gclient_utils.CheckCallAndFilter(cmd4, **kwargs) |
274 | 275 |
275 def _FetchAndReset(self, revision, file_list, options): | 276 def _FetchAndReset(self, revision, file_list, options): |
276 """Equivalent to git fetch; git reset.""" | 277 """Equivalent to git fetch; git reset.""" |
277 quiet = [] | 278 quiet = [] |
278 if not options.verbose: | 279 if not options.verbose: |
279 quiet = ['--quiet'] | 280 quiet = ['--quiet'] |
280 self._UpdateBranchHeads(options, fetch=False) | 281 self._UpdateBranchHeads(options, fetch=False) |
281 | 282 |
282 fetch_cmd = [ | 283 fetch_cmd = [ |
283 '-c', 'core.deltaBaseCacheLimit=2g', 'fetch', 'origin', '--prune'] | 284 '-c', 'core.deltaBaseCacheLimit=2g', 'fetch', self.remote, '--prune'] |
284 self._Run(fetch_cmd + quiet, options, retry=True) | 285 self._Run(fetch_cmd + quiet, options, retry=True) |
285 self._Run(['reset', '--hard', revision] + quiet, options) | 286 self._Run(['reset', '--hard', revision] + quiet, options) |
286 self.UpdateSubmoduleConfig() | 287 self.UpdateSubmoduleConfig() |
287 if file_list is not None: | 288 if file_list is not None: |
288 files = self._Capture(['ls-files']).splitlines() | 289 files = self._Capture(['ls-files']).splitlines() |
289 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 290 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
290 | 291 |
291 def update(self, options, args, file_list): | 292 def update(self, options, args, file_list): |
292 """Runs git to update or transparently checkout the working copy. | 293 """Runs git to update or transparently checkout the working copy. |
293 | 294 |
294 All updated files will be appended to file_list. | 295 All updated files will be appended to file_list. |
295 | 296 |
296 Raises: | 297 Raises: |
297 Error: if can't get URL for relative path. | 298 Error: if can't get URL for relative path. |
298 """ | 299 """ |
299 if args: | 300 if args: |
300 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) | 301 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) |
301 | 302 |
302 self._CheckMinVersion("1.6.6") | 303 self._CheckMinVersion("1.6.6") |
303 | 304 |
304 default_rev = "refs/heads/master" | 305 # If a dependency is not pinned, track the default remote branch. |
| 306 default_rev = 'refs/remotes/%s/master' % self.remote |
305 url, deps_revision = gclient_utils.SplitUrlRevision(self.url) | 307 url, deps_revision = gclient_utils.SplitUrlRevision(self.url) |
306 rev_str = "" | 308 rev_str = "" |
307 revision = deps_revision | 309 revision = deps_revision |
308 managed = True | 310 managed = True |
309 if options.revision: | 311 if options.revision: |
310 # Override the revision number. | 312 # Override the revision number. |
311 revision = str(options.revision) | 313 revision = str(options.revision) |
312 if revision == 'unmanaged': | 314 if revision == 'unmanaged': |
313 revision = None | 315 revision = None |
314 managed = False | 316 managed = False |
(...skipping 15 matching lines...) Expand all Loading... |
330 verbose = [] | 332 verbose = [] |
331 if options.verbose: | 333 if options.verbose: |
332 print('\n_____ %s%s' % (self.relpath, rev_str)) | 334 print('\n_____ %s%s' % (self.relpath, rev_str)) |
333 verbose = ['--verbose'] | 335 verbose = ['--verbose'] |
334 printed_path = True | 336 printed_path = True |
335 | 337 |
336 url = self._CreateOrUpdateCache(url, options) | 338 url = self._CreateOrUpdateCache(url, options) |
337 | 339 |
338 if revision.startswith('refs/'): | 340 if revision.startswith('refs/'): |
339 rev_type = "branch" | 341 rev_type = "branch" |
340 elif revision.startswith('origin/'): | 342 elif revision.startswith(self.remote + '/'): |
341 # For compatability with old naming, translate 'origin' to 'refs/heads' | 343 # For compatibility with old naming, translate 'origin' to 'refs/heads' |
342 revision = revision.replace('origin/', 'refs/heads/') | 344 revision = revision.replace(self.remote + '/', 'refs/heads/') |
343 rev_type = "branch" | 345 rev_type = "branch" |
344 else: | 346 else: |
345 # hash is also a tag, only make a distinction at checkout | 347 # hash is also a tag, only make a distinction at checkout |
346 rev_type = "hash" | 348 rev_type = "hash" |
347 | 349 |
348 if (not os.path.exists(self.checkout_path) or | 350 if (not os.path.exists(self.checkout_path) or |
349 (os.path.isdir(self.checkout_path) and | 351 (os.path.isdir(self.checkout_path) and |
350 not os.path.exists(os.path.join(self.checkout_path, '.git')))): | 352 not os.path.exists(os.path.join(self.checkout_path, '.git')))): |
351 self._Clone(revision, url, options) | 353 self._Clone(revision, url, options) |
352 self.UpdateSubmoduleConfig() | 354 self.UpdateSubmoduleConfig() |
(...skipping 15 matching lines...) Expand all Loading... |
368 if not os.path.exists(os.path.join(self.checkout_path, '.git')): | 370 if not os.path.exists(os.path.join(self.checkout_path, '.git')): |
369 raise gclient_utils.Error('\n____ %s%s\n' | 371 raise gclient_utils.Error('\n____ %s%s\n' |
370 '\tPath is not a git repo. No .git dir.\n' | 372 '\tPath is not a git repo. No .git dir.\n' |
371 '\tTo resolve:\n' | 373 '\tTo resolve:\n' |
372 '\t\trm -rf %s\n' | 374 '\t\trm -rf %s\n' |
373 '\tAnd run gclient sync again\n' | 375 '\tAnd run gclient sync again\n' |
374 % (self.relpath, rev_str, self.relpath)) | 376 % (self.relpath, rev_str, self.relpath)) |
375 | 377 |
376 # See if the url has changed (the unittests use git://foo for the url, let | 378 # See if the url has changed (the unittests use git://foo for the url, let |
377 # that through). | 379 # that through). |
378 current_url = self._Capture(['config', 'remote.origin.url']) | 380 current_url = self._Capture(['config', 'remote.%s.url' % self.remote]) |
379 return_early = False | 381 return_early = False |
380 # TODO(maruel): Delete url != 'git://foo' since it's just to make the | 382 # TODO(maruel): Delete url != 'git://foo' since it's just to make the |
381 # unit test pass. (and update the comment above) | 383 # unit test pass. (and update the comment above) |
382 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. | 384 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. |
383 # This allows devs to use experimental repos which have a different url | 385 # This allows devs to use experimental repos which have a different url |
384 # but whose branch(s) are the same as official repos. | 386 # but whose branch(s) are the same as official repos. |
385 if (current_url != url and | 387 if (current_url != url and |
386 url != 'git://foo' and | 388 url != 'git://foo' and |
387 subprocess2.capture( | 389 subprocess2.capture( |
388 ['git', 'config', 'remote.origin.gclient-auto-fix-url'], | 390 ['git', 'config', 'remote.%s.gclient-auto-fix-url' % self.remote], |
389 cwd=self.checkout_path).strip() != 'False'): | 391 cwd=self.checkout_path).strip() != 'False'): |
390 print('_____ switching %s to a new upstream' % self.relpath) | 392 print('_____ switching %s to a new upstream' % self.relpath) |
391 # Make sure it's clean | 393 # Make sure it's clean |
392 self._CheckClean(rev_str) | 394 self._CheckClean(rev_str) |
393 # Switch over to the new upstream | 395 # Switch over to the new upstream |
394 self._Run(['remote', 'set-url', 'origin', url], options) | 396 self._Run(['remote', 'set-url', self.remote, url], options) |
395 self._FetchAndReset(revision, file_list, options) | 397 self._FetchAndReset(revision, file_list, options) |
396 return_early = True | 398 return_early = True |
397 | 399 |
398 # Need to do this in the normal path as well as in the post-remote-switch | 400 # Need to do this in the normal path as well as in the post-remote-switch |
399 # path. | 401 # path. |
400 self._PossiblySwitchCache(url, options) | 402 self._PossiblySwitchCache(url, options) |
401 | 403 |
402 if return_early: | 404 if return_early: |
403 return self._Capture(['rev-parse', '--verify', 'HEAD']) | 405 return self._Capture(['rev-parse', '--verify', 'HEAD']) |
404 | 406 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 # case 1 | 468 # case 1 |
467 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None: | 469 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None: |
468 # Our git-svn branch (upstream_branch) is our upstream | 470 # Our git-svn branch (upstream_branch) is our upstream |
469 self._AttemptRebase(upstream_branch, files, options, | 471 self._AttemptRebase(upstream_branch, files, options, |
470 newbase=revision, printed_path=printed_path) | 472 newbase=revision, printed_path=printed_path) |
471 printed_path = True | 473 printed_path = True |
472 else: | 474 else: |
473 # Can't find a merge-base since we don't know our upstream. That makes | 475 # Can't find a merge-base since we don't know our upstream. That makes |
474 # this command VERY likely to produce a rebase failure. For now we | 476 # this command VERY likely to produce a rebase failure. For now we |
475 # assume origin is our upstream since that's what the old behavior was. | 477 # assume origin is our upstream since that's what the old behavior was. |
476 upstream_branch = 'origin' | 478 upstream_branch = self.remote |
477 if options.revision or deps_revision: | 479 if options.revision or deps_revision: |
478 upstream_branch = revision | 480 upstream_branch = revision |
479 self._AttemptRebase(upstream_branch, files, options, | 481 self._AttemptRebase(upstream_branch, files, options, |
480 printed_path=printed_path) | 482 printed_path=printed_path) |
481 printed_path = True | 483 printed_path = True |
482 elif rev_type == 'hash': | 484 elif rev_type == 'hash': |
483 # case 2 | 485 # case 2 |
484 self._AttemptRebase(upstream_branch, files, options, | 486 self._AttemptRebase(upstream_branch, files, options, |
485 newbase=revision, printed_path=printed_path) | 487 newbase=revision, printed_path=printed_path) |
486 printed_path = True | 488 printed_path = True |
487 elif revision.replace('heads', 'remotes/origin') != upstream_branch: | 489 elif revision.replace('heads', 'remotes/' + self.remote) != upstream_branch: |
488 # case 4 | 490 # case 4 |
489 new_base = revision.replace('heads', 'remotes/origin') | 491 new_base = revision.replace('heads', 'remotes/' + self.remote) |
490 if not printed_path: | 492 if not printed_path: |
491 print('\n_____ %s%s' % (self.relpath, rev_str)) | 493 print('\n_____ %s%s' % (self.relpath, rev_str)) |
492 switch_error = ("Switching upstream branch from %s to %s\n" | 494 switch_error = ("Switching upstream branch from %s to %s\n" |
493 % (upstream_branch, new_base) + | 495 % (upstream_branch, new_base) + |
494 "Please merge or rebase manually:\n" + | 496 "Please merge or rebase manually:\n" + |
495 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + | 497 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + |
496 "OR git checkout -b <some new branch> %s" % new_base) | 498 "OR git checkout -b <some new branch> %s" % new_base) |
497 raise gclient_utils.Error(switch_error) | 499 raise gclient_utils.Error(switch_error) |
498 else: | 500 else: |
499 # case 3 - the default case | 501 # case 3 - the default case |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 608 |
607 default_rev = "refs/heads/master" | 609 default_rev = "refs/heads/master" |
608 if options.upstream: | 610 if options.upstream: |
609 if self._GetCurrentBranch(): | 611 if self._GetCurrentBranch(): |
610 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path) | 612 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path) |
611 default_rev = upstream_branch or default_rev | 613 default_rev = upstream_branch or default_rev |
612 _, deps_revision = gclient_utils.SplitUrlRevision(self.url) | 614 _, deps_revision = gclient_utils.SplitUrlRevision(self.url) |
613 if not deps_revision: | 615 if not deps_revision: |
614 deps_revision = default_rev | 616 deps_revision = default_rev |
615 if deps_revision.startswith('refs/heads/'): | 617 if deps_revision.startswith('refs/heads/'): |
616 deps_revision = deps_revision.replace('refs/heads/', 'origin/') | 618 deps_revision = deps_revision.replace('refs/heads/', self.remote + '/') |
617 | 619 |
618 if file_list is not None: | 620 if file_list is not None: |
619 files = self._Capture(['diff', deps_revision, '--name-only']).split() | 621 files = self._Capture(['diff', deps_revision, '--name-only']).split() |
620 | 622 |
621 self._Run(['reset', '--hard', deps_revision], options) | 623 self._Run(['reset', '--hard', deps_revision], options) |
622 self._Run(['clean', '-f', '-d'], options) | 624 self._Run(['clean', '-f', '-d'], options) |
623 | 625 |
624 if file_list is not None: | 626 if file_list is not None: |
625 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 627 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
626 | 628 |
627 def revinfo(self, _options, _args, _file_list): | 629 def revinfo(self, _options, _args, _file_list): |
628 """Returns revision""" | 630 """Returns revision""" |
629 return self._Capture(['rev-parse', 'HEAD']) | 631 return self._Capture(['rev-parse', 'HEAD']) |
630 | 632 |
631 def runhooks(self, options, args, file_list): | 633 def runhooks(self, options, args, file_list): |
632 self.status(options, args, file_list) | 634 self.status(options, args, file_list) |
633 | 635 |
634 def status(self, options, _args, file_list): | 636 def status(self, options, _args, file_list): |
635 """Display status information.""" | 637 """Display status information.""" |
636 if not os.path.isdir(self.checkout_path): | 638 if not os.path.isdir(self.checkout_path): |
637 print(('\n________ couldn\'t run status in %s:\n' | 639 print(('\n________ couldn\'t run status in %s:\n' |
638 'The directory does not exist.') % self.checkout_path) | 640 'The directory does not exist.') % self.checkout_path) |
639 else: | 641 else: |
640 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) | 642 merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) |
641 self._Run(['diff', '--name-status', merge_base], options) | 643 self._Run(['diff', '--name-status', merge_base], options) |
642 if file_list is not None: | 644 if file_list is not None: |
643 files = self._Capture(['diff', '--name-only', merge_base]).split() | 645 files = self._Capture(['diff', '--name-only', merge_base]).split() |
644 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 646 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
645 | 647 |
646 def GetUsableRev(self, rev, options): | 648 def GetUsableRev(self, rev, options): |
647 """Finds a useful revision for this repository. | 649 """Finds a useful revision for this repository. |
648 | 650 |
649 If SCM is git-svn and the head revision is less than |rev|, git svn fetch | 651 If SCM is git-svn and the head revision is less than |rev|, git svn fetch |
650 will be called on the source.""" | 652 will be called on the source.""" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 ( 'It appears that either your git-svn remote is incorrectly\n' | 690 ( 'It appears that either your git-svn remote is incorrectly\n' |
689 'configured or the revision in your safesync_url is\n' | 691 'configured or the revision in your safesync_url is\n' |
690 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n' | 692 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n' |
691 'corresponding git hash for SVN rev %s.' ) % rev) | 693 'corresponding git hash for SVN rev %s.' ) % rev) |
692 else: | 694 else: |
693 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): | 695 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): |
694 sha1 = rev | 696 sha1 = rev |
695 else: | 697 else: |
696 # May exist in origin, but we don't have it yet, so fetch and look | 698 # May exist in origin, but we don't have it yet, so fetch and look |
697 # again. | 699 # again. |
698 scm.GIT.Capture(['fetch', 'origin'], cwd=self.checkout_path) | 700 scm.GIT.Capture(['fetch', self.remote], cwd=self.checkout_path) |
699 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): | 701 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): |
700 sha1 = rev | 702 sha1 = rev |
701 | 703 |
702 if not sha1: | 704 if not sha1: |
703 raise gclient_utils.Error( | 705 raise gclient_utils.Error( |
704 ( 'We could not find a valid hash for safesync_url response "%s".\n' | 706 ( 'We could not find a valid hash for safesync_url response "%s".\n' |
705 'Safesync URLs with a git checkout currently require a git-svn\n' | 707 'Safesync URLs with a git checkout currently require a git-svn\n' |
706 'remote or a safesync_url that provides git sha1s. Please add a\n' | 708 'remote or a safesync_url that provides git sha1s. Please add a\n' |
707 'git-svn remote or change your safesync_url. For more info, see:\n' | 709 'git-svn remote or change your safesync_url. For more info, see:\n' |
708 'http://code.google.com/p/chromium/wiki/UsingNewGit' | 710 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 if use_reference: | 802 if use_reference: |
801 cmd += ['--reference', os.path.abspath(self.checkout_path)] | 803 cmd += ['--reference', os.path.abspath(self.checkout_path)] |
802 | 804 |
803 self._Run(cmd + [url, folder], | 805 self._Run(cmd + [url, folder], |
804 options, filter_fn=filter_fn, cwd=self.cache_dir, retry=True) | 806 options, filter_fn=filter_fn, cwd=self.cache_dir, retry=True) |
805 else: | 807 else: |
806 # For now, assert that host/path/to/repo.git is identical. We may want | 808 # For now, assert that host/path/to/repo.git is identical. We may want |
807 # to relax this restriction in the future to allow for smarter cache | 809 # to relax this restriction in the future to allow for smarter cache |
808 # repo update schemes (such as pulling the same repo, but from a | 810 # repo update schemes (such as pulling the same repo, but from a |
809 # different host). | 811 # different host). |
810 existing_url = self._Capture(['config', 'remote.origin.url'], | 812 existing_url = self._Capture(['config', 'remote.%s.url' % self.remote], |
811 cwd=folder) | 813 cwd=folder) |
812 assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url) | 814 assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url) |
813 | 815 |
814 if use_reference: | 816 if use_reference: |
815 with open(altfile, 'w') as f: | 817 with open(altfile, 'w') as f: |
816 f.write(os.path.abspath(checkout_objects)) | 818 f.write(os.path.abspath(checkout_objects)) |
817 | 819 |
818 # Would normally use `git remote update`, but it doesn't support | 820 # Would normally use `git remote update`, but it doesn't support |
819 # --progress, so use fetch instead. | 821 # --progress, so use fetch instead. |
820 self._Run(['fetch'] + v + ['--multiple', '--progress', '--all'], | 822 self._Run(['fetch'] + v + ['--multiple', '--progress', '--all'], |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 gclient_utils.rmtree(tmp_dir) | 869 gclient_utils.rmtree(tmp_dir) |
868 if revision.startswith('refs/heads/'): | 870 if revision.startswith('refs/heads/'): |
869 self._Run( | 871 self._Run( |
870 ['checkout', '--quiet', revision.replace('refs/heads/', '')], options) | 872 ['checkout', '--quiet', revision.replace('refs/heads/', '')], options) |
871 else: | 873 else: |
872 # Squelch git's very verbose detached HEAD warning and use our own | 874 # Squelch git's very verbose detached HEAD warning and use our own |
873 self._Run(['checkout', '--quiet', revision], options) | 875 self._Run(['checkout', '--quiet', revision], options) |
874 print( | 876 print( |
875 ('Checked out %s to a detached HEAD. Before making any commits\n' | 877 ('Checked out %s to a detached HEAD. Before making any commits\n' |
876 'in this repo, you should use \'git checkout <branch>\' to switch to\n' | 878 'in this repo, you should use \'git checkout <branch>\' to switch to\n' |
877 'an existing branch or use \'git checkout origin -b <branch>\' to\n' | 879 'an existing branch or use \'git checkout %s -b <branch>\' to\n' |
878 'create a new branch for your work.') % revision) | 880 'create a new branch for your work.') % (revision, self.remote)) |
879 | 881 |
880 def _AttemptRebase(self, upstream, files, options, newbase=None, | 882 def _AttemptRebase(self, upstream, files, options, newbase=None, |
881 branch=None, printed_path=False): | 883 branch=None, printed_path=False): |
882 """Attempt to rebase onto either upstream or, if specified, newbase.""" | 884 """Attempt to rebase onto either upstream or, if specified, newbase.""" |
883 if files is not None: | 885 if files is not None: |
884 files.extend(self._Capture(['diff', upstream, '--name-only']).split()) | 886 files.extend(self._Capture(['diff', upstream, '--name-only']).split()) |
885 revision = upstream | 887 revision = upstream |
886 if newbase: | 888 if newbase: |
887 revision = newbase | 889 revision = newbase |
888 if not printed_path: | 890 if not printed_path: |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 | 1019 |
1018 def _Capture(self, args, cwd=None): | 1020 def _Capture(self, args, cwd=None): |
1019 return subprocess2.check_output( | 1021 return subprocess2.check_output( |
1020 ['git'] + args, | 1022 ['git'] + args, |
1021 stderr=subprocess2.VOID, | 1023 stderr=subprocess2.VOID, |
1022 cwd=cwd or self.checkout_path).strip() | 1024 cwd=cwd or self.checkout_path).strip() |
1023 | 1025 |
1024 def _UpdateBranchHeads(self, options, fetch=False): | 1026 def _UpdateBranchHeads(self, options, fetch=False): |
1025 """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" | 1027 """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" |
1026 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: | 1028 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: |
1027 config_cmd = ['config', 'remote.origin.fetch', | 1029 config_cmd = ['config', 'remote.%s.fetch' % self.remote, |
1028 '+refs/branch-heads/*:refs/remotes/branch-heads/*', | 1030 '+refs/branch-heads/*:refs/remotes/branch-heads/*', |
1029 '^\\+refs/branch-heads/\\*:.*$'] | 1031 '^\\+refs/branch-heads/\\*:.*$'] |
1030 self._Run(config_cmd, options) | 1032 self._Run(config_cmd, options) |
1031 if fetch: | 1033 if fetch: |
1032 fetch_cmd = ['-c', 'core.deltaBaseCacheLimit=2g', 'fetch', 'origin'] | 1034 fetch_cmd = ['-c', 'core.deltaBaseCacheLimit=2g', 'fetch', self.remote] |
1033 if options.verbose: | 1035 if options.verbose: |
1034 fetch_cmd.append('--verbose') | 1036 fetch_cmd.append('--verbose') |
1035 self._Run(fetch_cmd, options, retry=True) | 1037 self._Run(fetch_cmd, options, retry=True) |
1036 | 1038 |
1037 def _Run(self, args, options, **kwargs): | 1039 def _Run(self, args, options, **kwargs): |
1038 kwargs.setdefault('cwd', self.checkout_path) | 1040 kwargs.setdefault('cwd', self.checkout_path) |
1039 git_filter = not options.verbose | 1041 git_filter = not options.verbose |
1040 if git_filter: | 1042 if git_filter: |
1041 kwargs['filter_fn'] = GitFilter(kwargs.get('filter_fn')) | 1043 kwargs['filter_fn'] = GitFilter(kwargs.get('filter_fn')) |
1042 kwargs.setdefault('print_stdout', False) | 1044 kwargs.setdefault('print_stdout', False) |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 new_command.append('--force') | 1452 new_command.append('--force') |
1451 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1453 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1452 new_command.extend(('--accept', 'theirs-conflict')) | 1454 new_command.extend(('--accept', 'theirs-conflict')) |
1453 elif options.manually_grab_svn_rev: | 1455 elif options.manually_grab_svn_rev: |
1454 new_command.append('--force') | 1456 new_command.append('--force') |
1455 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1457 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1456 new_command.extend(('--accept', 'postpone')) | 1458 new_command.extend(('--accept', 'postpone')) |
1457 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1459 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1458 new_command.extend(('--accept', 'postpone')) | 1460 new_command.extend(('--accept', 'postpone')) |
1459 return new_command | 1461 return new_command |
OLD | NEW |