Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a "Precommit hook" on TFS?

We want every person that does a push in our git repository to run "grunt" before this is done. We enforce this by having a pre-push hook in .git/hooks/pre-push and writing npm install and grunt in that file.

We also have a TFS repository. I am looking for similar logic to be used here. Meaning, we want a sort of "Gated check-in" when someone tries to check something in. This will only starts up PowerShell and runs npm install and grunt locally.

We don't want TFS to do anything else (run build, run tests etc. (all this is done in the grunt task)).

Is this possible? Anyone know how?

like image 245
user3086725 Avatar asked Feb 19 '15 12:02

user3086725


People also ask

How do I add a Precommit to a Git hook?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

Where are pre-commit hooks stored?

The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that's . git/hooks .

How do pre-commit hooks work?

pre-commit hooks are a mechanism of the version control system git. They let you execute code right before the commit. Confusingly, there is also a Python package called pre-commit which allows you to create and use pre-commit hooks with a way simpler interface.

Does GitHub support server side hooks?

You can test a pre-receive hook script locally before you create or update it on your GitHub Enterprise Server instance.


1 Answers

TFS has nothing to do with what you do locally. You can add as many pre-commit hooks to your repo and push them to TFS. TFS will happily store these hook scripts. ANd when you are using a client that supports them, that client will execute them pre-commit.

But if you expect Visual Studio to run these hooks before commit, you're probably out of luck. There is no "check-in policy" support for Visual Studio when connected to Git. Nor in any other Git client based on LibGit2 at present as far as I can tell.

You could setup a branch policy linked to a CI build, effectively running the grunt tasks on a build server, but I understand this is not what you want. .

There's some background available on the LibGit2 issue section, which is what Visual Studio uses to implement its git functionality. And this corresponding user voice item for Visual Studio. As well as a discussion on the GitHub for Windows client which uses the same underlying library.

like image 140
jessehouwing Avatar answered Sep 25 '22 20:09

jessehouwing