Domanda

I've been looking for this for quite a while myself, but I have nearly no experience with the subject, so I'm just hoping that someone here has come across this before.

Would it be possible to run some kind of a script in SourceTree, which would check the files for some criteria (for example, going through the files checking if "StaticMethodX." is used anywhere and failing the commit attempt if it is?

I'm trying to enforce better coding standards within a team.

Any help is highly appreciated.

È stato utile?

Soluzione

You can either:

  • ask your client to use a pre-commit hook (also presented in this article or illustrated in this question), but they can bypass it if they want

  • or you can set up a pre-receive hook which will deny the push on the server side if your policy isn't followed.
    It would use git diff-index --cached --name-only, as in this question to get the content of each file pushed.

The server-side approach is generally favored, as it is easier to deply, maintain and enforce.

Altri suggerimenti

Try npm pre-git which allows you to run commmands on pre-commit and pre-push. Than open sourcetree using Terminal with following command

open /Applications/SourceTree.app/Contents/MacOS/SourceTree

Now you try to commit and push, sourcetree will run pre-commit and pre-push hooks.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top