-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooksSetup.bash
executable file
·77 lines (70 loc) · 3.06 KB
/
hooksSetup.bash
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
#!/usr/bin/env bash
#
# Copyright (c) 2019-2020 Alessandro Sciarra <[email protected]>
#
# This file is part of GitHooks.
#
# GitHooks is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GitHooks is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GitHooks. If not, see <https://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------
# Preliminary setup and source of bash functions
printf "\n"; trap 'printf "\n"' EXIT
readonly thisRepositoryTopLevelPath="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
readonly hookImplementationFolderName='BashImplementation'
readonly auxiliaryBashCodeTopLevelPath="${thisRepositoryTopLevelPath}"
source "${auxiliaryBashCodeTopLevelPath}/${hookImplementationFolderName}/auxiliaryFunctions.bash"
# Global variable for this hook are sourced in the file just sourced!
# Variables to tune setup
repositoryTopLevelPath=''
copyFilesToRepository='FALSE'
symlinkFilesToRepository='FALSE'
removeFilesFromRepository='FALSE'
forceCopyOrSymlink='FALSE'
activateCodeStyleCheck='FALSE'
repositoryLanguage=''
clangFormatStyleFile="${thisRepositoryTopLevelPath}/_clang-format"
activateLicenseNoticeCheck='FALSE'
licenceNoticeFile=''
extensionsOfFilesWhoseLicenseNoticeShouldBeChecked='.*'
activateCopyrightCheck='FALSE'
extensionsOfFilesWhoseCopyrightShouldBeChecked='.*'
activateWhitespaceFixAndCheck='FALSE'
activateBranchRestrictions='FALSE'
activateCommitFormatCheck='FALSE'
commitHeadlineMinimumLength=8
commitHeadlineMaximumLength=60
commitBodyLineMaximumLength=72
ParseCommandLineOptions "$@"
ValidateCommandLineOptions
# Actual set-up
readonly hookGitFolder="${repositoryTopLevelPath}/.git/hooks"
readonly hooksSourceFolderGlobalpath="${thisRepositoryTopLevelPath}"
readonly fileWithVariablesToSupportHooksExecution="${hookGitFolder}/hooksGlobalVariables.bash"
readonly clangFormatStyleFileDestination="${repositoryTopLevelPath}/$(basename "${clangFormatStyleFile}")"
readonly licenceNoticeFileDestination="${repositoryTopLevelPath}/.git/hooks/LicenseNotice.txt"
if [[ ${removeFilesFromRepository} = 'TRUE' ]]; then
RemoveFilesOrSymlinksFromRepository
else
CreateFileWithVariablesToSupportHooksExecution
SetupHooksForGivenRepository
if [[ ${activateCodeStyleCheck} = 'TRUE' && "${repositoryLanguage}" =~ ^c(pp)?$ ]]; then
CheckClangFormatAvailability
SetupClangFormatStyleForGivenRepository
elif [[ "${repositoryLanguage}" != '' ]]; then
PrintWarning "No code style setup available yet for the selected language."
fi
if [[ ${activateLicenseNoticeCheck} = 'TRUE' ]]; then
SetupLicenceNoticeCheckForGivenRepository
fi
fi