3

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?

avi_panday
  • 67
  • 1
  • 3
  • 13
  • Must it be during `git push` ? Or are you also open to blocking it on `commit` ? Because this might help: [Git hook to reject commits where files contain a specific string](https://stackoverflow.com/q/26835998/2745495). – Gino Mempin May 10 '19 at 01:35

2 Answers2

4

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.

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
2

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.

monday
  • 21
  • 4
  • 3
    Maybe better to use a server side `pre-receive` hook. That way, hook would execute even if someone is trying to push without having a `pre-commit`/`pre-push` hook in their local repo. – Alderath May 10 '19 at 07:27
  • 2
    @Alderath, you are right. However, if the git repo is hosted in GitHub.com, GitLab.com or most of the public repo host services, [they won't allow server-side hooks](https://stackoverflow.com/questions/22100581/github-server-side-git-hooks-i-e-pre-commit-and-post-commit). – monday May 10 '19 at 08:29