diff --git a/Makefile b/Makefile index 8de8b368..2131fe3d 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ lint-shell: docker run \ --volume="$${PWD}:/code" \ -w /code \ - -e SHELLCHECK_OPTS='-s bash -S warning -a' \ + -e SHELLCHECK_OPTS='-s bash -S style -a' \ --rm koalaman/shellcheck \ $$(find src .ci utils tests docs -type f \ -name '*.sh' -o -name '*.bash' -o -name '*.bats') diff --git a/docs/build.sh b/docs/build.sh index 529a48bd..7b4c8013 100644 --- a/docs/build.sh +++ b/docs/build.sh @@ -29,7 +29,7 @@ function copy_to_posts { current_date=$(date "+%Y-%m-%d") # Creating command refernce: - for com in $MAN_LOCATION/git-secret-*.1.md; do + for com in "$MAN_LOCATION"/git-secret-*.1.md; do local short_name short_name=$(echo "$com" | sed -n "s|$MAN_LOCATION/\(.*\)\.1\.md|\1|p") local command_header="--- @@ -69,7 +69,7 @@ function copy_install_scripts { function copy_version { - echo "$(./git-secret --version)" > docs/_includes/version.txt + ./git-secret --version > docs/_includes/version.txt } diff --git a/src/_utils/_git_secret_tools.sh b/src/_utils/_git_secret_tools.sh index 82921b27..86675890 100644 --- a/src/_utils/_git_secret_tools.sh +++ b/src/_utils/_git_secret_tools.sh @@ -388,7 +388,7 @@ function _append_relative_root_path { local subdir subdir=$(git rev-parse --show-prefix) # get the subdir of repo, like "subdir/" - if [ ! -z "$subdir" ]; then + if [ -n "$subdir" ]; then full_path="$(dirname "$full_path")/${subdir}/$(basename "$full_path")" fi diff --git a/tests/test_cat.bats b/tests/test_cat.bats index 9f967b0a..f39b4ab8 100644 --- a/tests/test_cat.bats +++ b/tests/test_cat.bats @@ -1,4 +1,6 @@ #!/usr/bin/env bats +# shellcheck disable=SC2030,SC2031 +# above is to avoid shellcheck info warnings that we don't understand load _test_base @@ -71,16 +73,17 @@ function teardown { mkdir subdir echo "content2" > subdir/new_filename.txt - cd subdir - run git secret add new_filename.txt - [ "$status" -eq 0 ] - run git secret hide - [ "$status" -eq 0 ] + ( # start subshell for subdir tests + cd subdir + run git secret add new_filename.txt + [ "$status" -eq 0 ] + run git secret hide + [ "$status" -eq 0 ] - run git secret cat -d "$TEST_GPG_HOMEDIR" -p "$password" new_filename.txt - [ "$status" -eq 0 ] + run git secret cat -d "$TEST_GPG_HOMEDIR" -p "$password" new_filename.txt + [ "$status" -eq 0 ] + ) # end subshell, cd back up # clean up - cd .. rm -rf subdir } diff --git a/tests/test_hide.bats b/tests/test_hide.bats index ff766b26..af3378a4 100644 --- a/tests/test_hide.bats +++ b/tests/test_hide.bats @@ -42,7 +42,7 @@ function teardown { # File must be a binary: local mime mime="$(file --mime-type --mime-encoding "$new_file" | grep 'charset=binary')" - [ ! -z "$mime" ] + [ -n "$mime" ] } @@ -61,7 +61,7 @@ function teardown { # File must be a text: local mime mime="$(file --mime-type --mime-encoding "$new_file" | grep 'charset=us-ascii')" - [ ! -z "$mime" ] + [ -n "$mime" ] } @@ -129,15 +129,17 @@ function teardown { # Verify that the second file is there: [ -f "$second_file" ] - # cd into the subdir - cd "$root_dir" + ( # start subshell for following commands - # Now it should hide 2 files: - run git secret hide - [ "$status" -eq 0 ] + # cd into the subdir + cd "$root_dir" + + # Now it should hide 2 files: + run git secret hide + [ "$status" -eq 0 ] + ) # end subshell, return to .. - # cd back and clean up - cd ".." + # clean up rm -rf "$root_dir" } diff --git a/tests/test_removeperson.bats b/tests/test_removeperson.bats index 64f03cae..abd7045d 100644 --- a/tests/test_removeperson.bats +++ b/tests/test_removeperson.bats @@ -27,6 +27,8 @@ function teardown { @test "run 'removeperson' with short name" { local name + # don't complain about sed + # shellcheck disable=SC2001 name=$(echo "$TEST_DEFAULT_USER" | sed -e 's/@.*//') # removeperson must use full email, not short name diff --git a/tests/test_reveal.bats b/tests/test_reveal.bats index 8191963f..006c5273 100644 --- a/tests/test_reveal.bats +++ b/tests/test_reveal.bats @@ -278,16 +278,17 @@ function teardown { mkdir subdir echo "content2" > subdir/new_filename.txt - cd subdir - run git secret add new_filename.txt - [ "$status" -eq 0 ] - run git secret hide - [ "$status" -eq 0 ] - - run git secret reveal -d "$TEST_GPG_HOMEDIR" -p "$password" new_filename.txt - [ "$status" -eq 0 ] + ( # start subshell for subdir tests + cd subdir + run git secret add new_filename.txt + [ "$status" -eq 0 ] + run git secret hide + [ "$status" -eq 0 ] + + run git secret reveal -d "$TEST_GPG_HOMEDIR" -p "$password" new_filename.txt + [ "$status" -eq 0 ] + ) # end subshell # clean up - cd .. rm -rf subdir } diff --git a/tests/test_tell.bats b/tests/test_tell.bats index 6609d814..21f598c5 100644 --- a/tests/test_tell.bats +++ b/tests/test_tell.bats @@ -199,6 +199,8 @@ function teardown { install_fixture_key "$TEST_NOEMAIL_COMMENT_USER" local name + # don't complain about sed + # shellcheck disable=SC2001 name=$(echo "$TEST_NOEMAIL_COMMENT_USER" | sed -e 's/@.*//') # echo "$name" | sed "s/^/# '$BATS_TEST_DESCRIPTION' name is: /" >&3