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

Side by Side Diff: git_cl.py

Issue 9836013: Choosing a default remote for determining base_url. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 8 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 import logging 10 import logging
(...skipping 30 matching lines...) Expand all
41 import presubmit_support 41 import presubmit_support
42 import rietveld 42 import rietveld
43 import scm 43 import scm
44 import subprocess2 44 import subprocess2
45 import watchlists 45 import watchlists
46 46
47 47
48 DEFAULT_SERVER = 'https://codereview.appspot.com' 48 DEFAULT_SERVER = 'https://codereview.appspot.com'
49 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' 49 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s'
50 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' 50 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup'
51 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit'
51 52
52 53
53 # Initialized in main() 54 # Initialized in main()
54 settings = None 55 settings = None
55 56
56 57
57 def DieWithError(message): 58 def DieWithError(message):
58 print >> sys.stderr, message 59 print >> sys.stderr, message
59 sys.exit(1) 60 sys.exit(1)
60 61
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 self.upstream_branch = None 302 self.upstream_branch = None
302 self.has_issue = False 303 self.has_issue = False
303 self.issue = None 304 self.issue = None
304 self.has_description = False 305 self.has_description = False
305 self.description = None 306 self.description = None
306 self.has_patchset = False 307 self.has_patchset = False
307 self.patchset = None 308 self.patchset = None
308 self._rpc_server = None 309 self._rpc_server = None
309 self.cc = None 310 self.cc = None
310 self.watchers = () 311 self.watchers = ()
312 self._remote = None
311 313
312 def GetCCList(self): 314 def GetCCList(self):
313 """Return the users cc'd on this CL. 315 """Return the users cc'd on this CL.
314 316
315 Return is a string suitable for passing to gcl with the --cc flag. 317 Return is a string suitable for passing to gcl with the --cc flag.
316 """ 318 """
317 if self.cc is None: 319 if self.cc is None:
318 base_cc = settings .GetDefaultCCList() 320 base_cc = settings .GetDefaultCCList()
319 more_cc = ','.join(self.watchers) 321 more_cc = ','.join(self.watchers)
320 self.cc = ','.join(filter(None, (base_cc, more_cc))) or '' 322 self.cc = ','.join(filter(None, (base_cc, more_cc))) or ''
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 return remote, upstream_branch 381 return remote, upstream_branch
380 382
381 def GetUpstreamBranch(self): 383 def GetUpstreamBranch(self):
382 if self.upstream_branch is None: 384 if self.upstream_branch is None:
383 remote, upstream_branch = self.FetchUpstreamTuple() 385 remote, upstream_branch = self.FetchUpstreamTuple()
384 if remote is not '.': 386 if remote is not '.':
385 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) 387 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote)
386 self.upstream_branch = upstream_branch 388 self.upstream_branch = upstream_branch
387 return self.upstream_branch 389 return self.upstream_branch
388 390
391 def GetRemote(self):
392 if not self._remote:
393 self._remote = self.FetchUpstreamTuple()[0]
394 if self._remote == '.':
395 def warn_default():
396 logging.warning('Could not determine which remote this change is '
397 'associated with, so defaulting to "%s". This may '
398 'not be what you want. You may prevent this message '
399 'by running "git svn info" as documented here: %s',
400 self._remote,
401 GIT_INSTRUCTIONS_URL)
402
403 remotes = RunGit(['remote'], error_ok=True).split()
404 if len(remotes) == 1:
405 self._remote, = remotes
406 warn_default()
M-A Ruel 2012/03/22 19:39:00 Actually, I'd prefer to not warn here. It's fine a
jmbaker1 2012/03/22 19:56:58 Done.
407 elif 'origin' in remotes:
408 self._remote = 'origin'
409 warn_default()
410 else:
411 logging.warn('Could not determine which remote this change is '
412 'associated with. You may prevent this message by '
413 'running "git svn info" as documented here: %s',
414 GIT_INSTRUCTIONS_URL)
415 return self._remote
416
417
389 def GetRemoteUrl(self): 418 def GetRemoteUrl(self):
390 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. 419 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'.
391 420
392 Returns None if there is no remote. 421 Returns None if there is no remote.
393 """ 422 """
394 remote = self.FetchUpstreamTuple()[0] 423 remote = self.GetRemote()
395 if remote == '.':
396 return None
397 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() 424 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip()
398 425
399 def GetIssue(self): 426 def GetIssue(self):
400 if not self.has_issue: 427 if not self.has_issue:
401 issue = RunGit(['config', self._IssueSetting()], error_ok=True).strip() 428 issue = RunGit(['config', self._IssueSetting()], error_ok=True).strip()
402 if issue: 429 if issue:
403 self.issue = issue 430 self.issue = issue
404 else: 431 else:
405 self.issue = None 432 self.issue = None
406 self.has_issue = True 433 self.has_issue = True
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1522 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1496 1523
1497 # Not a known command. Default to help. 1524 # Not a known command. Default to help.
1498 GenUsage(parser, 'help') 1525 GenUsage(parser, 'help')
1499 return CMDhelp(parser, argv) 1526 return CMDhelp(parser, argv)
1500 1527
1501 1528
1502 if __name__ == '__main__': 1529 if __name__ == '__main__':
1503 fix_encoding.fix_encoding() 1530 fix_encoding.fix_encoding()
1504 sys.exit(main(sys.argv[1:])) 1531 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698