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 errno | 9 import errno |
10 import logging | 10 import logging |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 clone_cmd = cfg + ['clone', '--no-checkout', '--progress'] | 818 clone_cmd = cfg + ['clone', '--no-checkout', '--progress'] |
819 if self.cache_dir: | 819 if self.cache_dir: |
820 clone_cmd.append('--shared') | 820 clone_cmd.append('--shared') |
821 if options.verbose: | 821 if options.verbose: |
822 clone_cmd.append('--verbose') | 822 clone_cmd.append('--verbose') |
823 clone_cmd.append(url) | 823 clone_cmd.append(url) |
824 # If the parent directory does not exist, Git clone on Windows will not | 824 # If the parent directory does not exist, Git clone on Windows will not |
825 # create it, so we need to do it manually. | 825 # create it, so we need to do it manually. |
826 parent_dir = os.path.dirname(self.checkout_path) | 826 parent_dir = os.path.dirname(self.checkout_path) |
827 gclient_utils.safe_makedirs(parent_dir) | 827 gclient_utils.safe_makedirs(parent_dir) |
| 828 |
| 829 template_dir = None |
| 830 if hasattr(options, 'no_history') and options.no_history: |
| 831 if gclient_utils.IsGitSha(revision): |
| 832 # In the case of a subproject, the pinned sha is not necessarily the |
| 833 # head of the remote branch (so we can't just use --depth=N). Instead, |
| 834 # we tell git to fetch all the remote objects from SHA..HEAD by means of |
| 835 # a template git dir which has a 'shallow' file pointing to the sha. |
| 836 template_dir = tempfile.mkdtemp( |
| 837 prefix='_gclient_gittmp_%s' % os.path.basename(self.checkout_path), |
| 838 dir=parent_dir) |
| 839 self._Run(['init', '--bare', template_dir], options, cwd=self._root_dir) |
| 840 with open(os.path.join(template_dir, 'shallow'), 'w') as template_file: |
| 841 template_file.write(revision) |
| 842 clone_cmd.append('--template=' + template_dir) |
| 843 else: |
| 844 # Otherwise, we're just interested in the HEAD. Just use --depth. |
| 845 clone_cmd.append('--depth=1') |
| 846 |
828 tmp_dir = tempfile.mkdtemp( | 847 tmp_dir = tempfile.mkdtemp( |
829 prefix='_gclient_%s_' % os.path.basename(self.checkout_path), | 848 prefix='_gclient_%s_' % os.path.basename(self.checkout_path), |
830 dir=parent_dir) | 849 dir=parent_dir) |
831 try: | 850 try: |
832 clone_cmd.append(tmp_dir) | 851 clone_cmd.append(tmp_dir) |
833 self._Run(clone_cmd, options, cwd=self._root_dir, retry=True) | 852 self._Run(clone_cmd, options, cwd=self._root_dir, retry=True) |
834 gclient_utils.safe_makedirs(self.checkout_path) | 853 gclient_utils.safe_makedirs(self.checkout_path) |
835 gclient_utils.safe_rename(os.path.join(tmp_dir, '.git'), | 854 gclient_utils.safe_rename(os.path.join(tmp_dir, '.git'), |
836 os.path.join(self.checkout_path, '.git')) | 855 os.path.join(self.checkout_path, '.git')) |
837 except: | 856 except: |
838 traceback.print_exc(file=self.out_fh) | 857 traceback.print_exc(file=self.out_fh) |
839 raise | 858 raise |
840 finally: | 859 finally: |
841 if os.listdir(tmp_dir): | 860 if os.listdir(tmp_dir): |
842 self.Print('_____ removing non-empty tmp dir %s' % tmp_dir) | 861 self.Print('_____ removing non-empty tmp dir %s' % tmp_dir) |
843 gclient_utils.rmtree(tmp_dir) | 862 gclient_utils.rmtree(tmp_dir) |
| 863 if template_dir: |
| 864 gclient_utils.rmtree(template_dir) |
844 self._UpdateBranchHeads(options, fetch=True) | 865 self._UpdateBranchHeads(options, fetch=True) |
845 self._Checkout(options, revision.replace('refs/heads/', ''), quiet=True) | 866 self._Checkout(options, revision.replace('refs/heads/', ''), quiet=True) |
846 if self._GetCurrentBranch() is None: | 867 if self._GetCurrentBranch() is None: |
847 # Squelch git's very verbose detached HEAD warning and use our own | 868 # Squelch git's very verbose detached HEAD warning and use our own |
848 self.Print( | 869 self.Print( |
849 ('Checked out %s to a detached HEAD. Before making any commits\n' | 870 ('Checked out %s to a detached HEAD. Before making any commits\n' |
850 'in this repo, you should use \'git checkout <branch>\' to switch to\n' | 871 'in this repo, you should use \'git checkout <branch>\' to switch to\n' |
851 'an existing branch or use \'git checkout %s -b <branch>\' to\n' | 872 'an existing branch or use \'git checkout %s -b <branch>\' to\n' |
852 'create a new branch for your work.') % (revision, self.remote)) | 873 'create a new branch for your work.') % (revision, self.remote)) |
853 | 874 |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 new_command.append('--force') | 1560 new_command.append('--force') |
1540 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1561 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1541 new_command.extend(('--accept', 'theirs-conflict')) | 1562 new_command.extend(('--accept', 'theirs-conflict')) |
1542 elif options.manually_grab_svn_rev: | 1563 elif options.manually_grab_svn_rev: |
1543 new_command.append('--force') | 1564 new_command.append('--force') |
1544 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1565 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1545 new_command.extend(('--accept', 'postpone')) | 1566 new_command.extend(('--accept', 'postpone')) |
1546 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1567 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1547 new_command.extend(('--accept', 'postpone')) | 1568 new_command.extend(('--accept', 'postpone')) |
1548 return new_command | 1569 return new_command |
OLD | NEW |