JGit TagCommand [message #1004827] |
Thu, 24 January 2013 00:06 |
Gurce Isikyildiz Messages: 6 Registered: April 2012 |
Junior Member |
|
|
Hi,
I'm using JGit to build a tailored GUI app. I'm currently experiencing problems with the TagCommand, I use it as follows:
- In my GUI, I have a list of past commits, generated via calling git.log().all().call() which returns a List<RevCommit> collection.
I want to allow the user to tag any one of these prior commits by right-clicking it and entering a tag name.
Once provided a name, I then execute the following JGit code to try apply the requested tag.
Git git = new Git(gitrepo);
org.eclipse.jgit.api.TagCommand tagcmd = git.tag();
tagcmd. setObjectId(revcmt);
tagcmd.setName(strTag);
System.out.println("revid = " + tagcmd.getObjectId().getId().toString());
try
{
Ref ref = tagcmd.call();
System.out.println("refid = " + ref.getObjectId().toString());
} catch (Exception ex)
{
parent.setErrMsg(ex);
return;
}
The only problem here is that when I refresh my list of commits (via git.log().all().call() again), I get the following exception:
SEVERE: null
org.eclipse.jgit.errors.IncorrectObjectTypeException: Object b7607418fae91345b3941532ad3ce2e94907a9d8 is not a commit.
at org.eclipse.jgit.storage.file.WindowCursor.open(WindowCursor.java:130)
at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes(RevWalk.java:861)
at org.eclipse.jgit.revwalk.RevCommit.parseHeaders(RevCommit.java:142)
at org.eclipse.jgit.revwalk.RevWalk.markStart(RevWalk.java:284)
at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:297)
at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:172)
at org.eclipse.jgit.api.LogCommand.all(LogCommand.java:245)
I think the object it is complaining about is the newly created tag, which I called "test1" in this example.
My two debug println's in the above code show the following:
revid = commit a7c533ff99c2b34b42991bccf6b901f4b6b8875a 1357769853 ----sp
refid = AnyObjectId[b7607418fae91345b3941532ad3ce2e94907a9d8]
Ie, "refid" is the id of tag, which equates to the id the exception is complaining about.
I found the tag object within the ".git/" sub-folder of the project in the following location:
.git/refs/tags/test1
Its contents is: b7607418fae91345b3941532ad3ce2e94907a9d8
Hmm, but now, I try something from the command-line as a test:
git tag -d test1 (to remove the tag)
git tag test1 a7c533ff99c2b34b42991bccf6b901f4b6b8875a (ie, make a tag called "test1" on the rev-id I intended it for)
This time, when I edit ".git/refs/tags/test1", it contains: a7c533ff99c2b34b42991bccf6b901f4b6b8875a
Ie:
- When I add a tag via JGit, this ".git/refs/tags/test1" file contains the Id of the tag itself
- When I add a tag via command-line git, this ".git/refs/tags/test1" file contains the Id of the commit that the tag is associated with
Anyone know what's going on here? Is it a bug? Or am I making use of JGit in the wrong way?
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02748 seconds