use of org.eclipse.jgit.api.errors.GitAPIException in project zeppelin by apache.
the class GitNotebookRepo method get.
/**
* the idea is to:
* 1. stash current changes
* 2. remember head commit and checkout to the desired revision
* 3. get note and checkout back to the head
* 4. apply stash on top and remove it
*/
@Override
public synchronized Note get(String noteId, String revId, AuthenticationInfo subject) throws IOException {
Note note = null;
RevCommit stash = null;
try {
List<DiffEntry> gitDiff = git.diff().setPathFilter(PathFilter.create(noteId)).call();
boolean modified = !gitDiff.isEmpty();
if (modified) {
// stash changes
stash = git.stashCreate().call();
Collection<RevCommit> stashes = git.stashList().call();
LOG.debug("Created stash : {}, stash size : {}", stash, stashes.size());
}
ObjectId head = git.getRepository().resolve(Constants.HEAD);
// checkout to target revision
git.checkout().setStartPoint(revId).addPath(noteId).call();
// get the note
note = super.get(noteId, subject);
// checkout back to head
git.checkout().setStartPoint(head.getName()).addPath(noteId).call();
if (modified && stash != null) {
// unstash changes
ObjectId applied = git.stashApply().setStashRef(stash.getName()).call();
ObjectId dropped = git.stashDrop().setStashRef(0).call();
Collection<RevCommit> stashes = git.stashList().call();
LOG.debug("Stash applied as : {}, and dropped : {}, stash size: {}", applied, dropped, stashes.size());
}
} catch (GitAPIException e) {
LOG.error("Failed to return note from revision \"{}\"", revId, e);
}
return note;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project indy by Commonjava.
the class GitManager method commitModifiedFiles.
public GitManager commitModifiedFiles(final ChangeSummary changeSummary) throws GitSubsystemException {
lockAnd((me) -> {
Status status;
try {
status = git.status().call();
} catch (NoWorkTreeException | GitAPIException e) {
throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage());
}
final Map<String, StageState> css = status.getConflictingStageState();
if (!css.isEmpty()) {
throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n %s", rootDir, new JoinString("\n ", css.entrySet()));
}
final Set<String> toAdd = new HashSet<>();
final Set<String> modified = status.getModified();
if (modified != null && !modified.isEmpty()) {
toAdd.addAll(modified);
}
final Set<String> untracked = status.getUntracked();
if (untracked != null && !untracked.isEmpty()) {
toAdd.addAll(untracked);
}
final Set<String> untrackedFolders = status.getUntrackedFolders();
if (untrackedFolders != null && !untrackedFolders.isEmpty()) {
toAdd.addAll(untrackedFolders);
// for ( String folderPath : untrackedFolders )
// {
// File dir = new File( rootDir, folderPath );
// Files.walkFileTree( null, null )
// }
}
if (!toAdd.isEmpty()) {
addAndCommitPaths(changeSummary, toAdd);
}
return me;
});
return this;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project gitiles by GerritCodeReview.
the class ArchiveServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
GitilesView view = ViewFilter.getView(req);
Revision rev = view.getRevision();
Repository repo = ServletUtils.getRepository(req);
ObjectId treeId = getTree(view, repo, rev);
if (treeId.equals(ObjectId.zeroId())) {
res.sendError(SC_NOT_FOUND);
return;
}
Optional<ArchiveFormat> format = ArchiveFormat.byExtension(view.getExtension(), getAccess(req).getConfig());
if (!format.isPresent()) {
res.setStatus(SC_NOT_FOUND);
return;
}
String filename = getFilename(view, rev, view.getExtension());
setDownloadHeaders(req, res, filename, format.get().getMimeType());
res.setStatus(SC_OK);
try {
new ArchiveCommand(repo).setFormat(format.get().getRegisteredName()).setTree(treeId).setOutputStream(res.getOutputStream()).call();
} catch (GitAPIException e) {
throw new IOException(e);
}
}
use of org.eclipse.jgit.api.errors.GitAPIException in project indy by Commonjava.
the class GitManager method deleteAndCommitPaths.
public GitManager deleteAndCommitPaths(final ChangeSummary summary, final Collection<String> paths) throws GitSubsystemException {
lockAnd(me -> {
try {
RmCommand rm = git.rm();
CommitCommand commit = git.commit();
for (final String path : paths) {
rm = rm.addFilepattern(path);
commit = commit.setOnly(path);
}
logger.info("Deleting:\n " + join(paths, "\n ") + "\n\nSummary: " + summary);
rm.call();
commit.setMessage(buildMessage(summary, paths)).setAuthor(summary.getUser(), email).call();
} catch (final NoFilepatternException e) {
throw new GitSubsystemException("Cannot remove from git: " + e.getMessage(), e);
} catch (final JGitInternalException | GitAPIException e) {
throw new GitSubsystemException("Cannot remove from git: " + e.getMessage(), e);
}
return me;
});
return this;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project POL-POM-5 by PlayOnLinux.
the class GitRepository method fetchInstallableApplications.
@Override
public synchronized List<CategoryDTO> fetchInstallableApplications() {
LOGGER.info(String.format("Begin fetching process of git-repository '%s' in '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
boolean folderExists = gitRepositoryLocation.exists();
// check that the repository folder exists
if (!folderExists) {
LOGGER.info(String.format("Creating new folder '%s' for git-repository '%s'", gitRepositoryLocation.getAbsolutePath(), this.gitRepositoryUri));
if (!gitRepositoryLocation.mkdirs()) {
LOGGER.error(String.format("Couldn't create folder for git repository '%s' at '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
return Collections.emptyList();
}
}
List<CategoryDTO> result = Collections.emptyList();
try {
Git gitRepository = null;
/*
* if the repository folder previously didn't exist, clone the
* repository now
*/
if (!folderExists) {
LOGGER.info(String.format("Cloning git-repository '%s' to '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
gitRepository = Git.cloneRepository().setURI(this.gitRepositoryUri.toString()).setDirectory(gitRepositoryLocation).call();
} else /*
* otherwise open the folder and pull the newest updates from the
* repository
*/
{
LOGGER.info(String.format("Opening git-repository '%s' at '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
gitRepository = Git.open(gitRepositoryLocation);
LOGGER.info(String.format("Pulling new commits from git-repository '%s' to '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
gitRepository.pull().call();
}
// close repository to free resources
gitRepository.close();
result = localRepositoryFactory.createInstance(this.gitRepositoryLocation, this.gitRepositoryUri).fetchInstallableApplications();
} catch (RepositoryNotFoundException | GitAPIException e) {
LOGGER.error(String.format("Folder '%s' is no git-repository", gitRepositoryLocation.getAbsolutePath()), e);
} catch (IOException e) {
LOGGER.error(String.format("An unknown error occured", e));
}
return result;
}
Aggregations