()
| 4563 | |
| 4564 | |
| 4565 | def main(): |
| 4566 | if len(sys.argv[1:]) == 0: |
| 4567 | printUsage(commands.keys()) |
| 4568 | sys.exit(2) |
| 4569 | |
| 4570 | cmdName = sys.argv[1] |
| 4571 | try: |
| 4572 | klass = commands[cmdName] |
| 4573 | cmd = klass() |
| 4574 | except KeyError: |
| 4575 | print("unknown command %s" % cmdName) |
| 4576 | print("") |
| 4577 | printUsage(commands.keys()) |
| 4578 | sys.exit(2) |
| 4579 | |
| 4580 | options = cmd.options |
| 4581 | cmd.gitdir = os.environ.get("GIT_DIR", None) |
| 4582 | |
| 4583 | args = sys.argv[2:] |
| 4584 | |
| 4585 | options.append(optparse.make_option("--verbose", "-v", dest="verbose", action="store_true")) |
| 4586 | if cmd.needsGit: |
| 4587 | options.append(optparse.make_option("--git-dir", dest="gitdir")) |
| 4588 | |
| 4589 | parser = optparse.OptionParser(cmd.usage.replace("%prog", "%prog " + cmdName), |
| 4590 | options, |
| 4591 | description=cmd.description, |
| 4592 | formatter=HelpFormatter()) |
| 4593 | |
| 4594 | try: |
| 4595 | cmd, args = parser.parse_args(sys.argv[2:], cmd) |
| 4596 | except: |
| 4597 | parser.print_help() |
| 4598 | raise |
| 4599 | |
| 4600 | global verbose |
| 4601 | verbose = cmd.verbose |
| 4602 | if cmd.needsGit: |
| 4603 | if cmd.gitdir is None: |
| 4604 | cmd.gitdir = os.path.abspath(".git") |
| 4605 | if not isValidGitDir(cmd.gitdir): |
| 4606 | # "rev-parse --git-dir" without arguments will try $PWD/.git |
| 4607 | cmd.gitdir = read_pipe(["git", "rev-parse", "--git-dir"]).strip() |
| 4608 | if os.path.exists(cmd.gitdir): |
| 4609 | cdup = read_pipe(["git", "rev-parse", "--show-cdup"]).strip() |
| 4610 | if len(cdup) > 0: |
| 4611 | chdir(cdup) |
| 4612 | |
| 4613 | if not isValidGitDir(cmd.gitdir): |
| 4614 | if isValidGitDir(cmd.gitdir + "/.git"): |
| 4615 | cmd.gitdir += "/.git" |
| 4616 | else: |
| 4617 | die("fatal: cannot locate git repository at %s" % cmd.gitdir) |
| 4618 | |
| 4619 | # so git commands invoked from the P4 workspace will succeed |
| 4620 | os.environ["GIT_DIR"] = cmd.gitdir |
| 4621 | |
| 4622 | if not cmd.run(args): |
no test coverage detected