Giter VIP home page Giter VIP logo

d8githooks's Introduction

Drupal core committer git hooks

About this project

This project performs automated checks (e.g. file permissions, PHP/CSS/JS coding standards) before/after performing a commit, to ensure regressions are not accidentally committed.

Project setup

How do I, as a developer, start working on the project?

This project depends on:

  1. [git] (https://git-scm.com/downloads)
  2. composer
  3. Drupal 10
  4. Running composer install in the root directory of the repository you have checked out
  5. Running yarn install in the core directory of the repository you have checked out

Optional dependencies

  1. Homebrew (You can use homebrew to install many of the dependencies above.)
  2. pbcopy & pbpaste
  3. cowsay (brew install cowsay)

How to install

  1. Clone the respository into any directory; for example your home directory:

    cd ~; git clone https://github.com/alexpott/d8githooks.git
    
  2. Navigate to the .git/hooks directory inside the Drupal 8 clone from which you commit patches

    cd ~/Sites/8.x/.git/hooks
    
  3. Create symlinks to pre-commit and post-commit files:

ln -sfn ~/d8githooks/pre-commit pre-commit;
ln -sfn ~/d8githooks/post-commit post-commit;
  1. Mark the hooks as executable.

    chmod u+x pre-commit; chmod u+x post-commit
    

To test that it's working, introduce a file permissions error and then attempt to commit a text change:

cd ~/Sites/8.x
composer install
chmod 777 core/core.services.yml
echo 'test' >> core/core.services.yml 
git add core/core.services.yml
git commit -m "Test."

You should see the error:

git pre-commit check failed: file core/core.services.yml should be 644 not 777

Troubleshooting

Using core's Coder dev dependency

If you previously installed PHPCS or Coder globally according to instructions on https://www.drupal.org/node/1419988 and your pre-commit hook starts failing silently, you may need to do:

composer global remove drupal/coder
composer global remove phpcs
composer install

This change is required because a canonical version of Coder is now added as a core dev dependency.

Manually checking or fixing a PHP standard

To manually test the standard on a particular file prior to commit:

  1. Apply any relevant patch (including fixes, newly configured rules, etc.)

  2. From within the repository, run:

    composer install
    
  3. From the root of the repository, run:

    composer run phpcs -- core/path/to/file.php
    

    You can confirm that the check is working properly by (e.g.) adding an unused use statement to the file and ensuring it raises an error.

    Similarly, to use phpcbf to fix a file, run:

    composer run phpcbf -- core/path/to/file.php
    

    Note that in some cases the enabled core rules are not enough to fix errors correctly! You can also check:

    vendor/bin/phpcs --standard=Drupal core/path/to/file.php
    

    Be aware, however, that this may introduce out-of-scope changes as it will run rules that core does not yet comply with.

Troubleshooting eslint

sudo npm update -g

If you previously installed yarn from Homebrew or another non-npm package manager:

brew uninstall yarn
npm install -g corepack
corepack enable

How to use

@todo something about what standard message(s) to copy/paste.

d8githooks's People

Contributors

alexpott avatar junowilderness avatar lauriii avatar longwave avatar star-szr avatar timplunkett avatar webchick avatar wimleers avatar xjm avatar zrpnr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d8githooks's Issues

Post-commit reminders?

There are a couple of things that get forgotten on commit a lot. Two in particular:

  1. Ensuring there is a change record and publishing it if it exists
  2. Tagging significant issues for the release notes

I'm not sure if a short reminder message on post-commit would be helpful or too spammy, but it's a thought.

Yarn deprecation warning

While the hooks run the eslint commands, there's following warnings:

warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.

pre-commit erroneously flags composer as not installed

Running through all the instructions in the README, I get stuck at:

$ git commit -m "Test."
composer not installed, for instructions visit https://getcomposer.org/

And yet...

$ composer -V
Composer version 1.4.2 2017-05-17 08:17:52

Browsing through the code at https://github.com/alexpott/d8githooks/blob/master/pre-commit-8-4 this seems to result from the output of:

# Function to test for command dependencies.
command_exists () {
    type "$1" &> /dev/null ;
}

If I manually type that from the command line, I get:

$ type "composer"
composer is aliased to `php /usr/local/bin/composer.phar'

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.