├── LICENSE
├── README.md
├── applypatch-msg
├── README.md
└── applypatch-msg-check-log-message
├── commit-msg
├── README.md
└── commit-msg-jira
├── contributing.md
├── post-commit
└── README.md
├── post-receive
├── README.md
└── post-receive-specific-folder
├── post-rewrite
├── README.md
└── post-rewrite-move-refs
├── pre-auto-gc
├── README.md
└── pre-auto-gc-battery
├── pre-commit
├── README.md
└── pre-commit-swiftlint
├── pre-push
├── README.md
└── pre-push-protect-branches
├── pre-rebase
├── README.md
└── pre-rebase-rebaselock
├── pre-receive
├── README.md
└── pre-receive-ban-on-push-to-branch
└── prepare-commit-msg
├── README.md
└── prepare-commit-msg-jira
/LICENSE:
--------------------------------------------------------------------------------
1 | CC0 1.0 Universal
2 |
3 | Statement of Purpose
4 |
5 | The laws of most jurisdictions throughout the world automatically confer
6 | exclusive Copyright and Related Rights (defined below) upon the creator and
7 | subsequent owner(s) (each and all, an "owner") of an original work of
8 | authorship and/or a database (each, a "Work").
9 |
10 | Certain owners wish to permanently relinquish those rights to a Work for the
11 | purpose of contributing to a commons of creative, cultural and scientific
12 | works ("Commons") that the public can reliably and without fear of later
13 | claims of infringement build upon, modify, incorporate in other works, reuse
14 | and redistribute as freely as possible in any form whatsoever and for any
15 | purposes, including without limitation commercial purposes. These owners may
16 | contribute to the Commons to promote the ideal of a free culture and the
17 | further production of creative, cultural and scientific works, or to gain
18 | reputation or greater distribution for their Work in part through the use and
19 | efforts of others.
20 |
21 | For these and/or other purposes and motivations, and without any expectation
22 | of additional consideration or compensation, the person associating CC0 with a
23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25 | and publicly distribute the Work under its terms, with knowledge of his or her
26 | Copyright and Related Rights in the Work and the meaning and intended legal
27 | effect of CC0 on those rights.
28 |
29 | 1. Copyright and Related Rights. A Work made available under CC0 may be
30 | protected by copyright and related or neighboring rights ("Copyright and
31 | Related Rights"). Copyright and Related Rights include, but are not limited
32 | to, the following:
33 |
34 | i. the right to reproduce, adapt, distribute, perform, display, communicate,
35 | and translate a Work;
36 |
37 | ii. moral rights retained by the original author(s) and/or performer(s);
38 |
39 | iii. publicity and privacy rights pertaining to a person's image or likeness
40 | depicted in a Work;
41 |
42 | iv. rights protecting against unfair competition in regards to a Work,
43 | subject to the limitations in paragraph 4(a), below;
44 |
45 | v. rights protecting the extraction, dissemination, use and reuse of data in
46 | a Work;
47 |
48 | vi. database rights (such as those arising under Directive 96/9/EC of the
49 | European Parliament and of the Council of 11 March 1996 on the legal
50 | protection of databases, and under any national implementation thereof,
51 | including any amended or successor version of such directive); and
52 |
53 | vii. other similar, equivalent or corresponding rights throughout the world
54 | based on applicable law or treaty, and any national implementations thereof.
55 |
56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59 | and Related Rights and associated claims and causes of action, whether now
60 | known or unknown (including existing as well as future claims and causes of
61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum
62 | duration provided by applicable law or treaty (including future time
63 | extensions), (iii) in any current or future medium and for any number of
64 | copies, and (iv) for any purpose whatsoever, including without limitation
65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66 | the Waiver for the benefit of each member of the public at large and to the
67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver
68 | shall not be subject to revocation, rescission, cancellation, termination, or
69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work
70 | by the public as contemplated by Affirmer's express Statement of Purpose.
71 |
72 | 3. Public License Fallback. Should any part of the Waiver for any reason be
73 | judged legally invalid or ineffective under applicable law, then the Waiver
74 | shall be preserved to the maximum extent permitted taking into account
75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76 | is so judged Affirmer hereby grants to each affected person a royalty-free,
77 | non transferable, non sublicensable, non exclusive, irrevocable and
78 | unconditional license to exercise Affirmer's Copyright and Related Rights in
79 | the Work (i) in all territories worldwide, (ii) for the maximum duration
80 | provided by applicable law or treaty (including future time extensions), (iii)
81 | in any current or future medium and for any number of copies, and (iv) for any
82 | purpose whatsoever, including without limitation commercial, advertising or
83 | promotional purposes (the "License"). The License shall be deemed effective as
84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the
85 | License for any reason be judged legally invalid or ineffective under
86 | applicable law, such partial invalidity or ineffectiveness shall not
87 | invalidate the remainder of the License, and in such case Affirmer hereby
88 | affirms that he or she will not (i) exercise any of his or her remaining
89 | Copyright and Related Rights in the Work or (ii) assert any associated claims
90 | and causes of action with respect to the Work, in either case contrary to
91 | Affirmer's express Statement of Purpose.
92 |
93 | 4. Limitations and Disclaimers.
94 |
95 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
96 | surrendered, licensed or otherwise affected by this document.
97 |
98 | b. Affirmer offers the Work as-is and makes no representations or warranties
99 | of any kind concerning the Work, express, implied, statutory or otherwise,
100 | including without limitation warranties of title, merchantability, fitness
101 | for a particular purpose, non infringement, or the absence of latent or
102 | other defects, accuracy, or the present or absence of errors, whether or not
103 | discoverable, all to the greatest extent permissible under applicable law.
104 |
105 | c. Affirmer disclaims responsibility for clearing rights of other persons
106 | that may apply to the Work or any use thereof, including without limitation
107 | any person's Copyright and Related Rights in the Work. Further, Affirmer
108 | disclaims responsibility for obtaining any necessary consents, permissions
109 | or other rights required for any use of the Work.
110 |
111 | d. Affirmer understands and acknowledges that Creative Commons is not a
112 | party to this document and has no duty or obligation with respect to this
113 | CC0 or use of the Work.
114 |
115 | For more information, please see
116 |
117 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Awesome Git Hooks [](https://awesome.re)
2 |
3 | > A curated list of awesome [Git hooks](https://git-scm.com/docs/githooks)
4 |
5 | Git Hooks are scripts that run automatically every time a particular event occurs in a Git repository.
6 |
7 | ## Contents
8 | - [Useful Git Hooks scripts](#useful-git-hooks-scripts)
9 | - [Tools](#tools)
10 | - [Projects](#projects)
11 | - [Articles](#articles)
12 | - [Video Tutorials](#video-tutorials)
13 | - [Support](#support)
14 |
15 | ## Useful Git Hooks scripts
16 |
17 | - [pre-commit](https://github.com/aitemr/awesome-git-hooks/tree/master/pre-commit) - This hook is called before obtaining the proposed commit message.
18 | - [prepare-commit-msg](https://github.com/aitemr/awesome-git-hooks/tree/master/prepare-commit-msg) - Called after receiving the default commit message, just prior to firing up the commit message editor.
19 | - [pre-receive](https://github.com/aitemr/awesome-git-hooks/tree/master/pre-receive) - This is called on the remote repo just before updating the pushed refs.
20 | - [commit-msg](https://github.com/aitemr/awesome-git-hooks/tree/master/commit-msg) - Can be used to adjust the message after it has been edited in order to ensure conformity to a standard or to reject based on any criteria.
21 | - [pre-push](https://github.com/aitemr/awesome-git-hooks/tree/master/pre-push) - Called prior to a push to a remote. In addition to the parameters, additional information, separated by a space is passed in through stdin in the form of ` `.
22 | - [pre-auto-gc](https://github.com/aitemr/awesome-git-hooks/tree/master/pre-auto-gc) - Is used to do some checks before automatically cleaning repos.
23 | - [pre-rebase](https://github.com/aitemr/awesome-git-hooks/tree/master/pre-rebase) - Called when rebasing a branch. Mainly used to halt the rebase if it is not desirable.
24 | - [applypatch-msg](https://github.com/aitemr/awesome-git-hooks/tree/master/applypatch-msg) - Can edit the commit message file and is often used to verify or actively format a patch's message to a project's standards.
25 | - [post-receive](https://github.com/aitemr/awesome-git-hooks/tree/master/post-receive) - This is run on the remote when pushing after the all refs have been updated. It does not take parameters, but receives info through stdin in the form of ` `.
26 | - [post-rewrite](https://github.com/aitemr/awesome-git-hooks/tree/master/post-rewrite) - This is called when git commands are rewriting already committed data.
27 | - [post-commit](https://github.com/aitemr/awesome-git-hooks/tree/master/post-commit) - Called after a successful commit. Useful for triggering notifications, etc.
28 |
29 | ## Tools
30 |
31 | - [Husky](https://github.com/typicode/husky) - Git hooks made easy.
32 | - [Komondor](https://github.com/orta/Komondor) - Git Hooks for Swift projects.
33 | - [Quickhook](https://github.com/dirk/quickhook/) - Faster Git hook (pre-commit, etc.) runner.
34 | - [overcommit](https://github.com/brigade/overcommit/) - A fully configurable and extendable Git hook manager.
35 | - [Grunt GitHooks](https://github.com/wecodemore/grunt-githooks) - Setup, manage and update your hooks with Grunt. Can be used with all languages, supports templates.
36 | - [Autohook](https://github.com/nkantar/Autohook) - A very, very small Git hook manager with focus on automation.
37 | - [Githooks](https://github.com/rycus86/githooks) - Auto-install Git hook, that supports hooks in any language checked into Git and also shared repos.
38 | - [Hooks](https://www.npmjs.com/package/node-hooks) - A command line git hook management tool.
39 | - [Lefthook](https://github.com/Arkweid/lefthook) - Fast and powerful Git hooks manager for any type of projects.
40 | - [pre-commit](https://github.com/pre-commit/pre-commit) - A framework for managing and maintaining multi-language pre-commit hooks.
41 |
42 | ## Projects
43 |
44 | - [Lolcommits](https://github.com/mroth/lolcommits) - Takes a snapshot with your webcam every time you git commit code, and archives a lolcat style image with it.
45 | - [Podmena](https://github.com/bmwant/podmena) - Enhance your commit messages adding random emoji to it.
46 | - [Git::Hooks](https://github.com/gnustavo/Git-Hooks) - A framework for implementing Git (and Gerrit) hooks.
47 | - [App::GitHooks](https://metacpan.org/pod/App::GitHooks) - A modular and easy to configure git hooks framework, supporting many plugins.
48 | - [Jig](https://pythonhosted.org/jig/) - A pre-commit hook on steroids.
49 | - [GitPHPHooks](https://github.com/wecodemore/GitPHPHooks) - Write your hooks in PHP, manage and organize them on a task and project level. Has an additional Hooks library on GitHub.
50 | - [git-hooks-php](https://github.com/BernardoSilva/git-hooks-php) - Git hooks for PHP based projects.
51 | - [commandbox-githooks](https://github.com/elpete/commandbox-githooks) - Git hooks for CommandBox CFML based projects.
52 | - [hooks4git](https://pypi.org/project/hooks4git/) - A simple, flexible and language agnostic git hook management approach.
53 | - [Commit Colors](https://github.com/sparkbox/commit-colors) - See a color swatch in your terminal every time you author a commit.
54 |
55 | ## Articles
56 |
57 | - [Official Documentation](https://git-scm.com/docs/githooks)
58 | - [Git Hooks (Part I): The Basics](http://omerkatz.com/blog/2013/2/15/git-hooks-part-1-the-basics)
59 | - [Git Hooks (Part II): Implementing Git Hooks using Python](http://omerkatz.com/blog/2013/5/23/git-hooks-part-2-implementing-git-hooks-using-python)
60 | - [Atlassian Git Hooks tutorial](https://ru.atlassian.com/git/tutorials/git-hooks)
61 | - [Tips for using Git pre commit hook](https://codeinthehole.com/tips/tips-for-using-a-git-pre-commit-hook/)
62 | - [Use a boostrap shell script to use Git Hooks in Mac with PowerShell and with IntelliJ](https://wilsonmar.github.io/git-hooks/)
63 | - [githooks.com](https://githooks.com)
64 | - [How To Use Git Hooks To Automate Development and Deployment Tasks](https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks)
65 | - [Automate your workflow with git hooks
66 | ](https://medium.com/backticks-tildes/how-to-automate-your-git-workflow-with-git-hooks-c905296c49bc)
67 | - [Automate your development workflow](https://medium.com/the-andela-way/git-hooks-beautifully-automate-tasks-stages-bfb29f42fea1)
68 | - [Deploying websites with a Git hook](http://ryanflorence.com/deploying-websites-with-a-tiny-git-hook/)
69 | - [The missing Git hooks documentation](https://longair.net/blog/2011/04/09/missing-git-hooks-documentation/)
70 |
71 | ## Video Tutorials
72 |
73 | - [Introduction to Git Hooks](https://www.youtube.com/watch?v=8-JL6NOTZOw)
74 | - [Git hooks, practical uses (yes, even on Windows)](https://www.youtube.com/watch?v=fMYv6-SZsSo)
75 | - [Life’s better with Git hooks](https://www.youtube.com/watch?v=RG26-Iozg70)
76 | - [Husky and the Git Hooks](https://www.youtube.com/watch?v=EpxkBgd8yq8)
77 |
78 | ## Support
79 |
80 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new). If you want to contribute, please read the [guide](./contributing.md).
81 |
82 | ## License
83 |
84 | [](https://creativecommons.org/publicdomain/zero/1.0/)
85 |
86 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
87 |
--------------------------------------------------------------------------------
/applypatch-msg/README.md:
--------------------------------------------------------------------------------
1 | ## applypatch-msg
2 |
3 | Can edit the commit message file and is often used to verify or actively format a patch's message to a project's standards. A non-zero exit status aborts the commit.
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git am
9 | ```
10 |
11 | ## applypatch-msg git hooks for:
12 |
13 | * [applypatch-msg-check-log-message](https://github.com/aitemr/awesome-git-hooks/blob/master/applypatch-msg/applypatch-msg-check-log-message) - check the commit log message taken by applypatch from an e-mail message.
14 |
15 | ## support
16 |
17 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
18 |
19 | ## license
20 |
21 | [](https://creativecommons.org/publicdomain/zero/1.0/)
22 |
23 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/applypatch-msg/applypatch-msg-check-log-message:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # An example hook script to check the commit log message taken by
4 | # applypatch from an e-mail message.
5 |
6 | . git-sh-setup
7 | test -x "$GIT_DIR/hooks/commit-msg" &&
8 | exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
9 | :
--------------------------------------------------------------------------------
/commit-msg/README.md:
--------------------------------------------------------------------------------
1 | ## commit-msg
2 |
3 | Can be used to adjust the message after it has been edited in order to ensure conformity to a standard or to reject based on any criteria. It can abort the commit if it exits with a non-zero value
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git commit
9 | ```
10 |
11 | ## commit-msg git hooks for:
12 |
13 | * [commit-msg-jira](https://github.com/aitemr/awesome-git-hooks/blob/master/commit-msg/commit-msg-jira) - hook to validate for jira issue or the word merge.
14 |
15 | ## support
16 |
17 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
18 |
19 | ## license
20 |
21 | [](https://creativecommons.org/publicdomain/zero/1.0/)
22 |
23 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/commit-msg/commit-msg-jira:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # set this to your active development branch
4 | develop_branch="develop"
5 | current_branch="$(git rev-parse --abbrev-ref HEAD)"
6 |
7 | # only check commit messages on main development branch
8 | [ "$current_branch" != "$develop_branch" ] && exit 0
9 |
10 | # regex to validate in commit msg
11 | commit_regex='(wap-[0-9]+|merge)'
12 | error_msg="Aborting commit. Your commit message is missing either a JIRA Issue ('WAP-1111') or 'Merge'"
13 |
14 | if ! grep -iqE "$commit_regex" "$1"; then
15 | echo "$error_msg" >&2
16 | exit 1
17 | fi
--------------------------------------------------------------------------------
/contributing.md:
--------------------------------------------------------------------------------
1 | # Contribution Guidelines
2 |
3 | Please ensure your pull request adheres to the following guidelines:
4 |
5 | - Search previous suggestions before making a new one, as yours may be a duplicate.
6 | - Suggested packages should be tested and documented.
7 | - Make an individual pull request for each suggestion.
8 | - Additions should be added to the bottom of the relevant category.
9 | - New categories, or improvements to the existing categorization are welcome.
10 | - Keep descriptions short and simple, but descriptive.
11 | - Start the description with a capital and end with a full stop/period.
12 | - Check your spelling and grammar.
13 | - Make sure your text editor is set to remove trailing whitespace.
14 | - The pull request should have a useful title and include a link to the package and why it should be included.
15 |
16 | Thank you for your suggestions!
--------------------------------------------------------------------------------
/post-commit/README.md:
--------------------------------------------------------------------------------
1 | post-commit hooks:
2 | - [git-blame-ignore-style-formatting-post-commit-hook](https://github.com/devinrhode2/git-blame-ignore-style-formatting-post-commit-hook) - automatically add `style: foo` commits to `.git-blame-ignore-revs`
--------------------------------------------------------------------------------
/post-receive/README.md:
--------------------------------------------------------------------------------
1 | ## post-receive
2 |
3 | This is run on the remote when pushing after the all refs have been updated. It does not take parameters, but receives info through stdin in the form of " ". Because it is called after the updates, it cannot abort the process.
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git-receive-pack
9 | # on the remote repo
10 | ```
11 |
12 | ## post-receive git hooks for:
13 |
14 | * [post-receive-specific-folder](https://github.com/aitemr/awesome-git-hooks/blob/master/post-receive/post-receive-specific-folder) - hook to deploy the code being pushed to production branch to a specific folder.
15 |
16 | ## support
17 |
18 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
19 |
20 | ## license
21 |
22 | [](https://creativecommons.org/publicdomain/zero/1.0/)
23 |
24 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/post-receive/post-receive-specific-folder:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | target_branch="production"
4 | working_tree="PATH_TO_DEPLOY"
5 |
6 | while read -r oldrev newrev refname
7 | do
8 | branch=$(git rev-parse --symbolic --abbrev-ref "$refname")
9 | if [ -n "$branch" ] && [ "$target_branch" = "$branch" ]; then
10 |
11 | GIT_WORK_TREE=$working_tree git checkout $target_branch -f
12 | NOW=$(date +"%Y%m%d-%H%M")
13 | git tag "release_$NOW" $target_branch
14 |
15 | echo " /==============================="
16 | echo " | DEPLOYMENT COMPLETED"
17 | echo " | Target branch: $target_branch"
18 | echo " | Target folder: $working_tree"
19 | echo " | Tag name : release_$NOW"
20 | echo " \=============================="
21 | fi
22 | done
23 |
--------------------------------------------------------------------------------
/post-rewrite/README.md:
--------------------------------------------------------------------------------
1 | ## post-rewrite
2 |
3 | This is called when git commands are rewriting already committed data. In addition to the parameters, it receives strings in stdin in the form of " ".
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git commit --amend
9 | git-rebase
10 | ```
11 |
12 | ## post-rewrite git h ooks for:
13 |
14 | * [post-rewrite-move-refs](https://github.com/aitemr/awesome-git-hooks/blob/master/post-rewrite/post-rewrite-move-refs) - hook to make local refs move automatically on rewrites.
15 |
16 | ## support
17 |
18 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
19 |
20 | ## license
21 |
22 | [](https://creativecommons.org/publicdomain/zero/1.0/)
23 |
24 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/post-rewrite/post-rewrite-move-refs:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # Git "post-rewrite" hook to make local refs move automatically on rewrites.
3 | set -e -u
4 | command="$1"
5 |
6 | # On rebase, update-ref from ORIG_HEAD to new HEAD is done after this
7 | # hook ran. Updating it in this hook causes error due to mismatch of the
8 | # old hash. (The final update-ref uses 3 args form.)
9 | rebasing=''
10 | if [ "$command" = 'rebase' ]; then
11 | rebasing=$(git rev-parse ORIG_HEAD)
12 | fi
13 |
14 | handle_rewrite() {
15 | old="$1"
16 | new="$2"
17 | shift; shift;
18 | if [ "$old" != "$rebasing" ]; then
19 | what="$command"
20 | if [ $# -gt 0 ]; then
21 | what="$command($*)"
22 | fi
23 | for ref in $(git show-ref --heads | sed -n "s/^$old //p"); do
24 | git update-ref -m "post-rewrite: $what" "$ref" "$new" "$old"
25 | short_ref=$(git rev-parse --abbrev-ref "$ref")
26 | short_old=$(git rev-parse --short "$old")
27 | short_new=$(git rev-parse --short "$new")
28 | echo "post-rewrite: update-ref $short_ref $short_new (was: $short_old)"
29 | done
30 | fi
31 | }
32 | while read -r line; do handle_rewrite "$line"; done
33 |
34 | # TODO:
35 | # Print recommended rebase commands for each branch found by
36 | # "git branch --contains " as "git rebase ref --onto ".
37 |
--------------------------------------------------------------------------------
/pre-auto-gc/README.md:
--------------------------------------------------------------------------------
1 | ## pre-auto-gc
2 |
3 | Is used to do some checks before automatically cleaning repos.
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git gc --auto
9 | ```
10 |
11 | ## pre-auto-gc git hooks for:
12 |
13 | * [pre-auto-gc-battery](https://github.com/aitemr/awesome-git-hooks/blob/master/pre-auto-gc/pre-auto-gc-battery) - script to verify if you are on battery.
14 |
15 | ## support
16 |
17 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
18 |
19 | ## license
20 |
21 | [](https://creativecommons.org/publicdomain/zero/1.0/)
22 |
23 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/pre-auto-gc/pre-auto-gc-battery:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # An example hook script to verify if you are on battery, in case you
4 | # are running Linux or OS X. Called by git-gc --auto with no arguments.
5 | # The hook should exit with non-zero status after issuing an appropriate
6 | # message if it wants to stop the auto repacking.
7 |
8 | if test -x /sbin/on_ac_power && /sbin/on_ac_power
9 | then
10 | exit 0
11 | elif test "$(cat /sys/class/power_supply/AC/online 2>/dev/null)" = 1
12 | then
13 | exit 0
14 | elif grep -q 'on-line' /proc/acpi/ac_adapter/AC/state 2>/dev/null
15 | then
16 | exit 0
17 | elif grep -q '0x01$' /proc/apm 2>/dev/null
18 | then
19 | exit 0
20 | elif grep -q "AC Power \+: 1" /proc/pmu/info 2>/dev/null
21 | then
22 | exit 0
23 | elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |
24 | grep -q "Currently drawing from 'AC Power'"
25 | then
26 | exit 0
27 | fi
28 |
29 | echo "Auto packing deferred; not on AC"
30 | exit 1
--------------------------------------------------------------------------------
/pre-commit/README.md:
--------------------------------------------------------------------------------
1 | ## pre commit
2 |
3 | This hook is called before obtaining the proposed commit message. Exiting with anything other than zero will abort the commit. It is used to check the commit itself (rather than the message).
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git commit
9 | ```
10 |
11 | ## pre commit git hooks for:
12 |
13 | * [SwiftLint](https://github.com/aitemr/awesome-git-hooks/blob/master/pre-commit/pre-commit-swiftlint) - a tool to enforce Swift style and conventions.
14 |
15 | ## support
16 |
17 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
18 |
19 | ## license
20 |
21 | [](https://creativecommons.org/publicdomain/zero/1.0/)
22 |
23 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/pre-commit/pre-commit-swiftlint:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Git Hook for SwiftLint
4 | # Runs at every commit and checks for an error.
5 | # For the test, you can run `git commit` with an empty` commit message`
6 |
7 | export PATH=/usr/local/bin:$PATH
8 |
9 | LINT=$(command -v swiftlint)
10 |
11 | if [[ -e "${LINT}" ]]; then
12 | echo "SwiftLint Start..."
13 | echo "$PWD"
14 | else
15 | echo "SwiftLint does not exist, download from https://github.com/realm/SwiftLint"
16 | exit 1
17 | fi
18 |
19 | RESULT=$($LINT lint --quiet --config .swiftlint.yml)
20 |
21 | if [ -z "$RESULT" ]; then
22 | printf "SwiftLint Finished.\n"
23 | else
24 | echo ""
25 | printf "SwiftLint Failed. Please check below:\n"
26 |
27 | while read -r line; do
28 | FILEPATH=$(echo "$line" | cut -d : -f 1)
29 | L=$(echo "$line" | cut -d : -f 2)
30 | C=$(echo "$line" | cut -d : -f 3)
31 | TYPE=$(echo "$line" | cut -d : -f 4 | cut -c 2-)
32 | MESSAGE=$(echo "$line" | cut -d : -f 5 | cut -c 2-)
33 | DESCRIPTION=$(echo "$line" | cut -d : -f 6 | cut -c 2-)
34 | printf '\n %s\n' "$TYPE"
35 | echo " $FILEPATH:$L:$C"
36 | echo " $MESSAGE - $DESCRIPTION"
37 | done <<< "$RESULT"
38 |
39 | printf "\nCOMMIT ABORTED. Please fix them before commiting.\n"
40 |
41 | exit 1
42 | fi
43 |
--------------------------------------------------------------------------------
/pre-push/README.md:
--------------------------------------------------------------------------------
1 | ## pre push
2 |
3 | Called prior to a push to a remote. In addition to the parameters, additional information, separated by a space is passed in through stdin in the form of " ". Parsing the input can get you additional information that you can use to check. For instance, if the local sha1 is 40 zeros long, the push is a delete and if the remote sha1 is 40 zeros, it is a new branch. This can be used to do many comparisons of the pushed ref to what is currently there. A non-zero exit status aborts the push.
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git push
9 | ```
10 |
11 | ## pre push git hooks for:
12 |
13 | * [pre-push](https://github.com/aitemr/awesome-git-hooks/blob/master/pre-push/pre-push-protect-branches) - Git pre-push hook to prevent force pushing master branch.
14 |
15 | ## support
16 |
17 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
18 |
19 | ## license
20 |
21 | [](https://creativecommons.org/publicdomain/zero/1.0/)
22 |
23 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/pre-push/pre-push-protect-branches:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # Prevents force-pushing to master
3 |
4 | BRANCH=$(git rev-parse --abbrev-ref HEAD)
5 | PUSH_COMMAND=$(ps -ocommand= -p $PPID)
6 | PROTECTED_BRANCHES="^(master|dev|release-*|patch-*)"
7 | FORCE_PUSH="force|delete|-f"
8 |
9 | if [[ "$BRANCH" =~ $PROTECTED_BRANCHES && "$PUSH_COMMAND" =~ $FORCE_PUSH ]]; then
10 | echo "Prevented force-push to protected branch \"$BRANCH\" by pre-push hook"
11 | exit 1
12 | fi
13 |
14 | exit 0
15 |
--------------------------------------------------------------------------------
/pre-rebase/README.md:
--------------------------------------------------------------------------------
1 | ## pre-rebase
2 |
3 | Called when rebasing a branch. Mainly used to halt the rebase if it is not desirable.
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git rebase
9 | ```
10 |
11 | ## pre-rebase git hooks for:
12 |
13 | * [pre-rebase-rebaselock](https://github.com/aitemr/awesome-git-hooks/blob/master/pre-rebase/pre-rebase-rebaselock) - refuses to rebase if "branch.${BRANCH}.rebaselock" is true.
14 |
15 | ## support
16 |
17 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
18 |
19 | ## license
20 |
21 | [](https://creativecommons.org/publicdomain/zero/1.0/)
22 |
23 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/pre-rebase/pre-rebase-rebaselock:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # The hook is called with the following parameters:
3 | #
4 | # $1 -- the upstream the series was forked from.
5 | # $2 -- the branch being rebased (or empty when rebasing the current branch).
6 | #
7 | branch="$2"
8 | [ -n "$branch" ] || branch=$(git rev-parse --abbrev-ref HEAD)
9 | lock="branch.${branch}.rebaselock"
10 | if [ "$(git config --bool "$lock")" = true ]; then
11 | echo "pre-rebase hook: \"$lock\" is set to true. Refusing to rebase."
12 | exit 1
13 | fi
14 |
--------------------------------------------------------------------------------
/pre-receive/README.md:
--------------------------------------------------------------------------------
1 | ## pre receive
2 |
3 | This is called on the remote repo just before updating the pushed refs. A non-zero status will abort the process. Although it receives no parameters, it is passed a string through stdin in the form of " " for each ref.
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git-receive-pack
9 | # on the remote repo
10 | ```
11 |
12 | ## pre receive git hooks for:
13 |
14 | * [Push Ban](https://github.com/aitemr/awesome-git-hooks/blob/master/pre-receive/pre-receive-ban-on-push-to-branch) - Git Hook for ban on push to master branch.
15 |
16 | ## support
17 |
18 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
19 |
20 | ## license
21 |
22 | [](https://creativecommons.org/publicdomain/zero/1.0/)
23 |
24 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
25 |
--------------------------------------------------------------------------------
/pre-receive/pre-receive-ban-on-push-to-branch:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # Git Hook for ban on push to master branch
3 |
4 | changedBranch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
5 | # Add blocked user username
6 | blockedUsers=(junior1 junior2)
7 |
8 | if [[ ${blockedUsers[*]} =~ $USER ]]; then
9 | if [ "$changedBranch" == "master" ]; then
10 | echo "You are not allowed commit changes in this branch"
11 | exit 1
12 | fi
13 | fi
14 |
--------------------------------------------------------------------------------
/prepare-commit-msg/README.md:
--------------------------------------------------------------------------------
1 | ## prepare-commit-msg
2 |
3 | Called after receiving the default commit message, just prior to firing up the commit message editor. A non-zero exit aborts the commit. This is used to edit the message in a way that cannot be suppressed.
4 |
5 | ## invoked by
6 |
7 | ```bash
8 | git commit
9 | ```
10 |
11 | ## prepare-commit-msg git hooks for:
12 |
13 | * [Jira](https://github.com/aitemr/awesome-git-hooks/blob/master/prepare-commit-msg/prepare-commit-msg-jira) - a proprietary issue tracking product developed by Atlassian.
14 |
15 | ## support
16 |
17 | If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new).
18 |
19 | ## license
20 |
21 | [](https://creativecommons.org/publicdomain/zero/1.0/)
22 |
23 | To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
--------------------------------------------------------------------------------
/prepare-commit-msg/prepare-commit-msg-jira:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Git Hook for JIRA_TASK_ID
4 | # Adds to the top of your commit message `JIRA_TASK_ID`, based on the prefix of the current branch `feature/AWG-562-add-linter`
5 | # Example: `Add SwiftLint -> `AWG-562 Add SwiftLint
6 |
7 | if [ -z "$BRANCHES_TO_SKIP" ]; then
8 | BRANCHES_TO_SKIP='master develop test'
9 | fi
10 |
11 | CURRENT_BRANCH=$(git branch --show-current)
12 | for BRANCH in $BRANCHES_TO_SKIP; do
13 | if [ "$BRANCH" = "$CURRENT_BRANCH" ]; then
14 | echo "Info, skipping Jira ID check since current branch is included in the 'BRANCHES_TO_SKIP' variable"
15 | exit 0
16 | fi
17 | done
18 |
19 | COMMIT_FILE=$1
20 | COMMIT_MSG=$(cat "$1")
21 | CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
22 | JIRA_ID_REGEX="[A-Z0-9]{1,10}-?[A-Z0-9]+"
23 | JIRA_ID_IN_CURRENT_BRANCH_NAME=$(echo "$CURRENT_BRANCH" | { grep -Eo "$JIRA_ID_REGEX" || true; })
24 | JIRA_ID_IN_COMMIT_MESSAGE=$(echo "$COMMIT_MSG" | { grep -Eo "$JIRA_ID_REGEX" || true; })
25 |
26 | if [ -n "$JIRA_ID_IN_COMMIT_MESSAGE" ]; then
27 | if [ "$JIRA_ID_IN_COMMIT_MESSAGE" != "$JIRA_ID_IN_CURRENT_BRANCH_NAME" ]; then
28 | echo "Error, your commit message JIRA_TASK_ID='$JIRA_ID_IN_COMMIT_MESSAGE' is not equal to current branch JIRA_TASK_ID='$JIRA_ID_IN_CURRENT_BRANCH_NAME'"
29 | exit 1
30 | fi
31 | elif [ -n "$JIRA_ID_IN_CURRENT_BRANCH_NAME" ]; then
32 | echo "$JIRA_ID_IN_CURRENT_BRANCH_NAME $COMMIT_MSG" > "$COMMIT_FILE"
33 | echo "JIRA ID '$JIRA_ID_IN_CURRENT_BRANCH_NAME', matched in current branch name, prepended to commit message. (Use --no-verify to skip)"
34 | fi
35 |
--------------------------------------------------------------------------------