Skip to content

Commit e6b2d8a

Browse files
committed
Drop pre-commit and script checking program in favor of the pre-commit framework
Signed-off-by: 林博仁(Buo-ren Lin) <Buo.Ren.Lin@gmail.com>
1 parent f57fd2c commit e6b2d8a

9 files changed

+38
-49
lines changed

.gitconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Project-specific Git Configuration
22
# Documentation: git-config manpage
33
[filter "bash"]
4-
clean = "\"Clean Filter for GNU Bash Scripts/Clean Filter for GNU Bash Script.bash\""
4+
clean = "\"Clean Filter for GNU Bash Scripts/filter.bash\""

.gitmodules

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
[submodule "GNU Bash Automatic Checking Program for Git Projects"]
2-
path = GNU Bash Automatic Checking Program for Git Projects
3-
url = https://github.com/Lin-Buo-Ren/GNU-Bash-Automatic-Checking-Program-for-Git-Projects.git
4-
[submodule "Git Pre-commit Hook for GNU Bash Projects"]
5-
path = Git Pre-commit Hook for GNU Bash Projects
6-
url = https://github.com/Lin-Buo-Ren/Git_Pre-commit_Hook_for_GNU_Bash_Projects
71
[submodule "Clean Filter for GNU Bash Scripts"]
82
path = Clean Filter for GNU Bash Scripts
93
url = https://github.com/Lin-Buo-Ren/Clean-Filter-for-GNU-Bash-Scripts

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Configuration for pre-commit: A framework for managing and maintaining multi-language pre-commit hooks.
2+
# https://pre-commit.com/
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v1.2.3
6+
hooks:
7+
- id: check-yaml
8+
- id: check-executables-have-shebangs
9+
- id: check-byte-order-marker
10+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
11+
rev: 1.6.0
12+
hooks:
13+
- id: shellcheck

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,25 @@ addons:
3737
# Software packages to be installed
3838
packages:
3939
- realpath # script dependencies
40-
- python-pip # for yamllint
4140

4241
### You can run custom commands before the installation step
4342
before_install:
44-
- git submodule init 'Utilities for Travis CI' 'GNU Bash Automatic Checking Program for Git Projects'
45-
- git submodule update --depth=1
43+
- git submodule init 'Utilities for Travis CI'
44+
- git submodule update --depth=30
4645

4746
### Install/Setup any required dependencies used in continuous integration
4847
### https://docs.travis-ci.com/user/installing-dependencies/
4948
install:
50-
5149
#### Sometimes dependencies needs to be build from source code and install/setup to use it
5250
#### https://docs.travis-ci.com/user/installing-dependencies/#Installing-Projects-from-Source
5351
- ./"Utilities for Travis CI/Setup ShellCheck's Latest Release without Re-building.bash"
5452
- PATH="${HOME}/Software/shellcheck-stable:${PATH}"
5553

56-
- ./"Utilities for Travis CI/Setup yamllint in Ubuntu lesser than 16.04.bash"
57-
- PATH="${HOME}/.local/bin:${PATH}"
54+
- pip install --user pre-commit
5855

5956
### You can run custom commands before the script/build step
6057
before_script:
61-
- yamllint *.yml .*.yml
62-
- ./"GNU Bash Automatic Checking Program for Git Projects/GNU Bash Automatic Checking Program for Git Projects.bash"
58+
- git diff-tree -z --no-commit-id --name-only -r HEAD | xargs --null pre-commit run --files
6359

6460
### Put your build scripts here
6561
script: true
Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 0 additions & 1 deletion
This file was deleted.

Setup Development Environment.bash

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,30 @@ init(){
4040

4141
export GIT_DIR="${RUNTIME_EXECUTABLE_DIRECTORY}/.git"
4242
export GIT_WORK_TREE="${RUNTIME_EXECUTABLE_DIRECTORY}"
43+
cd "${GIT_WORK_TREE}"
44+
45+
printf 'Fetching submodules..'
46+
git submodule init 'Clean Filter for GNU Bash Scripts'
47+
git submodule update --depth=30
48+
(
49+
unset GIT_DIR GIT_WORK_TREE
50+
cd 'Clean Filter for GNU Bash Scripts'
51+
git submodule init 'Code Formatters and Beautifiers/the Bash Script Beautifier'
52+
git submodule update --depth=30
53+
)
4354

4455
printf 'Setting Project-specific Git configuration...'
4556
git config include.path ../.gitconfig\
4657
&& printf 'done\n'
4758

4859
printf 'Setting Git Hooks...'
49-
declare -r precommit_hook_path='Git Pre-commit Hook for GNU Bash Projects/Git Pre-commit Hook for GNU Bash Projects.bash'
50-
if [ ! -x "${precommit_hook_path}" ]; then
51-
printf \
52-
'\n%s: Error: Unable to locate the pre-commit hook'\
53-
"${RUNTIME_EXECUTABLE_NAME}" 1>&2
54-
exit 1
60+
if ! command -v pre-commit &>/dev/null; then
61+
printf -- \
62+
'%s: Warning: pre-commit(https://pre-commit.com) is not installed, skipping setup.\n' \
63+
"${RUNTIME_EXECUTABLE_NAME}"
64+
else
65+
pre-commit install
5566
fi
56-
ln \
57-
--symbolic\
58-
--relative\
59-
--force\
60-
--verbose\
61-
"${precommit_hook_path}"\
62-
"${GIT_DIR}/hooks/pre-commit"\
63-
&& printf 'done\n'
64-
65-
printf 'Fetching submodules..'
66-
git submodule update --init --recursive\
67-
&& printf 'done\n'\
68-
|| printf 'failed\n'
69-
70-
printf 'Activate Git smudge filter...\n'
71-
declare -i result
72-
git stash save &>/dev/null\
73-
|| true
74-
rm "${GIT_DIR}/index" >/dev/null \
75-
&& git checkout HEAD -- "$(git rev-parse --show-toplevel)" >/dev/null
76-
git stash pop &>/dev/null\
77-
|| true
78-
printf 'done.\n'
7967

8068
exit 0
8169
}; declare -fr init
@@ -158,4 +146,4 @@ init "${@}"
158146
## https://github.com/Lin-Buo-Ren/GNU-Bash-Shell-Script-Template
159147
## and is based on the following version:
160148
declare -r META_BASED_ON_GNU_BASH_SHELL_SCRIPT_TEMPLATE_VERSION='v1.26.0-32-g317af27-dirty'
161-
## You may rebase your script to incorporate new features and fixes from the template
149+
## You may rebase your script to incorporate new features and fixes from the template

0 commit comments

Comments
 (0)