Skip to content

Commit 30db3b8

Browse files
committed
Add shellcheck pre-commit hook
Convert the shellcheck test from a test to a pre-commit hook this prevents needing to updated the docker file every time there is an update to shellcheck.
1 parent 68b8e97 commit 30db3b8

File tree

9 files changed

+47
-86
lines changed

9 files changed

+47
-86
lines changed

.github/workflows/pre-commit.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v3
13+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ repos:
1010
- id: check-executables-have-shebangs
1111
- id: check-shebang-scripts-are-executable
1212
exclude: \.t$
13+
- repo: https://github.com/koalaman/shellcheck-precommit
14+
rev: v0.10.0
15+
hooks:
16+
- id: shellcheck
17+
args: [-x]
18+
exclude: |
19+
(?x)^(ext/.*|
20+
share/git-completion.bash
21+
)$

note/init-test

Lines changed: 0 additions & 38 deletions
This file was deleted.

note/test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ git clone "[email protected]:$repo" test-repo
1313

1414
(
1515
# cd into test-repo
16-
cd test-repo
16+
cd test-repo || exit
1717
# Tag original head
1818
git tag o
1919
# Pick a commit in the middle of the commit history
2020
S=$(git rev-parse HEAD^^^^)
2121
# Reset to the middle commit
22-
git reset --hard $S
22+
git reset --hard "$S"
2323
# Tag that history as 'a'
2424
git tag a
2525
# Reset to original
2626
git reset --hard o
2727
# Take the tail of the history.
28-
git filter-branch -f --parent-filter "sed 's/-p $S//'" $S..HEAD
28+
git filter-branch -f --parent-filter "sed 's/-p $S//'" "$S..HEAD"
2929
# Mark that sequence as 'b'
3030
git tag b
3131
# Reset to a

pkg/bin/generate-completion.pl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,12 @@ sub generate_bash {
162162
local _opts="$options_string"
163163
local subcommands="@$list"
164164
local subdircommands="@$subdir_cmds"
165-
local subcommand="\$(__git_find_on_cmdline "\$subcommands")"
165+
local subcommand
166+
subcommand="\$(__git_find_on_cmdline "\$subcommands")"
166167
167168
if [ -z "\$subcommand" ]; then
168169
# no subcommand yet
170+
# shellcheck disable=SC2154
169171
case "\$cur" in
170172
-*)
171173
__gitcomp "\$_opts"
@@ -188,9 +190,11 @@ sub generate_bash {
188190
return
189191
fi
190192
191-
local subdircommand="\$(__git_find_on_cmdline "\$subdircommands")"
192-
if [ ! -z "\$subdircommand" ]; then
193-
local git_subrepos=`git subrepo status -q`
193+
local subdircommand
194+
subdircommand="\$(__git_find_on_cmdline "\$subdircommands")"
195+
if [ -n "\$subdircommand" ]; then
196+
local git_subrepos
197+
git_subrepos=$(git subrepo status -q)
194198
__gitcomp "\$git_subrepos"
195199
fi
196200

share/completion.bash

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ _git_subrepo() {
44
local _opts=" -h --help --version -a --all -A --ALL -b= --branch= -e --edit -f --force -F --fetch -M= --method= -m= --message= --file= -r= --remote= -s --squash -u --update -q --quiet -v --verbose -d --debug -x --DEBUG"
55
local subcommands="branch clean clone commit config fetch help init pull push status upgrade version"
66
local subdircommands="branch clean commit config fetch pull push status"
7-
local subcommand="$(__git_find_on_cmdline "$subcommands")"
7+
local subcommand
8+
subcommand="$(__git_find_on_cmdline "$subcommands")"
89

910
if [ -z "$subcommand" ]; then
1011
# no subcommand yet
12+
# shellcheck disable=SC2154
1113
case "$cur" in
1214
-*)
1315
__gitcomp "$_opts"
@@ -30,9 +32,11 @@ _git_subrepo() {
3032
return
3133
fi
3234

33-
local subdircommand="$(__git_find_on_cmdline "$subdircommands")"
34-
if [ ! -z "$subdircommand" ]; then
35-
local git_subrepos=`git subrepo status -q`
35+
local subdircommand
36+
subdircommand="$(__git_find_on_cmdline "$subdircommands")"
37+
if [ -n "$subdircommand" ]; then
38+
local git_subrepos
39+
git_subrepos=$(git subrepo status -q)
3640
__gitcomp "$git_subrepos"
3741
fi
3842

share/enable-completion.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if [[ -n ${BASH_VERSION-} ]]; then
1717
{,/usr/local,~/.homebrew}/etc/bash_completion.d/git
1818
do
1919
# If a file is found at the location being checked…
20+
# shellcheck source=/dev/null
2021
if [[ -f $f ]]; then
2122
# …source it.
2223
source "$f"
@@ -35,10 +36,14 @@ if [[ -n ${BASH_VERSION-} ]]; then
3536
# If no file was found at any of the potential file-paths checked
3637
# above, source a bundled copy of
3738
# <https://github.com/git/git/blob/c285171/contrib/completion/git-completion.bash>.
39+
40+
# shellcheck source=share/git-completion.bash
3841
source "$GIT_SUBREPO_ROOT/share/git-completion.bash"
3942
}
4043
fi
4144
# Load our Bash completion facilities.
45+
46+
# shellcheck source=share/completion.bash
4247
source "$GIT_SUBREPO_ROOT/share/completion.bash"
4348
elif [[ -n ${ZSH_VERSION-} ]]; then
4449
# Zsh

test/setup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ BASHLIB=$(
1717
export BASHLIB
1818

1919
export PATH=$BASHLIB:$PATH
20+
# shellcheck disable=SC1091
2021
source bash+ :std
2122

2223
source 'lib/git-subrepo'

test/shellcheck.t

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)