#!/usr/bin/env bash

# Copyright 2016 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT

# Use this script to bisect a regression using the prebuilt magenta kernel images. The arguments to
# this script are passed to 'git bisect start'

set -e

readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# During the bisect git will change the working tree including the bisect script, so make a copy of
# it in a temporary location first.
readonly TEMP_DIR="$(mktemp -d)"
trap "rm -rf ${TEMP_DIR}" EXIT
cp "${DIR}/bisect-helper-x86-64" "${TEMP_DIR}"
git bisect start $@
git bisect run "${TEMP_DIR}/bisect-helper-x86-64" "${DIR}"
