blob: f8f449b2cd0922ee571fe8a97b27aff661773f9a [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
24from bisect_kit import util
25
26logger = logging.getLogger(__name__)
27
28
29def create_argument_parser():
Kuang-che Wue41e0062017-09-01 19:04:14 +080030 parser = argparse.ArgumentParser()
Kuang-che Wu385279d2017-09-27 14:48:28 +080031 common.add_common_arguments(parser)
Kuang-che Wue41e0062017-09-01 19:04:14 +080032 parser.add_argument(
33 'git_rev',
34 nargs='?',
35 type=git_util.argtype_git_rev,
36 metavar='GIT_REV',
Kuang-che Wu385279d2017-09-27 14:48:28 +080037 default=configure.get('GIT_REV', ''),
Kuang-che Wue41e0062017-09-01 19:04:14 +080038 help='Git revision id')
39 parser.add_argument(
40 '--git_repo',
41 type=cli.argtype_dir_path,
42 metavar='GIT_REPO',
Kuang-che Wu385279d2017-09-27 14:48:28 +080043 default=configure.get('GIT_REPO'),
Kuang-che Wue41e0062017-09-01 19:04:14 +080044 help='Git repository path')
45
46 return parser
47
48
49def main(args=None):
Kuang-che Wu385279d2017-09-27 14:48:28 +080050 common.init()
Kuang-che Wue41e0062017-09-01 19:04:14 +080051 parser = create_argument_parser()
52 opts = parser.parse_args(args)
53 common.config_logging(opts)
54
55 git_util.checkout_version(opts.git_repo, opts.git_rev)
56
57
58if __name__ == '__main__':
59 main()