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 logging | 7 import logging |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 The patch file is generated from a diff of the merge base of HEAD and | 188 The patch file is generated from a diff of the merge base of HEAD and |
189 its upstream branch. | 189 its upstream branch. |
190 """ | 190 """ |
191 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) | 191 merge_base = self._Capture(['merge-base', 'HEAD', 'origin']) |
192 gclient_utils.CheckCallAndFilter( | 192 gclient_utils.CheckCallAndFilter( |
193 ['git', 'diff', merge_base], | 193 ['git', 'diff', merge_base], |
194 cwd=self.checkout_path, | 194 cwd=self.checkout_path, |
195 filter_fn=GitDiffFilterer(self.relpath).Filter) | 195 filter_fn=GitDiffFilterer(self.relpath).Filter) |
196 | 196 |
| 197 def UpdateSubmoduleConfig(self): |
| 198 submod_cmd = ['git', 'config', '-f', '$toplevel/.git/config', |
| 199 'submodule.$name.ignore', '||', |
| 200 'git', 'config', '-f', '$toplevel/.git/config', |
| 201 'submodule.$name.ignore', 'dirty'] |
| 202 cmd = ['git', 'submodule', '--quiet', 'foreach', ' '.join(submod_cmd)] |
| 203 try: |
| 204 gclient_utils.CheckCallAndFilter( |
| 205 cmd, cwd=self.checkout_path, print_stdout=False, |
| 206 filter_fn=lambda x: None) |
| 207 except subprocess2.CalledProcessError: |
| 208 # Not a fatal error, or even very interesting in a non-git-submodule |
| 209 # world. So just keep it quiet. |
| 210 pass |
| 211 |
197 def update(self, options, args, file_list): | 212 def update(self, options, args, file_list): |
198 """Runs git to update or transparently checkout the working copy. | 213 """Runs git to update or transparently checkout the working copy. |
199 | 214 |
200 All updated files will be appended to file_list. | 215 All updated files will be appended to file_list. |
201 | 216 |
202 Raises: | 217 Raises: |
203 Error: if can't get URL for relative path. | 218 Error: if can't get URL for relative path. |
204 """ | 219 """ |
205 if args: | 220 if args: |
206 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) | 221 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 rev_type = "branch" | 262 rev_type = "branch" |
248 else: | 263 else: |
249 # hash is also a tag, only make a distinction at checkout | 264 # hash is also a tag, only make a distinction at checkout |
250 rev_type = "hash" | 265 rev_type = "hash" |
251 | 266 |
252 if not os.path.exists(self.checkout_path) or ( | 267 if not os.path.exists(self.checkout_path) or ( |
253 os.path.isdir(self.checkout_path) and | 268 os.path.isdir(self.checkout_path) and |
254 not os.listdir(self.checkout_path)): | 269 not os.listdir(self.checkout_path)): |
255 gclient_utils.safe_makedirs(os.path.dirname(self.checkout_path)) | 270 gclient_utils.safe_makedirs(os.path.dirname(self.checkout_path)) |
256 self._Clone(revision, url, options) | 271 self._Clone(revision, url, options) |
| 272 self.UpdateSubmoduleConfig() |
257 files = self._Capture(['ls-files']).splitlines() | 273 files = self._Capture(['ls-files']).splitlines() |
258 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 274 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
259 if not verbose: | 275 if not verbose: |
260 # Make the output a little prettier. It's nice to have some whitespace | 276 # Make the output a little prettier. It's nice to have some whitespace |
261 # between projects when cloning. | 277 # between projects when cloning. |
262 print('') | 278 print('') |
263 return | 279 return |
264 | 280 |
265 if not managed: | 281 if not managed: |
266 print ('________ unmanaged solution; skipping %s' % self.relpath) | 282 print ('________ unmanaged solution; skipping %s' % self.relpath) |
(...skipping 16 matching lines...) Expand all Loading... |
283 print('_____ switching %s to a new upstream' % self.relpath) | 299 print('_____ switching %s to a new upstream' % self.relpath) |
284 # Make sure it's clean | 300 # Make sure it's clean |
285 self._CheckClean(rev_str) | 301 self._CheckClean(rev_str) |
286 # Switch over to the new upstream | 302 # Switch over to the new upstream |
287 self._Run(['remote', 'set-url', 'origin', url], options) | 303 self._Run(['remote', 'set-url', 'origin', url], options) |
288 quiet = [] | 304 quiet = [] |
289 if not options.verbose: | 305 if not options.verbose: |
290 quiet = ['--quiet'] | 306 quiet = ['--quiet'] |
291 self._Run(['fetch', 'origin', '--prune'] + quiet, options) | 307 self._Run(['fetch', 'origin', '--prune'] + quiet, options) |
292 self._Run(['reset', '--hard', 'origin/master'] + quiet, options) | 308 self._Run(['reset', '--hard', 'origin/master'] + quiet, options) |
| 309 self.UpdateSubmoduleConfig() |
293 files = self._Capture(['ls-files']).splitlines() | 310 files = self._Capture(['ls-files']).splitlines() |
294 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 311 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
295 return | 312 return |
296 | 313 |
297 cur_branch = self._GetCurrentBranch() | 314 cur_branch = self._GetCurrentBranch() |
298 | 315 |
299 # Cases: | 316 # Cases: |
300 # 0) HEAD is detached. Probably from our initial clone. | 317 # 0) HEAD is detached. Probably from our initial clone. |
301 # - make sure HEAD is contained by a named ref, then update. | 318 # - make sure HEAD is contained by a named ref, then update. |
302 # Cases 1-4. HEAD is a branch. | 319 # Cases 1-4. HEAD is a branch. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if not re.match('Already up-to-date.', merge_output) or verbose: | 471 if not re.match('Already up-to-date.', merge_output) or verbose: |
455 if not printed_path: | 472 if not printed_path: |
456 print('\n_____ %s%s' % (self.relpath, rev_str)) | 473 print('\n_____ %s%s' % (self.relpath, rev_str)) |
457 printed_path = True | 474 printed_path = True |
458 print(merge_output.strip()) | 475 print(merge_output.strip()) |
459 if not verbose: | 476 if not verbose: |
460 # Make the output a little prettier. It's nice to have some | 477 # Make the output a little prettier. It's nice to have some |
461 # whitespace between projects when syncing. | 478 # whitespace between projects when syncing. |
462 print('') | 479 print('') |
463 | 480 |
| 481 self.UpdateSubmoduleConfig() |
464 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 482 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
465 | 483 |
466 # If the rebase generated a conflict, abort and ask user to fix | 484 # If the rebase generated a conflict, abort and ask user to fix |
467 if self._IsRebasing(): | 485 if self._IsRebasing(): |
468 raise gclient_utils.Error('\n____ %s%s\n' | 486 raise gclient_utils.Error('\n____ %s%s\n' |
469 '\nConflict while rebasing this branch.\n' | 487 '\nConflict while rebasing this branch.\n' |
470 'Fix the conflict and run gclient again.\n' | 488 'Fix the conflict and run gclient again.\n' |
471 'See man git-rebase for details.\n' | 489 'See man git-rebase for details.\n' |
472 % (self.relpath, rev_str)) | 490 % (self.relpath, rev_str)) |
473 | 491 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 new_command.append('--force') | 1188 new_command.append('--force') |
1171 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1189 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1172 new_command.extend(('--accept', 'theirs-conflict')) | 1190 new_command.extend(('--accept', 'theirs-conflict')) |
1173 elif options.manually_grab_svn_rev: | 1191 elif options.manually_grab_svn_rev: |
1174 new_command.append('--force') | 1192 new_command.append('--force') |
1175 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1193 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1176 new_command.extend(('--accept', 'postpone')) | 1194 new_command.extend(('--accept', 'postpone')) |
1177 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1195 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1178 new_command.extend(('--accept', 'postpone')) | 1196 new_command.extend(('--accept', 'postpone')) |
1179 return new_command | 1197 return new_command |
OLD | NEW |