use of org.eclipse.jgit.api.errors.NoHeadException in project zeppelin by apache.
the class GitNotebookRepo method revisionHistory.
@Override
public List<Revision> revisionHistory(String noteId, AuthenticationInfo subject) {
List<Revision> history = Lists.newArrayList();
LOG.debug("Listing history for {}:", noteId);
try {
Iterable<RevCommit> logs = git.log().addPath(noteId).call();
for (RevCommit log : logs) {
history.add(new Revision(log.getName(), log.getShortMessage(), log.getCommitTime()));
LOG.debug(" - ({},{},{})", log.getName(), log.getCommitTime(), log.getFullMessage());
}
} catch (NoHeadException e) {
//when no initial commit exists
LOG.warn("No Head found for {}, {}", noteId, e.getMessage());
} catch (GitAPIException e) {
LOG.error("Failed to get logs for {}", noteId, e);
}
return history;
}
use of org.eclipse.jgit.api.errors.NoHeadException in project egit by eclipse.
the class MergeOperation method execute.
@Override
public void execute(IProgressMonitor m) throws CoreException {
if (mergeResult != null)
throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor mymonitor) throws CoreException {
IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
SubMonitor progress = SubMonitor.convert(mymonitor, NLS.bind(CoreText.MergeOperation_ProgressMerge, refName), 3);
try (Git git = new Git(repository)) {
progress.worked(1);
MergeCommand merge = git.merge().setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(1)));
Ref ref = repository.findRef(refName);
if (ref != null) {
merge.include(ref);
} else {
merge.include(ObjectId.fromString(refName));
}
if (fastForwardMode != null) {
merge.setFastForward(fastForwardMode);
}
if (commit != null) {
merge.setCommit(commit.booleanValue());
}
if (squash != null) {
merge.setSquash(squash.booleanValue());
}
if (mergeStrategy != null) {
merge.setStrategy(mergeStrategy);
}
if (message != null) {
merge.setMessage(message);
}
mergeResult = merge.call();
if (MergeResult.MergeStatus.NOT_SUPPORTED.equals(mergeResult.getMergeStatus())) {
throw new TeamException(new Status(IStatus.INFO, Activator.getPluginId(), mergeResult.toString()));
}
} catch (IOException e) {
throw new TeamException(CoreText.MergeOperation_InternalError, e);
} catch (NoHeadException e) {
throw new TeamException(CoreText.MergeOperation_MergeFailedNoHead, e);
} catch (ConcurrentRefUpdateException e) {
throw new TeamException(CoreText.MergeOperation_MergeFailedRefUpdate, e);
} catch (CheckoutConflictException e) {
mergeResult = new MergeResult(e.getConflictingPaths());
return;
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
} finally {
ProjectUtil.refreshValidProjects(validProjects, progress.newChild(1));
}
}
};
// lock workspace to protect working tree changes
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m);
}
use of org.eclipse.jgit.api.errors.NoHeadException in project MGit by maks.
the class CommitChangesTask method commit.
public static void commit(Repo repo, boolean stageAll, boolean isAmend, String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, GitAPIException, StopTaskException {
Context context = SGitApplication.getContext();
StoredConfig config = repo.getGit().getRepository().getConfig();
String committerEmail = config.getString("user", null, "email");
String committerName = config.getString("user", null, "name");
if (committerName == null || committerName.equals("")) {
committerName = Profile.getUsername(context);
}
if (committerEmail == null || committerEmail.equals("")) {
committerEmail = Profile.getEmail(context);
}
if (committerName.isEmpty() || committerEmail.isEmpty()) {
throw new Exception("Please set your name and email");
}
if (msg.isEmpty()) {
throw new Exception("Please include a commit message");
}
CommitCommand cc = repo.getGit().commit().setCommitter(committerName, committerEmail).setAll(stageAll).setAmend(isAmend).setMessage(msg);
if (authorName != null && authorEmail != null) {
cc.setAuthor(authorName, authorEmail);
}
cc.call();
repo.updateLatestCommitInfo();
}
use of org.eclipse.jgit.api.errors.NoHeadException in project alien4cloud by alien4cloud.
the class RepositoryManager method getHistory.
/**
* Return a simplified git commit history list.
*
* @param repositoryDirectory The directory in which the git repo exists.
* @param from Start to query from the given history.
* @param count The number of history entries to retrieve.
* @return A list of simplified history entries.
*/
public static List<SimpleGitHistoryEntry> getHistory(Path repositoryDirectory, int from, int count) {
Git repository = null;
try {
repository = Git.open(repositoryDirectory.toFile());
Iterable<RevCommit> commits = repository.log().setSkip(from).setMaxCount(count).call();
List<SimpleGitHistoryEntry> historyEntries = Lists.newArrayList();
for (RevCommit commit : commits) {
historyEntries.add(new SimpleGitHistoryEntry(commit.getId().getName(), commit.getAuthorIdent().getName(), commit.getAuthorIdent().getEmailAddress(), commit.getFullMessage(), new Date(commit.getCommitTime() * 1000L)));
}
return historyEntries;
} catch (NoHeadException e) {
log.debug("Your repository has no head, you need to save your topology before using the git history.");
return Lists.newArrayList();
} catch (GitAPIException | IOException e) {
throw new GitException("Unable to get history from the git repository", e);
} finally {
close(repository);
}
}
Aggregations