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

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
396 remotes = RunGit(['remote'], error_ok=True).split()
397 if len(remotes) == 1:
398 self._remote, = remotes
399 elif 'origin' in remotes:
400 self._remote = 'origin'
401 logging.warning('Could not determine which remote this change is '
402 'associated with, so defaulting to "%s". This may '
403 'not be what you want. You may prevent this message '
404 'by running "git svn info" as documented here: %s',
405 self._remote,
406 GIT_INSTRUCTIONS_URL)
407 else:
408 logging.warn('Could not determine which remote this change is '
409 'associated with. You may prevent this message by '
410 'running "git svn info" as documented here: %s',
411 GIT_INSTRUCTIONS_URL)
412 return self._remote
413
414
389 def GetRemoteUrl(self): 415 def GetRemoteUrl(self):
390 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. 416 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'.
391 417
392 Returns None if there is no remote. 418 Returns None if there is no remote.
393 """ 419 """
394 remote = self.FetchUpstreamTuple()[0] 420 remote = self.GetRemote()
395 if remote == '.':
396 return None
397 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() 421 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip()
398 422
399 def GetIssue(self): 423 def GetIssue(self):
400 if not self.has_issue: 424 if not self.has_issue:
401 issue = RunGit(['config', self._IssueSetting()], error_ok=True).strip() 425 issue = RunGit(['config', self._IssueSetting()], error_ok=True).strip()
402 if issue: 426 if issue:
403 self.issue = issue 427 self.issue = issue
404 else: 428 else:
405 self.issue = None 429 self.issue = None
406 self.has_issue = True 430 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))) 1519 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1496 1520
1497 # Not a known command. Default to help. 1521 # Not a known command. Default to help.
1498 GenUsage(parser, 'help') 1522 GenUsage(parser, 'help')
1499 return CMDhelp(parser, argv) 1523 return CMDhelp(parser, argv)
1500 1524
1501 1525
1502 if __name__ == '__main__': 1526 if __name__ == '__main__':
1503 fix_encoding.fix_encoding() 1527 fix_encoding.fix_encoding()
1504 sys.exit(main(sys.argv[1:])) 1528 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