-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidate.functions
89 lines (71 loc) · 3.22 KB
/
validate.functions
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This file is part of shellfire heroku. It is subject to the licence terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/heroku/master/COPYRIGHT. No part of shellfire heroku, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2015 The developers of shellfire heroku. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/heroku/master/COPYRIGHT.
core_usesIn git
heroku_validate_repository()
{
local code=$1
local category="$2"
local name="$3"
local value="$4"
core_validate_folderPathReadableAndSearchable "$code" "$category" "$name" "$value"
}
# This function has a side effect of setting heroku_repositoryPath and heroku_configurationFolderPath
core_usesIn git
heroku_validate_repositoryPathOnceDependenciesInstalled()
{
local code=$1
local category="$2"
local name="$3"
local value="$4"
if ! git_isPathSomewhereInsideGitRepository "$value"; then
core_validate_exit "The $category '$name' specifies a repository path '$value' which is not within a git repository"
fi
local repositoryPath="$(git_findAbsolutePathOfTopLevelOfRepository "$value")"
if [ -z "$repositoryPath" ]; then
core_validate_exit "The $category '$name' specifies a repository path '$value' which has not got a readable '.git' folder in its parent paths"
fi
local notEmptyIfLocalModifications="$(git_localModificationHashOrEmptyString "$repositoryPath")"
if [ -n "$notEmptyIfLocalModifications" ]; then
core_validate_exit "The $category '$name' specifies a repository path '$value' which has pending local modifications to the git repository at '$repositoryPath'"
fi
heroku_repositoryPath="$repositoryPath"
local configurationParentFolderPath="$(heroku_validate_findHerokuConfigurationParentFolderPath "$value")"
if [ -z "$configurationParentFolderPath" ]; then
core_validate_exit "The $category '$name' specifies a repository path '$value' which has not got a readable '$heroku_configurationFolderName' folder in its parent paths"
fi
heroku_configurationFolderPath="$configurationParentFolderPath"/"$heroku_configurationFolderName"
}
# If in a submodule, walks up the directory hierarchy to the '.git' folder
# If no repository found, returns ''
heroku_validate_findHerokuConfigurationParentFolderPath()
{
pushd "$1"
local currentFolderPath="$(pwd)"
popd
while ! core_path_isReadableAndSearchableFolderPath "$currentFolderPath"/"$heroku_configurationFolderName"
do
if [ "$currentFolderPath" = '/' ]; then
printf ''
return 0
fi
pushd "$currentFolderPath"/..
currentFolderPath="$(pwd)"
popd
done
printf '%s' "$currentFolderPath"
}
heroku_validate_parseBuildDir()
{
local buildDir="$1"
core_validate_folderPathReadableAndSearchableAndWritable $core_commandLine_exitCode_USAGE 'option' 'BUILD_DIR' "$buildDir"
pushd "$buildDir"
heroku_buildpack_buildDir="$(pwd)"
popd
}
heroku_validate_buildDirCommandLineParse()
{
if [ $# -ne 1 ]; then
core_commandLine_exitBadCommandLine "Please specify only one argument, BUILD_DIR, not $# arguments"
fi
heroku_validate_parseBuildDir "$1"
}