JGIT Pull NoHeadException - java

When is try to execute the following method (uses JGIT library)
private void pullRepo() throws IOException,GitAPIException, WrongRepositoryStateException, InvalidConfigurationException, DetachedHeadException, InvalidRemoteException, CanceledException, RefNotFoundException, NoHeadException{
Git git = new Git(localRepo);
git.pull().call();
}
I get the following runtime exception:
org.eclipse.jgit.api.errors.NoHeadException: Pull on repository without HEAD currently not supported
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:161)
Does someone know how to solve this?
The localRepo I use is the same as I use for the cloneRepository method ,which works perfectly.
thanks,
bgvv1983

Think I found my mistake.
was on the wrong level in my project folder.
I was at the ../project (which works in your shell) level in stead of ../project/.git level.

Related

How to create a merge request using Gitlab4J?

I made some changes to my project and commited them using JGit, I'm wokring on Gitlab! Usually when we do this manually, Gitlab generates a popup at the top of the repository that requests for the creation of a merge request. I used Gitlab4J for cloning my repositories and I noticed that there's also an API for the merge requests, does anyone knows how to use it?
I figured out how to do it, here's the code snippet:
GITLAB.getMergeRequestApi().createMergeRequest(
projectIdOrPath,
sourceBranch,
targetBranch,
title,
description,
assigneeId)
If you want to recover the projectIdOrPath using your local repository you can add this code snippet that uses JGit and Gitlab4J ProjectApi:
private Project getProject(Git localRepo) throws GitLabApiException {
return GITLAB.getProjectApi().getProjects().parallelStream()
.filter(p -> p.getHttpUrlToRepo()
.equals(localRepo.getRepository().getConfig().getString("remote", "origin", "url")))
.findAny().orElse(null);
}
And for the assigneeId you can get it using this code snippet which uses the approver's username:
GITLAB.getUserApi().getUser(approver).getId()

SVNKIT=> SVNUpdateClient.doCheckout method - pegRevision?

I am using SVNKit to checkout svn base repository. Earlier I was using checkout to head for that purpose I was using SVNRevision.HEAD. It was working fine without issue.
below is the syntax of same and revision.Head was used in case of checkout to Head.
doCheckout(SVNURL url,File dstPath,SVNRevision pegRevision,SVNRevision revision, boolean recursive)
but let say if I have to checkout to a specific revision for example 27988, what should be value of pegRevision parameter ?
I am confused please help, I tried HEAD/BASE for pegrevision and also same 27988 etc but it gives error like URL not exist etc .
Just an update, problem was with my code revision was going as 0 always due to some logic issue hence SVN URL was not found and giving error. I tried now with HEAD as pegRevision and 27988 revision works just fine. Thanks!
Well, first, you have to specify an SVNRevision, not an integer.
long targetRev = 27988;
SVNRevision revision = SVNRevision.create( targetRev );
doCheckout(...
As for pegRevision, you almost certainly want SVNRevision.HEAD. As the docs specify, it is:
the revision at which url will be firstly seen in the repository to
make sure it's the one that is needed
So, HEAD is usually sufficient. When it's not, things get complicated (and very specific), see the svn book.

JGit branch checkout Issue

I am checking out a repository from github using the following code .
private String url = "https://github.com/organization/project.git";
Git repo = Git.cloneRepository().setURI(url).setDirectory(directory).setCloneAllBranches(true).call();
for (Ref b : repo.branchList().call()) {
System.out.println("(standard): cloned branch " + b.getName());
}
i am using the code
Git git = Git.open(checkout); //checkout is the folder with .git
git.pull().call(); //succeeds
If i chekout a branch
Git git = Git.open(new File(checkout)); //checkout is the folder with .git
System.out.println(git.getRepository().getFullBranch());
CheckoutCommand checkout = git.checkout();
Ref call = checkout.setName("kalees").call();
It throws org.eclipse.jgit.api.errors.RefNotFoundException: Ref kalees can not be resolved.
What is the issue here, if i specify "master" instead of "kalees", it works fine. what change should i do to checkout a specific branch?
if i use the code
git.checkout().setCreateBranch(true).setName("refs/remotes/origin/kalees");
It checkout the kalees branch. but when i do pull operation
git.pull().call();
it throws org.eclipse.jgit.api.errors.DetachedHeadException: HEAD is detached. What could be the , whether this is a checkout issue or pull issue ?
It should only happen if:
kalees isn't an existing branch (or is incorrectly written, bad case)
kalees is a remote branch you haven tracked yet a a local branch
If so you might need to create it first (a bit like in this example)
git.branchCreate().setForce(true).setName("kalees").setStartPoint("origin/kalees").call();
Following "JGit: Cannot find a tutorial or simple example", I would rather use:
git.branchCreate()
.setName("kalees")
.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint("origin/kalees")
.setForce(true)
.call();
I met this question when I want to create a branch with an empty repository, there is no commit in this repository.
It's resolved when I commit something to the repository. Hope it's helpful for you :)
Muthu your code is working you only need to add origin/branch like this to the branch call
Ref call = checkout.setName("origin/kalees").call();

