blob: bcc825d65e24ccc12b8ed69aa26bd1d18a8cf5ab [file] [log] [blame]
Kuang-che Wue41e0062017-09-01 19:04:14 +08001#!/usr/bin/env python2
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 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()