blob: 9a57ebe7537cc0272f099f4636e5b53df81637f5 [file] [log] [blame]
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +00001#!/bin/bash
2#
3# Copyright 2015 Google Inc. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Setting up the environment for Bazel release scripts test.
18
19[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; }
20
21# Load the unit-testing framework
22source "${TEST_SRCDIR}/src/test/shell/unittest.bash" || \
23 { echo "Failed to source unittest.bash" >&2; exit 1; }
24
25# Commit at which we cut the master to do the test so we always take the git
26# repository in a consistent state.
27: ${MASTER_COMMIT:=7d41d7417fc34f7fa8aac7130a0588b8557e4b57}
28
29# Set-up a copy of the git repository in ${MASTER_ROOT}, pointing master
30# to ${MASTER_COMMIT}.
31function setup_git_repository() {
32 local origin_git_root=${TEST_SRCDIR}
33 MASTER_ROOT=${TEST_TMPDIR}/git/root
34 local orig_dir=${PWD}
35 # Create a new origin with the good starting point
36 mkdir -p ${MASTER_ROOT}
37 cd ${MASTER_ROOT}
38 cp -RL ${origin_git_root}/.git .git
39 rm -f .git/hooks/* # Do not keep custom hooks
40 git reset -q --hard HEAD
41 git checkout -q -B master ${MASTER_COMMIT}
42 cd ${orig_dir}
43}