Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » JGit/Ant integration(JGit/Ant integration)
JGit/Ant integration [message #1312968] Thu, 24 April 2014 12:14 Go to next message
R Shapiro is currently offline R Shapiro
Messages: 386
Registered: June 2011
Senior Member
I'm looking for a very simple Ant target that will let me set an Ant property to a SHA, given the root of a local clone and a reference (eg "HEAD"). If I could get the concise form of the SHA, rather than the full form, that would be icing on the cake.

Does such a thing already exist as part of JGIt? I definitely don't want to re-invent this wheel, but none of the search results I've seen so far appear to do this.

Re: JGit/Ant integration [message #1315480 is a reply to message #1312968] Fri, 25 April 2014 21:07 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias Sohn
Messages: 548
Registered: July 2009
Senior Member
this snippet should create a string for the shortened SHA for HEAD:

File gitDir = new File("/path/to/repo/.git");
Repository repo = FileRepositoryBuilder.create(gitDir);
ObjectId objectId = repo.resolve("HEAD");
ObjectReader reader = db.newObjectReader();
String sha = null;
try {
sha = reader.abbreviate(objectId).name();
} finally {
reader.release();
}
Re: JGit/Ant integration [message #1316508 is a reply to message #1315480] Sat, 26 April 2014 11:09 Go to previous messageGo to next message
R Shapiro is currently offline R Shapiro
Messages: 386
Registered: June 2011
Senior Member
The reader.abbreviate call will certainly be useful if I have to build an Ant target from scratch. But I'm hoping someone has already created Ant jar that knows how to invoke JGit.
Re: JGit/Ant integration [message #1316667 is a reply to message #1316508] Sat, 26 April 2014 13:18 Go to previous messageGo to next message
R Shapiro is currently offline R Shapiro
Messages: 386
Registered: June 2011
Senior Member
Since there were no responses suggesting that ant tools were already available for use with jgit I wrote my own, stealing a pattern from svntask, (googlecode [project written by Jon Stevens)

Currently it only does one thing I need right now: setting an Ant property to the abbreviated SHA of the current HEAD.

It's a simple matter to add more operations, pretty much anything JGit supports.

If anyone is interested in playing around with this, speak up here, I'll put it on github.
Re: JGit/Ant integration [message #1316997 is a reply to message #1316667] Sat, 26 April 2014 17:40 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias Sohn
Messages: 548
Registered: July 2009
Senior Member
Are you aware of the org.eclipse.jgit.ant bundle [1] which provides a few basic jgit commands as ant tasks ?
So feel free to contribute enhancements for this bundle Wink

[1] https://git.eclipse.org/c/jgit/jgit.git/tree/org.eclipse.jgit.ant
Re: JGit/Ant integration [message #1317423 is a reply to message #1316997] Sat, 26 April 2014 23:31 Go to previous messageGo to next message
R Shapiro is currently offline R Shapiro
Messages: 386
Registered: June 2011
Senior Member
I was not aware of jgit.ant, thanks for the pointer. I guess this repo is the answer to my original question.
It doesn't appear have the operation I need but I could certainly add it easily enough.

What's the clone URL for this repository, and what kind of registration do I need to do to be able to push to it?
Re: JGit/Ant integration [message #1318861 is a reply to message #1317423] Sun, 27 April 2014 19:08 Go to previous message
Matthias Sohn is currently offline Matthias Sohn
Messages: 548
Registered: July 2009
Senior Member
It's one of the many projects contained in the jgit repository
Previous Topic:jgit Ref for a relative references
Next Topic:Troubles installing Egit
Goto Forum:
  


Current Time: Thu Jul 31 21:48:43 EDT 2014

Powered by FUDForum. Page generated in 0.01877 seconds