Laravel Pint PHP Tests run automatically on before git commit using git hooks

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024

Комментарии • 10

  • @hoangquanghuy1475
    @hoangquanghuy1475 6 месяцев назад +1

    thk you

  • @71Anshumaan
    @71Anshumaan 2 года назад +1

    👍

  • @RudivanZandwijk
    @RudivanZandwijk 2 года назад +3

    Are the style code fixes also committed? It looks like after the fix is done, the previous code is committed, and the styling fixes are tracked en not committed. How do you make that work in the hook? "git add ." again in the hook can have unexpected results if you commit only specific files en not all changes.

    • @amitavroydev
      @amitavroydev  2 года назад

      Hey Rudi, so if I understand correctly, what you are saying is that the git hook which is running before the commit is not adding the changes which are added during the fix? I don't have the code setup, so I will try that and see if that's really the case and how I missed that.

    • @RudivanZandwijk
      @RudivanZandwijk 2 года назад

      @@amitavroydev Yeah, If I saw it correctly, it wasn't committed.

    • @jaim8587
      @jaim8587 2 года назад +2

      This could work for comitting specific/all files...
      # store list of staged files to variable except deleted file since it won't work at re-add
      list=$(git diff --name-only --cached --diff-filter=d)
      # run pint, this will unstage any files that pint will fix
      ./vendor/bin/pint
      # re-add unstaged files caused by pint back to staging
      printf $list | xargs git add
      PS - initially run pint first and add fixed files to staging

  • @rakeshroy7986
    @rakeshroy7986 Год назад +1

    Hi
    Modified files not adding to commit after pint fixed the files
    The below code doesn't work
    #!/bin/sh
    GREEN='\033[1;32m'
    NC='\033[0m' # No Color
    list=$(git diff --name-only --cached --diff-filter=d)
    printf "${GREEN}Running Pint${NC}

    "
    vendor/bin/pint
    printf "


    ==============================================


    "
    printf $list | xargs git add
    #printf "${GREEN}Running Tests${NC}

    "
    #php artisan test
    #printf "


    ==============================================


    "