Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created January 20, 2023 16:32
Show Gist options
  • Select an option

  • Save danielgomezrico/6f88ceb468162385fc7075e73817ec67 to your computer and use it in GitHub Desktop.

Select an option

Save danielgomezrico/6f88ceb468162385fc7075e73817ec67 to your computer and use it in GitHub Desktop.

Revisions

  1. danielgomezrico created this gist Jan 20, 2023.
    29 changes: 29 additions & 0 deletions pre-commit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/sh
    #
    # Autoformat all modified files before commit
    #

    function format_if_required {
    FILES=$1

    flutter format $FILES | grep -Ev '^(Unchanged)'

    echo "--> Autoformat was applied/checked ✅"
    }

    echo "----------------------------------------------------------"
    echo " Checking code format on staged files"
    echo "----------------------------------------------------------"
    CHANGED_FILES=$(git diff --diff-filter=d --cached --name-only | grep .dart)

    if [ -z "$CHANGED_FILES" ];
    then
    echo "--> No files added to check"
    else
    format_if_required $CHANGED_FILES
    fi

    echo "--> Commit is ok ✅"
    echo "----------------------------------------------------------"

    exit 0