OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # git-cl -- a git-command for integrating reviews on Rietveld | 2 # git-cl -- a git-command for integrating reviews on Rietveld |
3 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 3 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
4 | 4 |
5 import getpass | 5 import getpass |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import re | 8 import re |
9 import readline | 9 import readline |
10 import subprocess | 10 import subprocess |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 self.branchref = branchref | 217 self.branchref = branchref |
218 if self.branchref: | 218 if self.branchref: |
219 self.branch = ShortBranchName(self.branchref) | 219 self.branch = ShortBranchName(self.branchref) |
220 else: | 220 else: |
221 self.branch = None | 221 self.branch = None |
222 self.upstream_branch = None | 222 self.upstream_branch = None |
223 self.has_issue = False | 223 self.has_issue = False |
224 self.issue = None | 224 self.issue = None |
225 self.has_description = False | 225 self.has_description = False |
226 self.description = None | 226 self.description = None |
| 227 self.has_patchset = False |
| 228 self.patchset = None |
227 | 229 |
228 def GetBranch(self): | 230 def GetBranch(self): |
229 """Returns the short branch name, e.g. 'master'.""" | 231 """Returns the short branch name, e.g. 'master'.""" |
230 if not self.branch: | 232 if not self.branch: |
231 self.branchref = RunGit(['symbolic-ref', 'HEAD']).strip() | 233 self.branchref = RunGit(['symbolic-ref', 'HEAD']).strip() |
232 self.branch = ShortBranchName(self.branchref) | 234 self.branch = ShortBranchName(self.branchref) |
233 return self.branch | 235 return self.branch |
234 def GetBranchRef(self): | 236 def GetBranchRef(self): |
235 """Returns the full branch name, e.g. 'refs/heads/master'.""" | 237 """Returns the full branch name, e.g. 'refs/heads/master'.""" |
236 self.GetBranch() # Poke the lazy loader. | 238 self.GetBranch() # Poke the lazy loader. |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 # Load Codereview settings and download hooks (if available). | 482 # Load Codereview settings and download hooks (if available). |
481 hooks = LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) | 483 hooks = LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) |
482 for key, filename in (('predcommit', PREDCOMMIT_HOOK), | 484 for key, filename in (('predcommit', PREDCOMMIT_HOOK), |
483 ('preupload', PREUPLOAD_HOOK)): | 485 ('preupload', PREUPLOAD_HOOK)): |
484 if key in hooks: | 486 if key in hooks: |
485 DownloadToFile(hooks[key], filename) | 487 DownloadToFile(hooks[key], filename) |
486 | 488 |
487 | 489 |
488 def CmdStatus(args): | 490 def CmdStatus(args): |
489 parser = optparse.OptionParser(usage='git cl status [options]') | 491 parser = optparse.OptionParser(usage='git cl status [options]') |
490 parser.add_option('--field', help='print only specific field (desc|id|url)') | 492 parser.add_option('--field', |
| 493 help='print only specific field (desc|id|patch|url)') |
491 (options, args) = parser.parse_args(args) | 494 (options, args) = parser.parse_args(args) |
492 | 495 |
493 # TODO: maybe make show_branches a flag if necessary. | 496 # TODO: maybe make show_branches a flag if necessary. |
494 show_branches = not options.field | 497 show_branches = not options.field |
495 | 498 |
496 if show_branches: | 499 if show_branches: |
497 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) | 500 branches = RunGit(['for-each-ref', '--format=%(refname)', 'refs/heads']) |
498 if branches: | 501 if branches: |
499 print 'Branches associated with reviews:' | 502 print 'Branches associated with reviews:' |
500 for branch in sorted(branches.splitlines()): | 503 for branch in sorted(branches.splitlines()): |
501 cl = Changelist(branchref=branch) | 504 cl = Changelist(branchref=branch) |
502 print " %10s: %s" % (cl.GetBranch(), cl.GetIssue()) | 505 print " %10s: %s" % (cl.GetBranch(), cl.GetIssue()) |
503 | 506 |
504 cl = Changelist() | 507 cl = Changelist() |
505 if options.field: | 508 if options.field: |
506 if options.field.startswith('desc'): | 509 if options.field.startswith('desc'): |
507 print cl.GetDescription() | 510 print cl.GetDescription() |
508 elif options.field == 'id': | 511 elif options.field == 'id': |
509 print cl.GetIssue() | 512 id = cl.GetIssue() |
| 513 if id: |
| 514 print id |
| 515 elif options.field == 'patch': |
| 516 patchset = cl.GetPatchset() |
| 517 if patchset: |
| 518 print patchset |
510 elif options.field == 'url': | 519 elif options.field == 'url': |
511 print cl.GetIssueURL() | 520 url = cl.GetIssueURL() |
| 521 if url: |
| 522 print url |
512 else: | 523 else: |
513 print | 524 print |
514 print 'Current branch:', | 525 print 'Current branch:', |
515 if not cl.GetIssue(): | 526 if not cl.GetIssue(): |
516 print 'no issue assigned.' | 527 print 'no issue assigned.' |
517 return 0 | 528 return 0 |
518 print cl.GetBranch() | 529 print cl.GetBranch() |
519 print 'Issue number:', cl.GetIssue(), '(%s)' % cl.GetIssueURL() | 530 print 'Issue number:', cl.GetIssue(), '(%s)' % cl.GetIssueURL() |
520 print 'Issue description:' | 531 print 'Issue description:' |
521 print cl.GetDescription(pretty=True) | 532 print cl.GetDescription(pretty=True) |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 command = argv[1] | 1000 command = argv[1] |
990 for name, _, func in COMMANDS: | 1001 for name, _, func in COMMANDS: |
991 if name == command: | 1002 if name == command: |
992 return func(argv[2:]) | 1003 return func(argv[2:]) |
993 print 'unknown command: %s' % command | 1004 print 'unknown command: %s' % command |
994 Usage(argv[0]) | 1005 Usage(argv[0]) |
995 | 1006 |
996 | 1007 |
997 if __name__ == '__main__': | 1008 if __name__ == '__main__': |
998 sys.exit(main(sys.argv)) | 1009 sys.exit(main(sys.argv)) |
OLD | NEW |