blob: f76ea5d76b7675c24b4a41cb9ad65f93addaba07 [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
Kuang-che Wu385279d2017-09-27 14:48:28 +080022from bisect_kit import configure
Kuang-che Wue41e0062017-09-01 19:04:14 +080023from bisect_kit import git_util
Kuang-che Wue41e0062017-09-01 19:04:14 +080024
25logger = logging.getLogger(__name__)
26
27
28def create_argument_parser():
Kuang-che Wue41e0062017-09-01 19:04:14 +080029 parser = argparse.ArgumentParser()
Kuang-che Wu385279d2017-09-27 14:48:28 +080030 common.add_common_arguments(parser)
Kuang-che Wue41e0062017-09-01 19:04:14 +080031 parser.add_argument(
32 'git_rev',
33 nargs='?',
34 type=git_util.argtype_git_rev,
35 metavar='GIT_REV',
Kuang-che Wu385279d2017-09-27 14:48:28 +080036 default=configure.get('GIT_REV', ''),
Kuang-che Wue41e0062017-09-01 19:04:14 +080037 help='Git revision id')
38 parser.add_argument(
39 '--git_repo',
40 type=cli.argtype_dir_path,
41 metavar='GIT_REPO',
Kuang-che Wu385279d2017-09-27 14:48:28 +080042 default=configure.get('GIT_REPO'),
Kuang-che Wue41e0062017-09-01 19:04:14 +080043 help='Git repository path')
44
45 return parser
46
47
48def main(args=None):
Kuang-che Wu385279d2017-09-27 14:48:28 +080049 common.init()
Kuang-che Wue41e0062017-09-01 19:04:14 +080050 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()