Skip to content

Commit

Permalink
Merge pull request #2034 from perlpunk/sync-tidy
Browse files Browse the repository at this point in the history
Sync tools/tidy with openQA
  • Loading branch information
mergify[bot] committed Apr 20, 2022
2 parents 1f2717e + f47ab95 commit 0b7e5b8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tools/tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@
#
# perltidy rules can be found in ../.perltidyrc
#

usage() {
cat << EOF
Usage:
tidy [-c|--check] [-f|--force] [-o|--only-changed] [path/to/file]
tidy [-c|--check] [-f|--force] [-o|--only-changed] [-l|--list] [path/to/file]
Options:
-h, -?, --help display this help
-c, --check Only check for style check differences
-f, --force Force check even if tidy version mismatches
-o --only-changed Only tidy files with uncommitted changes in git. This can
speed up execution a lot.
-l --list List files tidy would touch
path/to/file When passing a file as argument, tidy will run perltidy
wether it is added to the git tree or not
perltidy rules can be found in .perltidyrc
EOF
exit
}

set -eo pipefail
dir="$(dirname "$0")"

args=""
selection='--all'
opts=$(getopt -o hcfo --long help,check,force,only-changed -n 'parse-options' -- "$@") || usage
[[ -e "$dir/perlfiles" ]] && selection=$("$dir"/perlfiles)
opts=$(getopt -o hcfol --long help,check,force,only-changed,list -n "$0" -- "$@") || usage
eval set -- "$opts"
while true; do
case "$1" in
-h | --help ) usage; shift ;;
-c | --check ) args+=' --check-only'; shift ;;
-f | --force ) force=true; shift ;;
-o | --only-changed ) selection='--git'; shift ;;
-l | --list ) args+='--list'; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
Expand All @@ -49,17 +51,16 @@ if ! command -v perltidy > /dev/null 2>&1; then
exit 1
fi

# cpan file is in top directory
dir="$(dirname "$0")/.."
perltidy_version_expected=$(sed -n "s/^.*Perl::Tidy[^0-9]*\([0-9]*\)['];$/\1/p" "$dir"/cpanfile)
perltidy_version_expected=$(sed -n "s/^.*Perl::Tidy[^0-9]*\([0-9]*\)['];$/\1/p" "$dir"/../cpanfile)
# This might be used from another repo like os-autoinst-distri-opensuse
if [ -z "${perltidy_version_expected}" ]; then
# No cpanfile in the linked repo, use the one from os-autoinst instead
dir="$(dirname "$(readlink -f "$0")")/.."
perltidy_version_expected=$(sed -n "s/^.*Perl::Tidy[^0-9]*\([0-9]*\)['];$/\1/p" "$dir"/cpanfile)
dir="$(dirname "$(readlink -f "$0")")"
perltidy_version_expected=$(sed -n "s/^.*Perl::Tidy[^0-9]*\([0-9]*\)['];$/\1/p" "$dir"/../cpanfile)
fi
perltidy_version_found=$(perltidy -version | sed -n '1s/^.*perltidy, v\([0-9]*\)\s*$/\1/p')
if [ "$perltidy_version_found" != "$perltidy_version_expected" ]; then
echo -n "Wrong version of perltidy. Found '$perltidy_version_found', expected '$perltidy_version_expected'."
echo -n "Wrong version of perltidy. Found '$perltidy_version_found', expected '$perltidy_version_expected'. "
if [[ "$force" = "true" ]]; then
echo "Found '--force', continuing"
else
Expand All @@ -69,7 +70,7 @@ if [ "$perltidy_version_found" != "$perltidy_version_expected" ]; then
fi

# go to caller directory
cd "$(dirname "$0")/.."
cd "$dir/.."

# just to make sure we are at the right location
test -e tools/tidy || exit 1
Expand Down

0 comments on commit 0b7e5b8

Please sign in to comment.