Andy Jarrett // Code. Develop. Create.

CFGit (coldfusion and Git. get it?)

I wish I could be more original with project names, anyway ... this is just anexperiment I was playing around with tonight and I wanted to share before I left it in folder oblivion. At the moment it is a rather bare bones CFC for talking to Git. You can run currentlyon run:
* Status
* Log
* Show
* But you can easily add more

The benefit (which is where the idea started) is that you don't have to be inthe git project to run this!

I've only tested on a Mac w/CF9 so would be glad for any feed back on other platforms or suggestions!

Below is the CFC code alone but if you want to check it all out (an index.cfm and Readme.txt file, thats it!) check out: github.com/andyj/CFGit

<cfcomponent displayname="cfgit" hint="I interact with git" output="false"><cfproperty name="git_path" displayname="Git path" hint="On *nix system you can find the git to path by running $which git" type="string" /> <cfproperty name="git_folder" displayname="Repository folder" hint="I am the folder you are going to query" type="string" /><cffunction name="init" access="public" output="false" returntype="any"> <cfargument name="argGit_path" type="string" required="true"> <cfargument name="arggit_folder" type="string" required="true"> <cfscript> setGit_path( argGit_path ); setgit_folder( arggit_folder ); return this; </cfscript></cffunction><cffunction name="log" access="public" output="false" returntype="any"> <cfargument name="argN" type="numeric" default="5" hint="Limits the number of commits to show" /> <cfif len( trim( argN )) AND isValid( "integer", argN )> <cfset argN = "-n " & argN> </cfif> <cfreturn execGit( "log", argN )></cffunction><cffunction name="show" access="public" output="false" returntype="any"> <cfreturn execGit( "show" )></cffunction><cffunction name="status" access="public" output="false" returntype="any"> <cfreturn execGit( "status" )></cffunction><cffunction name="execGit" access="private" output="false" returntype="string"> <cfargument name="argCommand" required="true" type="string"> <cfargument name="argArguments" required="true" type="string"> <cfset var local = {} /> <cfexecute name = "#getGit_path()#" arguments = "--git-dir=#getgit_folder()# #argCommand# #argArguments#" timeout = "1" variable="local.out" errorvariable="local.err"> </cfexecute> <cfif len( trim( local.err ) )> <cfreturn '' & local.err & ""> <cfelse> <cfreturn local.out> </cfif></cffunction><cffunction name="getGit_path" access="public" output="false" returntype="string"> <cfreturn git_path></cffunction><cffunction name="setGit_path" access="private" output="false" returntype="void"> <cfargument name="argGit_path" type="any"> <cfset git_path=argGit_path/></cffunction><cffunction name="getgit_folder" access="public" output="false" returntype="string"> <cfreturn git_folder></cffunction><cffunction name="setgit_folder" access="private" output="false" returntype="void"> <cfargument name="arggit_folder" type="any"> <cfscript> // makse sure there is a trailing slash if( right( arggit_folder, 1) NEQ "/"){ arggit_folder = arggit_folder & "/"; } arggit_folder = arggit_folder & ".git"; git_folder=arggit_folder; </cfscript> </cffunction></cfcomponent>

I’m here, learning and working away. If you liked this content and want to keep me going, consider buying me a coffee. Your support keeps this site running and the coffee brewing! ☕️