Question
· Aug 29, 2017

Are there server-side Git Studio Hooks available out there?

I want to demonstrate using Git via Server-side Source Control hooks (to allow both Studio and Atelier to access a Shared Dev namespace), and I was planning to use the popular Caché Git hooks:

https://github.com/intersystems/cache-tort-git 

Unfortunately, when I installed and configured them I realized that they will not work in a Shared Dev configuration because those hooks rely on calling the TortoiseGit Windows executable, which means that your IDE and your Caché instance must both be running on the same machine (this doesn't make sense for Shared Dev configurations).

Can anyone point me to examples of Git hooks for Studio which do not rely on calling a UI executable, but rather rely on the CLI for Git so they can run on a different machine than the IDE?

Thanks in advance for any suggestions you can offer.

Ben

Discussion (7)1
Log in or sign up to continue

Hello Benjamin,

This is how I binded a class to some git cli commands on the earlier versions of my project.

The main tip here is to use ZF along with ">" to output the result to a file. This way you can make Caché aware about what happened when the command was executed.


You'll notice that you can even create a custom query for operations like log, diff, etc.

If you don't want with the logic behind the outputs, you can simply use RunCommandViaZF from %Net.Remote.Utility.
But remember that older versions haven't this method.

Also, when reading the command string you'll notice a lot of {PLACEHOLDERS}. You don't need to implement it to work, just rewrite it to use static parameters instead.

They are:

{VCS} - The absolute path to the git executable.

{SLASH} - The resolution from \ or / depending the OS.
{Pn} - Where n is a sequential number, they are the parameters needed to call the command.

And finally, here's a sample:

do $zf(-1, "C:\Program Files (x86)\Git\bin\git.exe --work-tree="C:\Projects\Test" --git-dir=C:\Projects\Test\.git add cls 2> ""outputfilepath"" > ""errorfilepath""")

Sadly I haven't the code with me anymore. because it was a a feature implemented on another branch, that's why I posted a Gist instead. I used it to preserve the important implementation parts since I deleted the branch. Check my post again to understand better regarding the placeholders.

Port.SourceControl.Extension.VCS is quite simple actually, %OnNew initialize two temp files path that serve as output and error feedback, inheriting classes use those files as parameters along with >.

It doesn't, at least not directly. I used it for boosting the comparison speed by using git diff.

 

The idea as a whole was:

diff - whenever the user selected the "Import" from the Source Control menu, it would run git diff instead, if git was installed and the current project is versioned (has .git).

add - automatically add modified and new files to the staging area whenever the item is saved on Studio.

I ended up dropping those ideas because I noticed I was wasting resources as it need to be less exploitable and it also went against my objective of creating something agnostic to version control systems.

If you want to see the result, here's the project in question.