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 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 | |
847 tmp_dir = tempfile.mkdtemp( | 828 tmp_dir = tempfile.mkdtemp( |
848 prefix='_gclient_%s_' % os.path.basename(self.checkout_path), | 829 prefix='_gclient_%s_' % os.path.basename(self.checkout_path), |
849 dir=parent_dir) | 830 dir=parent_dir) |
850 try: | 831 try: |
851 clone_cmd.append(tmp_dir) | 832 clone_cmd.append(tmp_dir) |
852 self._Run(clone_cmd, options, cwd=self._root_dir, retry=True) | 833 self._Run(clone_cmd, options, cwd=self._root_dir, retry=True) |
853 gclient_utils.safe_makedirs(self.checkout_path) | 834 gclient_utils.safe_makedirs(self.checkout_path) |
854 gclient_utils.safe_rename(os.path.join(tmp_dir, '.git'), | 835 gclient_utils.safe_rename(os.path.join(tmp_dir, '.git'), |
855 os.path.join(self.checkout_path, '.git')) | 836 os.path.join(self.checkout_path, '.git')) |
856 except: | 837 except: |
857 traceback.print_exc(file=self.out_fh) | 838 traceback.print_exc(file=self.out_fh) |
858 raise | 839 raise |
859 finally: | 840 finally: |
860 if os.listdir(tmp_dir): | 841 if os.listdir(tmp_dir): |
861 self.Print('_____ removing non-empty tmp dir %s' % tmp_dir) | 842 self.Print('_____ removing non-empty tmp dir %s' % tmp_dir) |
862 gclient_utils.rmtree(tmp_dir) | 843 gclient_utils.rmtree(tmp_dir) |
863 if template_dir: | |
864 gclient_utils.rmtree(template_dir) | |
865 self._UpdateBranchHeads(options, fetch=True) | 844 self._UpdateBranchHeads(options, fetch=True) |
866 self._Checkout(options, revision.replace('refs/heads/', ''), quiet=True) | 845 self._Checkout(options, revision.replace('refs/heads/', ''), quiet=True) |
867 if self._GetCurrentBranch() is None: | 846 if self._GetCurrentBranch() is None: |
868 # Squelch git's very verbose detached HEAD warning and use our own | 847 # Squelch git's very verbose detached HEAD warning and use our own |
869 self.Print( | 848 self.Print( |
870 ('Checked out %s to a detached HEAD. Before making any commits\n' | 849 ('Checked out %s to a detached HEAD. Before making any commits\n' |
871 'in this repo, you should use \'git checkout <branch>\' to switch to\n' | 850 'in this repo, you should use \'git checkout <branch>\' to switch to\n' |
872 'an existing branch or use \'git checkout %s -b <branch>\' to\n' | 851 'an existing branch or use \'git checkout %s -b <branch>\' to\n' |
873 'create a new branch for your work.') % (revision, self.remote)) | 852 'create a new branch for your work.') % (revision, self.remote)) |
874 | 853 |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 new_command.append('--force') | 1539 new_command.append('--force') |
1561 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1540 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1562 new_command.extend(('--accept', 'theirs-conflict')) | 1541 new_command.extend(('--accept', 'theirs-conflict')) |
1563 elif options.manually_grab_svn_rev: | 1542 elif options.manually_grab_svn_rev: |
1564 new_command.append('--force') | 1543 new_command.append('--force') |
1565 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1544 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1566 new_command.extend(('--accept', 'postpone')) | 1545 new_command.extend(('--accept', 'postpone')) |
1567 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1546 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1568 new_command.extend(('--accept', 'postpone')) | 1547 new_command.extend(('--accept', 'postpone')) |
1569 return new_command | 1548 return new_command |
OLD | NEW |