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

Side by Side Diff: git_cl.py

Issue 9969099: Allow overriding base-url in git-cl. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 8 years, 8 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 | tests/git_cl_test.py » ('j') | 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 'by running "git svn info" as documented here: %s', 404 'by running "git svn info" as documented here: %s',
405 self._remote, 405 self._remote,
406 GIT_INSTRUCTIONS_URL) 406 GIT_INSTRUCTIONS_URL)
407 else: 407 else:
408 logging.warn('Could not determine which remote this change is ' 408 logging.warn('Could not determine which remote this change is '
409 'associated with. You may prevent this message by ' 409 'associated with. You may prevent this message by '
410 'running "git svn info" as documented here: %s', 410 'running "git svn info" as documented here: %s',
411 GIT_INSTRUCTIONS_URL) 411 GIT_INSTRUCTIONS_URL)
412 return self._remote 412 return self._remote
413 413
414 def GetGitBaseUrlFromConfig(self):
415 """Return the configured base URL from branch.<branchname>.baseurl.
416
417 Returns None if it is not set.
418 """
419 return RunGit(['config', 'branch.%s.base-url' % self.GetBranch()],
420 error_ok=True).strip()
414 421
415 def GetRemoteUrl(self): 422 def GetRemoteUrl(self):
416 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. 423 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'.
417 424
418 Returns None if there is no remote. 425 Returns None if there is no remote.
419 """ 426 """
420 remote = self.GetRemote() 427 remote = self.GetRemote()
421 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() 428 return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip()
422 429
423 def GetIssue(self): 430 def GetIssue(self):
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 return 0 785 return 0
779 786
780 url = args[0] 787 url = args[0]
781 if not url.endswith('codereview.settings'): 788 if not url.endswith('codereview.settings'):
782 url = os.path.join(url, 'codereview.settings') 789 url = os.path.join(url, 'codereview.settings')
783 790
784 # Load code review settings and download hooks (if available). 791 # Load code review settings and download hooks (if available).
785 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) 792 LoadCodereviewSettingsFromFile(urllib2.urlopen(url))
786 DownloadHooks(True) 793 DownloadHooks(True)
787 return 0 794 return 0
788 795
M-A Ruel 2012/04/03 15:18:40 2 spaces between file level symbols
kalmard 2012/04/03 15:27:10 Done.
796 def CMDbaseurl(parser, args):
797 """get or set base-url for this branch"""
798 branchref = RunGit(['symbolic-ref', 'HEAD']).strip()
799 branch = ShortBranchName(branchref)
800 _, args = parser.parse_args(args)
801 if len(args) == 0:
M-A Ruel 2012/04/03 15:18:40 if not args:
kalmard 2012/04/03 15:27:10 Done.
802 print("Current base-url:")
803 return RunGit(['config', 'branch.%s.base-url' % branch],
804 error_ok=False).strip()
805 else:
806 print("Setting base-url to %s" % args[0])
807 return RunGit(['config', 'branch.%s.base-url' % branch, args[0]],
808 error_ok=False).strip()
789 809
M-A Ruel 2012/04/03 15:18:40 same
kalmard 2012/04/03 15:27:10 Done.
790 def CMDstatus(parser, args): 810 def CMDstatus(parser, args):
791 """show status of changelists""" 811 """show status of changelists"""
792 parser.add_option('--field', 812 parser.add_option('--field',
793 help='print only specific field (desc|id|patch|url)') 813 help='print only specific field (desc|id|patch|url)')
794 (options, args) = parser.parse_args(args) 814 (options, args) = parser.parse_args(args)
795 815
796 # TODO: maybe make show_branches a flag if necessary. 816 # TODO: maybe make show_branches a flag if necessary.
797 show_branches = not options.field 817 show_branches = not options.field
798 818
799 if show_branches: 819 if show_branches:
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 if options.send_mail: 995 if options.send_mail:
976 if not change_desc.reviewers: 996 if not change_desc.reviewers:
977 DieWithError("Must specify reviewers to send email.") 997 DieWithError("Must specify reviewers to send email.")
978 upload_args.append('--send_mail') 998 upload_args.append('--send_mail')
979 cc = ','.join(filter(None, (cl.GetCCList(), options.cc))) 999 cc = ','.join(filter(None, (cl.GetCCList(), options.cc)))
980 if cc: 1000 if cc:
981 upload_args.extend(['--cc', cc]) 1001 upload_args.extend(['--cc', cc])
982 1002
983 # Include the upstream repo's URL in the change -- this is useful for 1003 # Include the upstream repo's URL in the change -- this is useful for
984 # projects that have their source spread across multiple repos. 1004 # projects that have their source spread across multiple repos.
985 remote_url = None 1005 remote_url = cl.GetGitBaseUrlFromConfig()
986 if settings.GetIsGitSvn(): 1006 if not remote_url:
987 # URL is dependent on the current directory. 1007 if settings.GetIsGitSvn():
988 data = RunGit(['svn', 'info'], cwd=settings.GetRoot()) 1008 # URL is dependent on the current directory.
989 if data: 1009 data = RunGit(['svn', 'info'], cwd=settings.GetRoot())
990 keys = dict(line.split(': ', 1) for line in data.splitlines() 1010 if data:
991 if ': ' in line) 1011 keys = dict(line.split(': ', 1) for line in data.splitlines()
992 remote_url = keys.get('URL', None) 1012 if ': ' in line)
993 else: 1013 remote_url = keys.get('URL', None)
994 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): 1014 else:
995 remote_url = (cl.GetRemoteUrl() + '@' 1015 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch():
996 + cl.GetUpstreamBranch().split('/')[-1]) 1016 remote_url = (cl.GetRemoteUrl() + '@'
1017 + cl.GetUpstreamBranch().split('/')[-1])
997 if remote_url: 1018 if remote_url:
998 upload_args.extend(['--base_url', remote_url]) 1019 upload_args.extend(['--base_url', remote_url])
999 1020
1000 try: 1021 try:
1001 issue, patchset = upload.RealMain(['upload'] + upload_args + args) 1022 issue, patchset = upload.RealMain(['upload'] + upload_args + args)
1002 except KeyboardInterrupt: 1023 except KeyboardInterrupt:
1003 sys.exit(1) 1024 sys.exit(1)
1004 except: 1025 except:
1005 # If we got an exception after the user typed a description for their 1026 # If we got an exception after the user typed a description for their
1006 # change, back up the description before re-raising. 1027 # change, back up the description before re-raising.
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 1542 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
1522 1543
1523 # Not a known command. Default to help. 1544 # Not a known command. Default to help.
1524 GenUsage(parser, 'help') 1545 GenUsage(parser, 'help')
1525 return CMDhelp(parser, argv) 1546 return CMDhelp(parser, argv)
1526 1547
1527 1548
1528 if __name__ == '__main__': 1549 if __name__ == '__main__':
1529 fix_encoding.fix_encoding() 1550 fix_encoding.fix_encoding()
1530 sys.exit(main(sys.argv[1:])) 1551 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698