using jgit with railo

42 views
Skip to first unread message

Michael Sprague

unread,
Feb 22, 2012, 12:50:29 PM2/22/12
to ra...@googlegroups.com
I've been trying to get some Git integration set up via CFML on Railo and am wondering if anyone here has worked with jGit before.. I have tried adding jGit to the classpath and loading it via the javaloader cfc and I can't seem to get anything past that working. I found the documentation here ( http://wiki.eclipse.org/JGit/User_Guide#Repository ) but it doesn't help me much with getting started. 

Right now I just want to pass in the local directory of the repository and do a git status which seems like it should be simple enough but I think my lack of Java experience is getting in the way. Does anyone have any advice or experience setting this up? Thanks in advance.

Peter Boughton

unread,
Feb 22, 2012, 8:01:28 PM2/22/12
to ra...@googlegroups.com
I've tried using jGit before but got nowhere, so gave up and used a
shell script.


If all you need is "git status" you don't even need a script.

You can't do what I was initially thinking ("cd #Dir# && git status" -
works from command line but cfexecute complains that 'cd' isn't a
program), but what you can do is tell git to look at a different
directory like this:

<cfexecute
variable = "GitStatus"
name = "git --work-tree=#Dir# --git-dir=#Dir#/.git status"
timeout = 2
/>

(On Windows, if you don't have git on the path, you'll need
"C:\Program Files (x86)\Git\bin\git" there instead.)

Randy Merrill

unread,
Feb 22, 2012, 8:18:01 PM2/22/12
to ra...@googlegroups.com
I agree with peter,

I tried to use jGit but when I tried it you needed to understand all the internals of how git works to even do anything.

So I opted for the execute. Someday if jGit is actually usable I would like to use it since it would be nice to get information back from it without having to parse it.

If you do get jGit working let us know how :)
--
Randy Merrill

Michael Sprague

unread,
Feb 22, 2012, 8:28:25 PM2/22/12
to ra...@googlegroups.com
I had tried using cfexecute previously but didn't know how to pass the directory in. I just tested Peter's code and that did the trick. Thanks, Peter.

Long story short, I just want to write a commit hook for the main repository so when we push changes there it will update a testing server without having to ssh or remote in to do it. 

At some point I'd like to do some more complex work with it so hopefully jGit will become a bit more user friendly in future releases.

Thanks for the replies.

Mike

Denny

unread,
Feb 23, 2012, 7:47:32 PM2/23/12
to ra...@googlegroups.com
I've got two extensions for jGit-- one that uses the "deep down" API and
isn't very functional, and one that uses the CLI jar, which does
everything that the CLI can do, pretty much (forced checkouts were not
working last I checked, but I haven't updated it in a bit).

They should be in github before too long (in assembla somewhere right
now, I think).

:Denny


--
Railo Technologies: getrailo.com Professional Open Source
Skype: valliantster (505)510.1336 de...@getrailo.com
GnuPG-FP: DDEB 16E1 EF43 DCFD 0AEE 5CD0 964B B7B0 1C22 CB62

Michael Sprague

unread,
Feb 23, 2012, 7:56:25 PM2/23/12
to ra...@googlegroups.com
I'd be interested in checking out both once they're available. If you don't mind, please reply here once they are.

Thanks,

Mike

GB

unread,
Feb 23, 2012, 9:46:06 PM2/23/12
to Railo
I've been using the cfexecute method for git commands as well. I've
been doing it like this:

<cfexecute name="/bin/bash" arguments="-c 'cd -P #ExpandPath('/')#;
git rev-parse --short HEAD'" variable="server.codeversion"
timeout="1" />

This gets the latest short git log hash into a variable, which I then
tack onto my CSS link tags like this:

<link type="text/css" rel="stylesheet" href="/styles/global.css?
v=<cfoutput>#server.codeversion#</cfoutput>">

But I've been reading places that say that cfexecute has a lot of
overhead/cost so it should be run on every page request. I have this
inside a function that runs onApplicationStart or whenever I pass in a
specific url parameter - which I would run once after each deployment
to reinitialize certain global variables and functions.


I'd be interested in jgit too. I'll look into it and post back here if
I get anything working.

Denny

unread,
Feb 24, 2012, 3:05:53 PM2/24/12
to ra...@googlegroups.com
On 2/23/12 5:56 PM, Michael Sprague wrote:
> I'd be interested in checking out both once they're available. If you
> don't mind, please reply here once they are.
>

I'll holler when they're in their own project in github, but FWIW, using
the CLI jar is as easy as calling the main method with the arguments
you'd pass the command line executable.

It'll be bundled up into an extension though, so you won't have to
bother finding/installing jars, etc..

:Denny

Michael Sprague

unread,
Feb 24, 2012, 3:34:15 PM2/24/12
to ra...@googlegroups.com

Cool, I may try playing around with the CLI jar this weekend then. Thanks, and looking forward to checking out the extensions.

Mike

Reply all
Reply to author
Forward
0 new messages