use of org.eclipse.jgit.api.errors.GitAPIException in project gitiles by GerritCodeReview.
the class DescribeServlet method describe.
private String describe(Repository repo, GitilesView view, HttpServletRequest req, HttpServletResponse res) throws IOException {
if (!getBooleanParam(view, CONTAINS_PARAM)) {
res.setStatus(SC_BAD_REQUEST);
return null;
}
ObjectId id = resolve(repo, view, req, res);
if (id == null) {
return null;
}
String name;
try (Git git = new Git(repo)) {
NameRevCommand cmd = nameRevCommand(git, id, req, res);
if (cmd == null) {
return null;
}
name = cmd.call().get(id);
} catch (GitAPIException e) {
throw new IOException(e);
}
if (name == null) {
res.setStatus(SC_NOT_FOUND);
return null;
}
return name;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project gerrit by GerritCodeReview.
the class UploadArchive method runImpl.
@Override
protected void runImpl() throws IOException, PermissionBackendException, Failure {
PacketLineOut packetOut = new PacketLineOut(out);
packetOut.setFlushOnEnd(true);
packetOut.writeString("ACK");
packetOut.end();
try {
// Parse Git arguments
readArguments();
ArchiveFormat f = allowedFormats.getExtensions().get("." + options.format);
if (f == null) {
throw new Failure(3, "fatal: upload-archive not permitted");
}
// Find out the object to get from the specified reference and paths
ObjectId treeId = repo.resolve(options.treeIsh);
if (treeId == null) {
throw new Failure(4, "fatal: reference not found");
}
// Verify the user has permissions to read the specified tree.
if (!canRead(treeId)) {
throw new Failure(5, "fatal: cannot perform upload-archive operation");
}
// The archive is sent in DATA sideband channel
try (SideBandOutputStream sidebandOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, SideBandOutputStream.MAX_BUF, out)) {
new ArchiveCommand(repo).setFormat(f.name()).setFormatOptions(getFormatOptions(f)).setTree(treeId).setPaths(options.path.toArray(new String[0])).setPrefix(options.prefix).setOutputStream(sidebandOut).call();
sidebandOut.flush();
} catch (GitAPIException e) {
throw new Failure(7, "fatal: git api exception, " + e);
}
} catch (Failure f) {
// Report the error in ERROR sideband channel
try (SideBandOutputStream sidebandError = new SideBandOutputStream(SideBandOutputStream.CH_ERROR, SideBandOutputStream.MAX_BUF, out)) {
sidebandError.write(f.getMessage().getBytes(UTF_8));
sidebandError.flush();
}
throw f;
} finally {
// In any case, cleanly close the packetOut channel
packetOut.end();
}
}
use of org.eclipse.jgit.api.errors.GitAPIException in project indy by Commonjava.
the class GitManager method addAndCommitPaths.
public GitManager addAndCommitPaths(final ChangeSummary summary, final Collection<String> paths) throws GitSubsystemException {
lockAnd(me -> {
if (!verifyChangesExist(paths)) {
logger.info("No actual changes in:\n {}\n\nSkipping commit.", join(paths, "\n "));
return this;
}
try {
final AddCommand add = git.add();
final CommitCommand commit = git.commit();
for (final String filepath : paths) {
add.addFilepattern(filepath);
}
logger.info("Adding:\n " + join(paths, "\n ") + "\n\nSummary: " + summary);
add.call();
commit.setMessage(buildMessage(summary, paths)).setAuthor(summary.getUser(), email).call();
} catch (final NoFilepatternException e) {
throw new GitSubsystemException("Cannot add to git: " + e.getMessage(), e);
} catch (final GitAPIException e) {
throw new GitSubsystemException("Cannot add to git: " + e.getMessage(), e);
}
return me;
});
return this;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project compiler by boalang.
the class RepositoryCloner method main.
public static void main(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
// prepare a new folder for the cloned repository
String localpath = args[1];
String url = args[0];
REMOTE_URL = url;
File localPath = new File(localpath);
if (!localPath.exists())
localPath.mkdir();
// then clone
Git result = null;
try {
result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call();
// Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
result.getRepository().close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (result != null && result.getRepository() != null)
result.getRepository().close();
}
}
use of org.eclipse.jgit.api.errors.GitAPIException in project compiler by boalang.
the class RepositoryCloner method clone.
public static void clone(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
// prepare a new folder for the cloned repository
String localpaths = args[1];
String url = args[0];
REMOTE_URL = url;
File localPath = new File(localpaths);
if (!localPath.exists())
localPath.mkdir();
// then clone
Git result = null;
try {
result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call();
// Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
result.getRepository().close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (result != null && result.getRepository() != null)
result.getRepository().close();
}
}
Aggregations