JIRA - Jira post function -- How to update "fix version" field?

My scenario is: One step in my jira workflow should have the ability to unschedule a task i.e. set a Fix Version to "None".
I noticed that I was not able to update fix version in a workflow post function - I don't know exactly why, but anyway I did implement a jira plugin to help me solve my problem but I know I'm going against jira structure (even java good coding practices :)). I am not sure if my implementation can cause problems, but indeed it is working in my jira instance 4.1.x.
How I've implemented a plugin to update fix version in a post function, 2 very similar ways:
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// Here I create an empty Collection to be the new value of FixVersion (empty because I need no version in Fix Version)
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection<Version> newFixVersion = new ArrayList<Version>();
issue.setFixVersions(newFixVersion);
issue.store();
}
}
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// here I clear the Collection I got from "old" Fix Version and I have to set it again to make it work.
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection fixVersions = issue.getFixVersions();
fixVersions.clear();
issue.setFixVersions(fixVersions);
issue.store();
}
}
I presume that a real solution should use classes like: ChangeItemBean, ModifiedValue, IssueChangeHolder - taking as example the updateValue methods from CustomFieldImpl (from jira source code, project: jira, package: com.atlassian.jira.issue.fields).
My point of publishing this here is:
Does anyone know how to implement a jira plugin containing a post function to change Fix Version correctly?
If you want to do it properly take a look in the code for
./jira/src/java/com/atlassian/jira/workflow/function/issue/UpdateIssueFieldFunction.java processField()
Postfunctions that take input parameters are not documented yet it seems. Other places to go for code are other open source plugins.
Atlassian has a tutorial on doing just about exactly what you want to do, here:
I do it like in this snippet:
List<GenericValue> genericValueList = issueManager.getIssues(issues);
versionManager.moveIssuesToNewVersion(genericValueList, lastVersion, newVersion);

Problem with ImageTools plugin in Grails

i have a grails project with an Image Domain Class and Controller.
I just installed the grails ImageTools 1.0.4 Plugin and i would like to generate thumbnails for images wich will be uploaded.
My Image-Domain-Class:
class Image {
byte[] data
//String name
byte[] thumbnail
static constraints = {
//name()
data()
}
}
The "safe"-action in my Controller:
def save = {
def imageInstance = new Image(params)
def imageTool = new ImageTool()
imageTool.load(imageInstance.data)
imageTool.thumbnail(320)
imageInstance.thumbnail = imageTool.getBytes("JPEG") //Here is my problem!
if(!imageInstance.hasErrors() && imageInstance.save()) {
flash.message = "Image ${imageInstance.id} created"
redirect(action:show,id:imageInstance.id)
}
else {
render(view:'create',model:[imageInstance:imageInstance])
}
}
When I start my Grails-application and uploading an image I'm getting the following error-message:
Error 200: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Servlet: grails
URI: /grailsproject/grails/image/save.dispatch
Exception Message: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Caused by: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Class: GrailsAuthenticationProcessingFilter
At Line: [57]
It says that the Method getBytes() is missing but the method is still available. My IDE intelliJ also recognizes no errors.
So what can I do? Could someone help me please?
Sorry for my bad english. If you are german, please look at http://support-network.info/board/problem-mit-imagetools-getbytes-t3008.html .
I use Grails 1.0.4.
I could fix this error message. I just copied the getBytes() method from the git Repository of Ricardo (the plugin developer) and replaced the old one with the new one. Now everything works! I don't know where the bug was but i'm happy that i solved it.
Thank you both very much!
Looks like that method is a fairly new addition to the class (3/6/2009). If you have verified that that method is in the ./plugins/imagetools/src/groovy/ImageTool.groovy file I'd recommend running:
grails clean
If you had been using this plugin prior it might be a cache problem.
The reply that you received from John sounds about right - if you have installed the new plugin and can see the code, but keep getting this error only outside IntelliJ, you should try cleaning your grails cache - it's very possible that an older copy of the plugin is precompiled on the cache.
Are you using Grails 1.1? I haven't yet tested it with the latest grails, but I understand it keeps the plugins not under the project but in a separate directory. Do let me know and I'll try it out.
I don't know what the plugin is really giving you over using JAI directly, IMHO it isn't doing much.
I use ImageMagick out of process for my image conversion and the results are superior to what can be done with JAI from what I have seen. Of course if your doing as much traffic as Amazon running out of process is not an option, however if you need to get to revenue as quickly as possible then you might want to consider what I've done.
I use apache-commons-exec to have a nice interface around handling opening an external process and reading data from std in and out. The only thing I'm using JAI for is to read the sizes of images.
try this one http://support-network.info/board/gel%C3%B6st-problem-mit-imagetools-getbytes-t3008.html

Categories