avi_panday
avi_panday

Reputation: 67

How to reject git push based on some rule

In our repository, we have instructed all developers not include one keyword (which is ops$abc) prefixed database objects. For example for "update ops$abc.tablename ." we have instructed to use update tablenane .

But developers are making this kind of mistake. Is there any way to reject push to the branch having this kind of code?

Upvotes: 3

Views: 3963

Answers (2)

monday
monday

Reputation: 21

you could use git hooks feature to achieve this. BUT, it requires each developer to setup the ./.git/hooks/pre-commit manually. Or you could create a shell script for developers in the repository to copy a pre-commit file into ./.git/hooks.

No matter what, it requires developers cooperation.

Upvotes: 2

Aaron Brager
Aaron Brager

Reputation: 66282

You can use GitHub protected branches:

  1. Set your master or release branch as protected.
  2. Add an automated test that fails if developers use update ops$abc.tablename.
  3. Configure your CI server to run the automated tests when a GitHub pull request is opened.

Now developers won't be able to merge pull requests (or commit directly to the protected branch) with this change.

Upvotes: 4

Related Questions