blob: 47b4937e9fb9d6ab959444a25b6092412b18340c [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/usr/bin/env bash
2
3# The common script is only meant to be included from other LLVM helper scripts
4
5if [[ $LLVM_SRC = '' ]]; then
6 echo "Please, define \$LLVM_SRC"
7 exit -1
8fi
9if [[ $LLVM_BLD = '' ]]; then
10 echo "Please, define \$LLVM_BLD"
11 exit -1
12fi
13if [[ $LLVM_GITRW = '' ]]; then
14 echo "Please, define \$LLVM_GITRW"
15 exit -1
16fi
Renato Golin7c10e6e2016-05-12 16:20:10 +010017if [[ $LLVM_GITUSER = '' ]]; then
18 echo "Please, define \$LLVM_GITUSER to access Linaro's Git server"
19 exit 1
20fi
21if [[ $LLVM_GITRW = 'yes' ]] && [[ $LLVM_SVNUSER = '' ]]; then
22 echo "Please, define \$LLVM_SVNUSER when using GITRW=yes"
23 echo "SVNUSER is your upstream LLVM commit user"
24 exit 1
Renato Golin94cc1042016-04-26 11:02:23 +010025fi
26
27get_branch() {
28 branch=`git rev-parse --abbrev-ref HEAD`
29 if [[ $? != 0 ]]; then
30 local dir=`pwd`
31 echo "Source dir '$dir' is not in a git repository" 1>&2
32 exit -1
33 fi
34 echo $branch
35}
36
37get_branches() {
38 branches=`git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)'`
39 if [[ $? != 0 ]]; then
40 local dir=`pwd`
41 echo "Source dir '$dir' is not in a git repository" 1>&2
42 exit -1
43 fi
44 echo $branches
45}
46
47safe_run() {
Diana Picus416bc4f2016-04-22 16:47:57 +030048 "$@"
Renato Golin94cc1042016-04-26 11:02:23 +010049 if [[ $? != 0 ]]; then
Diana Picus416bc4f2016-04-22 16:47:57 +030050 echo "'$@' failed, bailing out"
Renato Golin94cc1042016-04-26 11:02:23 +010051 exit 1
52 fi
53}
54
55is_git() {
56 test -d `git rev-parse --show-toplevel`/.git
57}
58
59is_git_svn() {
60 test -f `git rev-parse --show-toplevel`/.git/svn/.metadata
61}