Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: gclient_scm.py

Issue 61623008: If the destination directory doesn't contain the desired repo, delete it (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Address GetRemoteURL comments Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 result, version = scm.GIT.AssertVersion('1.7') 208 result, version = scm.GIT.AssertVersion('1.7')
209 if not result: 209 if not result:
210 raise gclient_utils.Error('Git version is older than 1.7: %s' % version) 210 raise gclient_utils.Error('Git version is older than 1.7: %s' % version)
211 return result 211 return result
212 except OSError: 212 except OSError:
213 return False 213 return False
214 214
215 def GetCheckoutRoot(self): 215 def GetCheckoutRoot(self):
216 return scm.GIT.GetCheckoutRoot(self.checkout_path) 216 return scm.GIT.GetCheckoutRoot(self.checkout_path)
217 217
218 def GetRemoteURL(self, options, cwd=None):
219 try:
220 return self._Capture(['config', 'remote.origin.url'],
221 cwd=cwd or self.checkout_path).rstrip()
222 except (OSError, subprocess2.CalledProcessError):
223 return None
224
218 def GetRevisionDate(self, _revision): 225 def GetRevisionDate(self, _revision):
219 """Returns the given revision's date in ISO-8601 format (which contains the 226 """Returns the given revision's date in ISO-8601 format (which contains the
220 time zone).""" 227 time zone)."""
221 # TODO(floitsch): get the time-stamp of the given revision and not just the 228 # TODO(floitsch): get the time-stamp of the given revision and not just the
222 # time-stamp of the currently checked out revision. 229 # time-stamp of the currently checked out revision.
223 return self._Capture(['log', '-n', '1', '--format=%ai']) 230 return self._Capture(['log', '-n', '1', '--format=%ai'])
224 231
225 @staticmethod 232 @staticmethod
226 def cleanup(options, args, file_list): 233 def cleanup(options, args, file_list):
227 """'Cleanup' the repo. 234 """'Cleanup' the repo.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 if not os.path.exists(os.path.join(self.checkout_path, '.git')): 375 if not os.path.exists(os.path.join(self.checkout_path, '.git')):
369 raise gclient_utils.Error('\n____ %s%s\n' 376 raise gclient_utils.Error('\n____ %s%s\n'
370 '\tPath is not a git repo. No .git dir.\n' 377 '\tPath is not a git repo. No .git dir.\n'
371 '\tTo resolve:\n' 378 '\tTo resolve:\n'
372 '\t\trm -rf %s\n' 379 '\t\trm -rf %s\n'
373 '\tAnd run gclient sync again\n' 380 '\tAnd run gclient sync again\n'
374 % (self.relpath, rev_str, self.relpath)) 381 % (self.relpath, rev_str, self.relpath))
375 382
376 # See if the url has changed (the unittests use git://foo for the url, let 383 # See if the url has changed (the unittests use git://foo for the url, let
377 # that through). 384 # that through).
378 current_url = self._Capture(['config', 'remote.origin.url']) 385 current_url = self.GetRemoteURL(options)
379 return_early = False 386 return_early = False
380 # TODO(maruel): Delete url != 'git://foo' since it's just to make the 387 # TODO(maruel): Delete url != 'git://foo' since it's just to make the
381 # unit test pass. (and update the comment above) 388 # unit test pass. (and update the comment above)
382 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. 389 # 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 390 # This allows devs to use experimental repos which have a different url
384 # but whose branch(s) are the same as official repos. 391 # but whose branch(s) are the same as official repos.
385 if (current_url != url and 392 if (current_url != url and
Isaac (away) 2013/12/04 03:29:19 I'm confused how your logic interacts with this se
borenet 2013/12/04 16:58:42 Ah yes, I can see how this is dangerous. I guess
borenet 2013/12/05 21:49:24 Per discussion on chat, removed this section.
386 url != 'git://foo' and 393 url != 'git://foo' and
387 subprocess2.capture( 394 subprocess2.capture(
388 ['git', 'config', 'remote.origin.gclient-auto-fix-url'], 395 ['git', 'config', 'remote.origin.gclient-auto-fix-url'],
389 cwd=self.checkout_path).strip() != 'False'): 396 cwd=self.checkout_path).strip() != 'False'):
390 print('_____ switching %s to a new upstream' % self.relpath) 397 print('_____ switching %s to a new upstream' % self.relpath)
391 # Make sure it's clean 398 # Make sure it's clean
392 self._CheckClean(rev_str) 399 self._CheckClean(rev_str)
393 # Switch over to the new upstream 400 # Switch over to the new upstream
394 self._Run(['remote', 'set-url', 'origin', url], options) 401 self._Run(['remote', 'set-url', 'origin', url], options)
395 self._FetchAndReset(revision, file_list, options) 402 self._FetchAndReset(revision, file_list, options)
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 if use_reference: 807 if use_reference:
801 cmd += ['--reference', os.path.abspath(self.checkout_path)] 808 cmd += ['--reference', os.path.abspath(self.checkout_path)]
802 809
803 self._Run(cmd + [url, folder], 810 self._Run(cmd + [url, folder],
804 options, filter_fn=filter_fn, cwd=self.cache_dir, retry=True) 811 options, filter_fn=filter_fn, cwd=self.cache_dir, retry=True)
805 else: 812 else:
806 # For now, assert that host/path/to/repo.git is identical. We may want 813 # 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 814 # 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 815 # repo update schemes (such as pulling the same repo, but from a
809 # different host). 816 # different host).
810 existing_url = self._Capture(['config', 'remote.origin.url'], 817 existing_url = self.GetRemoteURL(options, cwd=folder)
811 cwd=folder)
812 assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url) 818 assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url)
813 819
814 if use_reference: 820 if use_reference:
815 with open(altfile, 'w') as f: 821 with open(altfile, 'w') as f:
816 f.write(os.path.abspath(checkout_objects)) 822 f.write(os.path.abspath(checkout_objects))
817 823
818 # Would normally use `git remote update`, but it doesn't support 824 # Would normally use `git remote update`, but it doesn't support
819 # --progress, so use fetch instead. 825 # --progress, so use fetch instead.
820 self._Run(['fetch'] + v + ['--multiple', '--progress', '--all'], 826 self._Run(['fetch'] + v + ['--multiple', '--progress', '--all'],
821 options, filter_fn=filter_fn, cwd=folder, retry=True) 827 options, filter_fn=filter_fn, cwd=folder, retry=True)
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 result, version = scm.SVN.AssertVersion('1.4') 1076 result, version = scm.SVN.AssertVersion('1.4')
1071 if not result: 1077 if not result:
1072 raise gclient_utils.Error('SVN version is older than 1.4: %s' % version) 1078 raise gclient_utils.Error('SVN version is older than 1.4: %s' % version)
1073 return result 1079 return result
1074 except OSError: 1080 except OSError:
1075 return False 1081 return False
1076 1082
1077 def GetCheckoutRoot(self): 1083 def GetCheckoutRoot(self):
1078 return scm.SVN.GetCheckoutRoot(self.checkout_path) 1084 return scm.SVN.GetCheckoutRoot(self.checkout_path)
1079 1085
1086 def GetRemoteURL(self, options):
1087 try:
1088 local_info = scm.SVN.CaptureLocalInfo([os.curdir], self.checkout_path)
1089 except (OSError, subprocess2.CalledProcessError):
1090 return None
1091 return local_info.get('URL')
1092
1080 def GetRevisionDate(self, revision): 1093 def GetRevisionDate(self, revision):
1081 """Returns the given revision's date in ISO-8601 format (which contains the 1094 """Returns the given revision's date in ISO-8601 format (which contains the
1082 time zone).""" 1095 time zone)."""
1083 date = scm.SVN.Capture( 1096 date = scm.SVN.Capture(
1084 ['propget', '--revprop', 'svn:date', '-r', revision], 1097 ['propget', '--revprop', 'svn:date', '-r', revision],
1085 os.path.join(self.checkout_path, '.')) 1098 os.path.join(self.checkout_path, '.'))
1086 return date.strip() 1099 return date.strip()
1087 1100
1088 def cleanup(self, options, args, _file_list): 1101 def cleanup(self, options, args, _file_list):
1089 """Cleanup working copy.""" 1102 """Cleanup working copy."""
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 new_command.append('--force') 1463 new_command.append('--force')
1451 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1464 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1452 new_command.extend(('--accept', 'theirs-conflict')) 1465 new_command.extend(('--accept', 'theirs-conflict'))
1453 elif options.manually_grab_svn_rev: 1466 elif options.manually_grab_svn_rev:
1454 new_command.append('--force') 1467 new_command.append('--force')
1455 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1468 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1456 new_command.extend(('--accept', 'postpone')) 1469 new_command.extend(('--accept', 'postpone'))
1457 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1470 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1458 new_command.extend(('--accept', 'postpone')) 1471 new_command.extend(('--accept', 'postpone'))
1459 return new_command 1472 return new_command
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698