use of org.eclipse.jgit.api.errors.JGitInternalException in project bndtools by bndtools.
the class GitCloneTemplate method generateOutputs.
@Override
public ResourceMap generateOutputs(Map<String, List<Object>> parameters, IProgressMonitor monitor) throws Exception {
File workingDir = null;
File gitDir = null;
// Get existing checkout if available
synchronized (this) {
if (checkedOut != null) {
workingDir = checkedOut.getWorkTree();
gitDir = new File(workingDir, ".git");
}
}
if (workingDir == null) {
// Need to do a new checkout
workingDir = Files.createTempDirectory("checkout").toFile();
gitDir = new File(workingDir, ".git");
try {
CloneCommand cloneCmd = Git.cloneRepository().setURI(params.cloneUrl).setDirectory(workingDir).setNoCheckout(true);
cloneCmd.setProgressMonitor(new EclipseGitProgressTransformer(monitor));
Git git = cloneCmd.call();
CheckoutCommand checkout = git.checkout().setCreateBranch(true).setName("_tmp");
if (params.branch == null) {
checkout.setStartPoint(GitCloneTemplateParams.DEFAULT_BRANCH);
} else {
String startPoint = null;
if (params.branch.startsWith(Constants.DEFAULT_REMOTE_NAME + "/")) {
startPoint = params.branch;
} else {
// Check for a matching tag
for (Ref ref : git.tagList().call()) {
if (ref.getName().endsWith("/" + params.branch)) {
startPoint = params.branch;
break;
}
}
if (startPoint == null) {
// Check remote branches
for (Ref ref : git.branchList().setListMode(ListMode.REMOTE).call()) {
if (ref.getName().endsWith("/" + params.branch)) {
startPoint = Constants.DEFAULT_REMOTE_NAME + "/" + params.branch;
break;
}
}
if (startPoint == null) {
if (SHA1_PATTERN.matcher(params.branch).matches()) {
startPoint = params.branch;
if (startPoint == null) {
throw new Exception("Unable to find requested ref \"" + params.branch + "\"");
}
}
}
}
}
checkout.setStartPoint(startPoint);
}
checkout.call();
checkedOut = git.getRepository();
} catch (JGitInternalException e) {
Throwable cause = e.getCause();
if (cause instanceof Exception)
throw (Exception) cause;
throw e;
}
}
final File exclude = gitDir;
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File path) {
return !path.equals(exclude);
}
};
return toResourceMap(workingDir, filter);
}
Aggregations