-
Notifications
You must be signed in to change notification settings - Fork 2
/
branchout-environment
executable file
·71 lines (53 loc) · 2.07 KB
/
branchout-environment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
test -n "${DEBUG}" && set -x
set -e
# Check if the give directory contains the branchout files
function branchoutFiles() {
if test -f "${1}/Branchoutfile"; then
BRANCHOUT_FILE=Branchoutfile
BRANCHOUT_PROJECTS=Branchoutprojects
return 0
fi
if test -f "${1}/.branchout"; then
BRANCHOUT_FILE=.branchout
BRANCHOUT_PROJECTS=.projects
return 0
fi
return 1
}
function branchoutDirectory() {
PROJECTION_DIRECTORY="${PWD}"
while test "${PROJECTION_DIRECTORY}" != '/'; do
if branchoutFiles "${PROJECTION_DIRECTORY}"; then
return 0
fi
PROJECTION_DIRECTORY=$(dirname "${PROJECTION_DIRECTORY}")
done
fail "Branchoutfile configuration not found in parent hierarchy, perhaps you need to be in a project directory $(ls -d "${HOME}/${BRANCHOUT_PROJECTS_DIRECTORY}" )"
}
function fail() {
test -n "${1}" && echo "${1}" && echo
exit 1
}
test -n "${BRANCHOUT_LOADED}" && return 0
branchoutDirectory
export PROJECTION_DIRECTORY
export BRANCHOUT_PROJECTS
export BRANCHOUT_FILE
# shellcheck source=examples/Branchoutfile
source "${PROJECTION_DIRECTORY}/${BRANCHOUT_FILE}"
test -z "${BRANCHOUT_NAME}" && fail "Branchout name not defined in ${BRANCHOUT_FILE}, run branchout init"
export BRANCHOUT_NAME
BRANCHOUT_STATE="${HOME}/branchout/${BRANCHOUT_NAME}"
export BRANCHOUT_STATE
test ! -d "${BRANCHOUT_STATE}" && usage "Branchout home '${BRANCHOUT_STATE}' does not exist, run branchout init"
test -f "${PROJECTION_DIRECTORY}/${BRANCHOUT_PROJECTS}" || usage "${BRANCHOUT_PROJECTS} file missing, try branchout add [repository]"
# shellcheck source=examples/branchoutrc
test -f "${BRANCHOUT_STATE}/branchoutrc" && source "${BRANCHOUT_STATE}/branchoutrc"
BRANCHOUT_GIT_BASEURL="$(git --git-dir "${PROJECTION_DIRECTORY}/.git" remote get-url origin 2>/dev/null | sed -e 's,/[^/]*$,,')"
test -z "${BRANCHOUT_GIT_BASEURL}" && fail "The projection directory is not a git repository, run branchout init."
export BRANCHOUT_GIT_BASEURL
export BRANCHOUT_PREFIX
export BRANCHOUT_MAVEN_REPOSITORY
export BRANCHOUT_DOCKER_REGISTRY
export BRANCHOUT_LOADED="true"