blob: 701033987c789441fdca8f1a953de66a0afc1013 [file] [log] [blame]
Kuang-che Wu875c89a2020-01-08 14:30:55 +08001#!/usr/bin/env python3
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wue41e0062017-09-01 19:04:14 +08003# Copyright 2017 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6r"""Switcher for git bisecting.
7
8Typical usage:
9 $ bisect_git.py config switch ./switch_git.py
10
11This is actually equivalent to
12 $ bisect_git.py config switch \
13 sh -c 'cd $GIT_REPO && git checkout -q -f $GIT_REV'
14(Note, use single quotes instead of double quotes because the variables need to
15be expanded at switch time, not now.)
16"""
17from __future__ import print_function
18import argparse
19import logging
20
21from bisect_kit import cli
22from bisect_kit import common
Kuang-che Wu385279d2017-09-27 14:48:28 +080023from bisect_kit import configure
Kuang-che Wue41e0062017-09-01 19:04:14 +080024from bisect_kit import git_util
Kuang-che Wue41e0062017-09-01 19:04:14 +080025
26logger = logging.getLogger(__name__)
27
28
29def create_argument_parser():
Kuang-che Wud2d6e412021-01-28 16:26:41 +080030 parents = [common.common_argument_parser, common.session_optional_parser]
31 parser = argparse.ArgumentParser(parents=parents)
Kuang-che Wufe1e88a2019-09-10 21:52:25 +080032 cli.patching_argparser_exit(parser)
Kuang-che Wue41e0062017-09-01 19:04:14 +080033 parser.add_argument(
34 'git_rev',
35 nargs='?',
36 type=git_util.argtype_git_rev,
37 metavar='GIT_REV',
Kuang-che Wu385279d2017-09-27 14:48:28 +080038 default=configure.get('GIT_REV', ''),
Kuang-che Wue41e0062017-09-01 19:04:14 +080039 help='Git revision id')
40 parser.add_argument(
41 '--git_repo',
42 type=cli.argtype_dir_path,
43 metavar='GIT_REPO',
Kuang-che Wu385279d2017-09-27 14:48:28 +080044 default=configure.get('GIT_REPO'),
Kuang-che Wue41e0062017-09-01 19:04:14 +080045 help='Git repository path')
46
47 return parser
48
49
Kuang-che Wufe1e88a2019-09-10 21:52:25 +080050@cli.fatal_error_handler
Kuang-che Wue41e0062017-09-01 19:04:14 +080051def main(args=None):
Kuang-che Wu385279d2017-09-27 14:48:28 +080052 common.init()
Kuang-che Wue41e0062017-09-01 19:04:14 +080053 parser = create_argument_parser()
54 opts = parser.parse_args(args)
55 common.config_logging(opts)
56
57 git_util.checkout_version(opts.git_repo, opts.git_rev)
58
59
60if __name__ == '__main__':
61 main()