From 634a3d2075a4b775044879c9465589be8f64f3f0 Mon Sep 17 00:00:00 2001 From: Fabricio Sander <79223916+fsz-codeshop@users.noreply.github.com> Date: Tue, 13 Apr 2021 16:34:40 -0300 Subject: [PATCH] fix: changes the logic to handle dry-run with --write option and corrects the logic as it will never have changes on dry-run --- entrypoint.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 501660f..43bd364 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,6 +25,10 @@ _git_changed() { [[ -n "$(git status -s)" ]] } +_git_changes() { + git diff +} + # PROGRAM echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in @@ -56,13 +60,12 @@ prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running # To keep runtime good, just continue if something was changed if _git_changed; then + # case when --write is used with dry-run so if something is unpretty there will always have _git_changed if $INPUT_DRY; then - if [ "$PRETTIER_RESULT" -eq 1 ]; then - echo "Prettier found unpretty files!" - exit 1 - else - echo "No unpretty files! Finishing dry-run." - fi + echo "Unpretty Files Changes:" + _git_changes + echo "Finishing dry-run. Exiting before committing." + exit 1 else # Calling method to configure the git environemnt _git_setup @@ -91,5 +94,13 @@ if _git_changed; then echo "Changes pushed successfully." fi else + # case when --check is used so there will never have something to commit but there are unpretty files + if [ "$PRETTIER_RESULT" -eq 1 ]; then + echo "Prettier found unpretty files!" + exit 1 + else + echo "Finishing dry-run." + fi + echo "No unpretty files!" echo "Nothing to commit. Exiting." fi