Search in sources :

Example 1 with NoHeadException

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;
}
Also used : NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with NoHeadException

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) SubMonitor(org.eclipse.core.runtime.SubMonitor) MergeCommand(org.eclipse.jgit.api.MergeCommand) MergeResult(org.eclipse.jgit.api.MergeResult) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IOException(java.io.IOException) CheckoutConflictException(org.eclipse.jgit.api.errors.CheckoutConflictException) IProject(org.eclipse.core.resources.IProject) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) CoreException(org.eclipse.core.runtime.CoreException) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException)

Example 3 with NoHeadException

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();
}
Also used : Context(android.content.Context) StoredConfig(org.eclipse.jgit.lib.StoredConfig) CommitCommand(org.eclipse.jgit.api.CommitCommand) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) StopTaskException(me.sheimi.sgit.exception.StopTaskException) UnmergedPathsException(org.eclipse.jgit.api.errors.UnmergedPathsException) NoMessageException(org.eclipse.jgit.api.errors.NoMessageException)

Example 4 with NoHeadException

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);
    }
}
Also used : NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitException(alien4cloud.exception.GitException) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 NoHeadException (org.eclipse.jgit.api.errors.NoHeadException)4 IOException (java.io.IOException)2 ConcurrentRefUpdateException (org.eclipse.jgit.api.errors.ConcurrentRefUpdateException)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 GitException (alien4cloud.exception.GitException)1 Context (android.content.Context)1 StopTaskException (me.sheimi.sgit.exception.StopTaskException)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 EclipseGitProgressTransformer (org.eclipse.egit.core.EclipseGitProgressTransformer)1 CommitCommand (org.eclipse.jgit.api.CommitCommand)1 Git (org.eclipse.jgit.api.Git)1 MergeCommand (org.eclipse.jgit.api.MergeCommand)1 MergeResult (org.eclipse.jgit.api.MergeResult)1