Skip to content
Permalink
Browse files
explained how to manage git hooks
  • Loading branch information
aa7401 committed Nov 14, 2018
1 parent 8353fc5 commit 997544dc254d8415f6eda50beef2a7f25fc7bf42
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
@@ -0,0 +1,9 @@
#!/bin/sh

GREEN='\033[0;32m'
NC='\033[0m'

echo "found the following hooks:"
ls | grep -v \\.
echo "copying to the ${GREEN}.git/hooks/${NC} directory"
cp -a . ../.git/hooks/
@@ -0,0 +1,3 @@
#!/bin/sh
echo "pre-commit running"

@@ -69,21 +69,21 @@ This week you are starting the development process. You are advised to use the `
1. Ensure you have private repo(s) in the 340CT-1819OCTJAN organisation (where the TEACHING-MATERIALS repo is found). Names should be in the format xxx-yyy where xxx is your university username. Clone this into your chosen IDE.
2. Create a package.json file by running the `npm init` command.
3. Install any packages needed by your script using the `npm install --save xxx` command, where xxx is the package name. Make sure this has added the package to your `package.json` file.
3. Install any developer tools (such as eslint and jest) using the `npm install --save-dev xxx` command. This will add the module to the `dev-dependency` section of your `package.json` file.
4. Set up your `.eslintrc.json` file with the rules you want to use.
5. Add a `.eslintignore` file containing the files and directories you want to be ignored by the linter.
6. Add a jest section to your `package.json` that includes the coverage thresholds you are aiming for (100%).
7. Create a `pre-commit` file in the `.git/hooks/` directory:
4. Install any developer tools (such as eslint and jest) using the `npm install --save-dev xxx` command. This will add the module to the `dev-dependency` section of your `package.json` file.
5. Set up your `.eslintrc.json` file with the rules you want to use.
6. Add a `.eslintignore` file containing the files and directories you want to be ignored by the linter.
7. Add a jest section to your `package.json` that includes the coverage thresholds you are aiming for (100%).
8. Create a `pre-commit` file in the `.git/hooks/` directory:
1. Add a _shebang. If you are on Windows this will be `#!C:/Program\ Files/Git/usr/bin/sh.exe`, on Mac or Linux it is `#!/bin/sh`.
2. Add the line `echo "pre-commit hook working"`.
3. Make the file executable.
8. Create a `README.md` file and add the name of your project.
9. Stage and commit the file using the terminal commands:
9. Create a `README.md` file and add the name of your project.
10. Stage and commit the file using the terminal commands:
1. You should see the message `pre-commit hook working` in the terminal.
10. Create a `pre-push` hook file and add a suitable message. Test it is working.
11. Start developing your code. Make sure you apply TDD (write a test to define your next piece of functionality before implementing).
12. Modify the `pre-commit` hook to run the linter.
13. Modify the `pre-push` hook to run the jest test suite with code coverage.
11. Create a `pre-push` hook file and add a suitable message. Test it is working.
12. Start developing your code. Make sure you apply TDD (write a test to define your next piece of functionality before implementing).
13. Modify the `pre-commit` hook to run the linter.
14. Modify the `pre-push` hook to run the jest test suite with code coverage.

At this stage you can start building your system. Each time you commit code the linter will run. Each time you push your code it will run the unit tests.

@@ -93,4 +93,15 @@ By default the hooks directory contents are not part of the remote repository. T

1. Create a `.githooks` directory in the root of your project.
2. Create your hooks in this directory (make sure they are executable).
3. Create a shell script to copy the contents of the `.githooks` directory into the `.git/hooks` directory.
3. Set your hooksPath configuration variable to point to your new directory: `git config core.hooksPath .githooks`
4. If this does not work (you are probably using Windows?) you can create a shell script to copy the contents of the `.githooks` directory into the `.git/hooks` directory. There is a simple example below:

```shell
#!/bin/sh
GREEN='\033[0;32m'
NC='\033[0m'
echo "found the following hooks:"
ls | grep -v \\.
echo "copying to the ${GREEN}.git/hooks/${NC} directory"
cp -a . ../.git/hooks/
```

0 comments on commit 997544d

Please sign in to comment.