blob: 3be9312ec30fb639b46769a8baefb18c15985456 [file] [log] [blame]
Kuang-che Wue41e0062017-09-01 19:04:14 +08001#!/usr/bin/env python2
2# Copyright 2017 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5r"""Switcher for git bisecting.
6
7Typical usage:
8 $ bisect_git.py config switch ./switch_git.py
9
10This is actually equivalent to
11 $ bisect_git.py config switch \
12 sh -c 'cd $GIT_REPO && git checkout -q -f $GIT_REV'
13(Note, use single quotes instead of double quotes because the variables need to
14be expanded at switch time, not now.)
15"""
16from __future__ import print_function
17import argparse
18import logging
19
20from bisect_kit import cli
21from bisect_kit import common
22from bisect_kit import git_util
23from bisect_kit import util
24
25logger = logging.getLogger(__name__)
26
27
28def create_argument_parser():
29 defaults = util.DefaultConfig()
30 parser = argparse.ArgumentParser()
31 common.add_logging_arguments(parser, defaults)
32 parser.add_argument(
33 'git_rev',
34 nargs='?',
35 type=git_util.argtype_git_rev,
36 metavar='GIT_REV',
37 default=defaults.get('GIT_REV', ''),
38 help='Git revision id')
39 parser.add_argument(
40 '--git_repo',
41 type=cli.argtype_dir_path,
42 metavar='GIT_REPO',
43 default=defaults.get('GIT_REPO'),
44 help='Git repository path')
45
46 return parser
47
48
49def main(args=None):
50 parser = create_argument_parser()
51 opts = parser.parse_args(args)
52 common.config_logging(opts)
53
54 git_util.checkout_version(opts.git_repo, opts.git_rev)
55
56
57if __name__ == '__main__':
58 main()