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 from __future__ import print_function | 7 from __future__ import print_function |
8 | 8 |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 | 267 |
268 The patch file is generated from a diff of the merge base of HEAD and | 268 The patch file is generated from a diff of the merge base of HEAD and |
269 its upstream branch. | 269 its upstream branch. |
270 """ | 270 """ |
271 merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) | 271 merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) |
272 gclient_utils.CheckCallAndFilter( | 272 gclient_utils.CheckCallAndFilter( |
273 ['git', 'diff', merge_base], | 273 ['git', 'diff', merge_base], |
274 cwd=self.checkout_path, | 274 cwd=self.checkout_path, |
275 filter_fn=GitDiffFilterer(self.relpath).Filter, print_func=self.Print) | 275 filter_fn=GitDiffFilterer(self.relpath).Filter, print_func=self.Print) |
276 | 276 |
277 def UpdateSubmoduleConfig(self): | |
278 submod_cmd = ['git', 'config', '-f', '$toplevel/.git/config', | |
279 'submodule.$name.ignore', 'all'] | |
280 cmd = ['git', 'submodule', '--quiet', 'foreach', ' '.join(submod_cmd)] | |
281 cmd2 = ['git', 'config', 'diff.ignoreSubmodules', 'all'] | |
282 cmd3 = ['git', 'config', 'branch.autosetupmerge'] | |
jochen (gone - plz use gerrit)
2014/10/20 10:48:25
autosetupmerge wasn't really related to submodules
| |
283 cmd4 = ['git', 'config', 'fetch.recurseSubmodules', 'false'] | |
284 kwargs = {'cwd': self.checkout_path, | |
285 'print_stdout': False, | |
286 'filter_fn': lambda x: None} | |
287 try: | |
288 gclient_utils.CheckCallAndFilter(cmd, **kwargs) | |
289 gclient_utils.CheckCallAndFilter(cmd2, **kwargs) | |
290 except subprocess2.CalledProcessError: | |
291 # Not a fatal error, or even very interesting in a non-git-submodule | |
292 # world. So just keep it quiet. | |
293 pass | |
294 try: | |
295 gclient_utils.CheckCallAndFilter(cmd3, **kwargs) | |
296 except subprocess2.CalledProcessError: | |
297 gclient_utils.CheckCallAndFilter(cmd3 + ['always'], **kwargs) | |
298 | |
299 gclient_utils.CheckCallAndFilter(cmd4, **kwargs) | |
300 | |
301 def _FetchAndReset(self, revision, file_list, options): | 277 def _FetchAndReset(self, revision, file_list, options): |
302 """Equivalent to git fetch; git reset.""" | 278 """Equivalent to git fetch; git reset.""" |
303 quiet = [] | 279 quiet = [] |
304 if not options.verbose: | 280 if not options.verbose: |
305 quiet = ['--quiet'] | 281 quiet = ['--quiet'] |
306 self._UpdateBranchHeads(options, fetch=False) | 282 self._UpdateBranchHeads(options, fetch=False) |
307 | 283 |
308 cfg = gclient_utils.DefaultIndexPackConfig(self.url) | 284 cfg = gclient_utils.DefaultIndexPackConfig(self.url) |
309 fetch_cmd = cfg + ['fetch', self.remote, '--prune'] | 285 fetch_cmd = cfg + ['fetch', self.remote, '--prune'] |
310 self._Run(fetch_cmd + quiet, options, retry=True) | 286 self._Run(fetch_cmd + quiet, options, retry=True) |
311 self._Run(['reset', '--hard', revision] + quiet, options) | 287 self._Run(['reset', '--hard', revision] + quiet, options) |
312 self.UpdateSubmoduleConfig() | |
313 if file_list is not None: | 288 if file_list is not None: |
314 files = self._Capture(['ls-files']).splitlines() | 289 files = self._Capture(['ls-files']).splitlines() |
315 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]) |
316 | 291 |
317 def update(self, options, args, file_list): | 292 def update(self, options, args, file_list): |
318 """Runs git to update or transparently checkout the working copy. | 293 """Runs git to update or transparently checkout the working copy. |
319 | 294 |
320 All updated files will be appended to file_list. | 295 All updated files will be appended to file_list. |
321 | 296 |
322 Raises: | 297 Raises: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 rev_type = "hash" | 348 rev_type = "hash" |
374 | 349 |
375 if (not os.path.exists(self.checkout_path) or | 350 if (not os.path.exists(self.checkout_path) or |
376 (os.path.isdir(self.checkout_path) and | 351 (os.path.isdir(self.checkout_path) and |
377 not os.path.exists(os.path.join(self.checkout_path, '.git')))): | 352 not os.path.exists(os.path.join(self.checkout_path, '.git')))): |
378 if (os.path.isdir(self.checkout_path) and | 353 if (os.path.isdir(self.checkout_path) and |
379 not os.path.exists(os.path.join(self.checkout_path, '.git'))): | 354 not os.path.exists(os.path.join(self.checkout_path, '.git'))): |
380 self._DeleteOrMove(options.force) | 355 self._DeleteOrMove(options.force) |
381 self._Clone(revision, url, options) | 356 self._Clone(revision, url, options) |
382 self._UpdateBranchHeads(options, fetch=True) | 357 self._UpdateBranchHeads(options, fetch=True) |
383 self.UpdateSubmoduleConfig() | |
384 if file_list is not None: | 358 if file_list is not None: |
385 files = self._Capture(['ls-files']).splitlines() | 359 files = self._Capture(['ls-files']).splitlines() |
386 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 360 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
387 if not verbose: | 361 if not verbose: |
388 # Make the output a little prettier. It's nice to have some whitespace | 362 # Make the output a little prettier. It's nice to have some whitespace |
389 # between projects when cloning. | 363 # between projects when cloning. |
390 self.Print('') | 364 self.Print('') |
391 return self._Capture(['rev-parse', '--verify', 'HEAD']) | 365 return self._Capture(['rev-parse', '--verify', 'HEAD']) |
392 | 366 |
393 if not managed: | 367 if not managed: |
394 self._UpdateBranchHeads(options, fetch=False) | 368 self._UpdateBranchHeads(options, fetch=False) |
395 self.UpdateSubmoduleConfig() | |
396 self.Print('________ unmanaged solution; skipping %s' % self.relpath) | 369 self.Print('________ unmanaged solution; skipping %s' % self.relpath) |
397 return self._Capture(['rev-parse', '--verify', 'HEAD']) | 370 return self._Capture(['rev-parse', '--verify', 'HEAD']) |
398 | 371 |
399 # See if the url has changed (the unittests use git://foo for the url, let | 372 # See if the url has changed (the unittests use git://foo for the url, let |
400 # that through). | 373 # that through). |
401 current_url = self._Capture(['config', 'remote.%s.url' % self.remote]) | 374 current_url = self._Capture(['config', 'remote.%s.url' % self.remote]) |
402 return_early = False | 375 return_early = False |
403 # TODO(maruel): Delete url != 'git://foo' since it's just to make the | 376 # TODO(maruel): Delete url != 'git://foo' since it's just to make the |
404 # unit test pass. (and update the comment above) | 377 # unit test pass. (and update the comment above) |
405 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. | 378 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 if not re.match('Already up-to-date.', merge_output) or verbose: | 554 if not re.match('Already up-to-date.', merge_output) or verbose: |
582 if not printed_path: | 555 if not printed_path: |
583 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) | 556 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) |
584 printed_path = True | 557 printed_path = True |
585 self.Print(merge_output.strip()) | 558 self.Print(merge_output.strip()) |
586 if not verbose: | 559 if not verbose: |
587 # Make the output a little prettier. It's nice to have some | 560 # Make the output a little prettier. It's nice to have some |
588 # whitespace between projects when syncing. | 561 # whitespace between projects when syncing. |
589 self.Print('') | 562 self.Print('') |
590 | 563 |
591 self.UpdateSubmoduleConfig() | |
592 if file_list is not None: | 564 if file_list is not None: |
593 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 565 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
594 | 566 |
595 # If the rebase generated a conflict, abort and ask user to fix | 567 # If the rebase generated a conflict, abort and ask user to fix |
596 if self._IsRebasing(): | 568 if self._IsRebasing(): |
597 raise gclient_utils.Error('\n____ %s%s\n' | 569 raise gclient_utils.Error('\n____ %s%s\n' |
598 '\nConflict while rebasing this branch.\n' | 570 '\nConflict while rebasing this branch.\n' |
599 'Fix the conflict and run gclient again.\n' | 571 'Fix the conflict and run gclient again.\n' |
600 'See man git-rebase for details.\n' | 572 'See man git-rebase for details.\n' |
601 % (self.relpath, rev_str)) | 573 % (self.relpath, rev_str)) |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 new_command.append('--force') | 1452 new_command.append('--force') |
1481 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1453 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1482 new_command.extend(('--accept', 'theirs-conflict')) | 1454 new_command.extend(('--accept', 'theirs-conflict')) |
1483 elif options.manually_grab_svn_rev: | 1455 elif options.manually_grab_svn_rev: |
1484 new_command.append('--force') | 1456 new_command.append('--force') |
1485 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1457 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1486 new_command.extend(('--accept', 'postpone')) | 1458 new_command.extend(('--accept', 'postpone')) |
1487 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1459 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1488 new_command.extend(('--accept', 'postpone')) | 1460 new_command.extend(('--accept', 'postpone')) |
1489 return new_command | 1461 return new_command |
OLD | NEW |