Search in sources :

Example 31 with GitAPIException

use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.

the class JGitConnection method tagCreate.

@Override
public Tag tagCreate(TagCreateParams params) throws GitException {
    String commit = params.getCommit();
    if (commit == null) {
        commit = Constants.HEAD;
    }
    try {
        RevWalk revWalk = new RevWalk(repository);
        RevObject revObject;
        try {
            revObject = revWalk.parseAny(repository.resolve(commit));
        } finally {
            revWalk.close();
        }
        TagCommand tagCommand = getGit().tag().setName(params.getName()).setObjectId(revObject).setMessage(params.getMessage()).setForceUpdate(params.isForce());
        GitUser tagger = getUser();
        if (tagger != null) {
            tagCommand.setTagger(new PersonIdent(tagger.getName(), tagger.getEmail()));
        }
        Ref revTagRef = tagCommand.call();
        RevTag revTag = revWalk.parseTag(revTagRef.getLeaf().getObjectId());
        return newDto(Tag.class).withName(revTag.getTagName());
    } catch (IOException | GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) RevObject(org.eclipse.jgit.revwalk.RevObject) GitException(org.eclipse.che.api.git.exception.GitException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TagCommand(org.eclipse.jgit.api.TagCommand) GitUser(org.eclipse.che.api.git.shared.GitUser) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Ref(org.eclipse.jgit.lib.Ref) PersonIdent(org.eclipse.jgit.lib.PersonIdent) RevTag(org.eclipse.jgit.revwalk.RevTag) Tag(org.eclipse.che.api.git.shared.Tag)

Example 32 with GitAPIException

use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.

the class JGitConnection method reset.

@Override
public void reset(ResetParams params) throws GitException {
    try {
        ResetCommand resetCommand = getGit().reset();
        resetCommand.setRef(params.getCommit());
        List<String> patterns = params.getFilePattern();
        patterns.forEach(resetCommand::addPath);
        if (params.getType() != null && patterns.isEmpty()) {
            switch(params.getType()) {
                case HARD:
                    resetCommand.setMode(ResetType.HARD);
                    break;
                case KEEP:
                    resetCommand.setMode(ResetType.KEEP);
                    break;
                case MERGE:
                    resetCommand.setMode(ResetType.MERGE);
                    break;
                case MIXED:
                    resetCommand.setMode(ResetType.MIXED);
                    break;
                case SOFT:
                    resetCommand.setMode(ResetType.SOFT);
                    break;
            }
        }
        resetCommand.call();
    } catch (GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitException(org.eclipse.che.api.git.exception.GitException) ResetCommand(org.eclipse.jgit.api.ResetCommand)

Example 33 with GitAPIException

use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.

the class JGitConnection method lsRemote.

@Override
public List<RemoteReference> lsRemote(String remoteUrl) throws UnauthorizedException, GitException {
    LsRemoteCommand lsRemoteCommand = getGit().lsRemote().setRemote(remoteUrl);
    Collection<Ref> refs;
    try {
        refs = lsRemoteCommand.call();
    } catch (GitAPIException exception) {
        if (exception.getMessage().contains(ERROR_AUTHENTICATION_REQUIRED)) {
            throw new UnauthorizedException(format(ERROR_AUTHENTICATION_FAILED, remoteUrl));
        } else {
            throw new GitException(exception.getMessage(), exception);
        }
    }
    return refs.stream().map(ref -> newDto(RemoteReference.class).withCommitId(ref.getObjectId().name()).withReferenceName(ref.getName())).collect(Collectors.toList());
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) InvalidRefNameException(org.eclipse.jgit.api.errors.InvalidRefNameException) Arrays(java.util.Arrays) LsFilesParams(org.eclipse.che.api.git.params.LsFilesParams) RevObject(org.eclipse.jgit.revwalk.RevObject) RebaseResponse(org.eclipse.che.api.git.shared.RebaseResponse) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) RepositoryState(org.eclipse.jgit.lib.RepositoryState) PullParams(org.eclipse.che.api.git.params.PullParams) SshTransport(org.eclipse.jgit.transport.SshTransport) RevWalk(org.eclipse.jgit.revwalk.RevWalk) CloneParams(org.eclipse.che.api.git.params.CloneParams) RevTag(org.eclipse.jgit.revwalk.RevTag) ResetCommand(org.eclipse.jgit.api.ResetCommand) PathFilter(org.eclipse.jgit.treewalk.filter.PathFilter) Map(java.util.Map) URIish(org.eclipse.jgit.transport.URIish) PullResponse(org.eclipse.che.api.git.shared.PullResponse) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) RebaseStatus(org.eclipse.che.api.git.shared.RebaseResponse.RebaseStatus) GitConflictException(org.eclipse.che.api.git.exception.GitConflictException) EnumSet(java.util.EnumSet) TagCommand(org.eclipse.jgit.api.TagCommand) RepositoryCache(org.eclipse.jgit.lib.RepositoryCache) Result(org.eclipse.jgit.lib.RefUpdate.Result) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) TreeFilter(org.eclipse.jgit.treewalk.filter.TreeFilter) GitConnection(org.eclipse.che.api.git.GitConnection) RefSpec(org.eclipse.jgit.transport.RefSpec) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) RebaseResult(org.eclipse.jgit.api.RebaseResult) CommitCommand(org.eclipse.jgit.api.CommitCommand) Config(org.eclipse.che.api.git.Config) RefUpdate(org.eclipse.jgit.lib.RefUpdate) OpenSshConfig(org.eclipse.jgit.transport.OpenSshConfig) Set(java.util.Set) Status(org.eclipse.che.api.git.shared.Status) Constants(org.eclipse.jgit.lib.Constants) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) TransportCommand(org.eclipse.jgit.api.TransportCommand) Nullable(org.eclipse.che.commons.annotation.Nullable) RevTree(org.eclipse.jgit.revwalk.RevTree) DirectoryFileFilter(org.apache.commons.io.filefilter.DirectoryFileFilter) RemoteUpdateParams(org.eclipse.che.api.git.params.RemoteUpdateParams) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GitInvalidRefNameException(org.eclipse.che.api.git.exception.GitInvalidRefNameException) StatusFormat(org.eclipse.che.api.git.shared.StatusFormat) FileUtils(org.eclipse.jgit.util.FileUtils) Stream(java.util.stream.Stream) CredentialsLoader(org.eclipse.che.api.git.CredentialsLoader) Session(com.jcraft.jsch.Session) PushResult(org.eclipse.jgit.transport.PushResult) DirCache(org.eclipse.jgit.dircache.DirCache) GitRefNotFoundException(org.eclipse.che.api.git.exception.GitRefNotFoundException) FS(org.eclipse.jgit.util.FS) JSchException(com.jcraft.jsch.JSchException) Revision(org.eclipse.che.api.git.shared.Revision) FilenameFilter(java.io.FilenameFilter) RevCommit(org.eclipse.jgit.revwalk.RevCommit) LogCommand(org.eclipse.jgit.api.LogCommand) LogPage(org.eclipse.che.api.git.LogPage) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) PROVIDER_NAME(org.eclipse.che.api.git.shared.ProviderInfo.PROVIDER_NAME) ArrayList(java.util.ArrayList) LogParams(org.eclipse.che.api.git.params.LogParams) SetupUpstreamMode(org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode) ListMode(org.eclipse.jgit.api.ListBranchCommand.ListMode) ResetParams(org.eclipse.che.api.git.params.ResetParams) PushResponse(org.eclipse.che.api.git.shared.PushResponse) DiffCommitFile(org.eclipse.che.api.git.shared.DiffCommitFile) PushCommand(org.eclipse.jgit.api.PushCommand) RefAlreadyExistsException(org.eclipse.jgit.api.errors.RefAlreadyExistsException) PathFilterGroup(org.eclipse.jgit.treewalk.filter.PathFilterGroup) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) DiffPage(org.eclipse.che.api.git.DiffPage) ErrorCodes(org.eclipse.che.api.core.ErrorCodes) BranchListMode(org.eclipse.che.api.git.shared.BranchListMode) Tag(org.eclipse.che.api.git.shared.Tag) AddRequest(org.eclipse.che.api.git.shared.AddRequest) FileOutputStream(java.io.FileOutputStream) MergeResult(org.eclipse.che.api.git.shared.MergeResult) ProviderInfo(org.eclipse.che.api.git.shared.ProviderInfo) IOException(java.io.IOException) File(java.io.File) RefNotFoundException(org.eclipse.jgit.api.errors.RefNotFoundException) DiffParams(org.eclipse.che.api.git.params.DiffParams) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) ServerException(org.eclipse.che.api.core.ServerException) StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) PushParams(org.eclipse.che.api.git.params.PushParams) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) FetchParams(org.eclipse.che.api.git.params.FetchParams) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) GitRefAlreadyExistsException(org.eclipse.che.api.git.exception.GitRefAlreadyExistsException) AddCommand(org.eclipse.jgit.api.AddCommand) UserCredential(org.eclipse.che.api.git.UserCredential) CheckoutConflictException(org.eclipse.jgit.api.errors.CheckoutConflictException) NullOutputStream(org.eclipse.jgit.util.io.NullOutputStream) FetchResult(org.eclipse.jgit.transport.FetchResult) CommitParams(org.eclipse.che.api.git.params.CommitParams) ProxyAuthenticator(org.eclipse.che.commons.proxy.ProxyAuthenticator) ResetType(org.eclipse.jgit.api.ResetCommand.ResetType) RemoteAddParams(org.eclipse.che.api.git.params.RemoteAddParams) AUTHENTICATE_URL(org.eclipse.che.api.git.shared.ProviderInfo.AUTHENTICATE_URL) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) GitException(org.eclipse.che.api.git.exception.GitException) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) Branch(org.eclipse.che.api.git.shared.Branch) RemoteReference(org.eclipse.che.api.git.shared.RemoteReference) Ref(org.eclipse.jgit.lib.Ref) TagCreateParams(org.eclipse.che.api.git.params.TagCreateParams) Optional(java.util.Optional) ListBranchCommand(org.eclipse.jgit.api.ListBranchCommand) Pattern(java.util.regex.Pattern) RmCommand(org.eclipse.jgit.api.RmCommand) GitUrlUtils(org.eclipse.che.api.git.GitUrlUtils) Remote(org.eclipse.che.api.git.shared.Remote) System.lineSeparator(java.lang.System.lineSeparator) JSch(com.jcraft.jsch.JSch) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CanonicalTreeParser(org.eclipse.jgit.treewalk.CanonicalTreeParser) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) CloneCommand(org.eclipse.jgit.api.CloneCommand) HashMap(java.util.HashMap) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) LIST_ALL(org.eclipse.che.api.git.shared.BranchListMode.LIST_ALL) LIST_LOCAL(org.eclipse.che.api.git.shared.BranchListMode.LIST_LOCAL) FetchCommand(org.eclipse.jgit.api.FetchCommand) Inject(javax.inject.Inject) HashSet(java.util.HashSet) RmParams(org.eclipse.che.api.git.params.RmParams) LIST_REMOTE(org.eclipse.che.api.git.shared.BranchListMode.LIST_REMOTE) Files(com.google.common.io.Files) SshKeyProvider(org.eclipse.che.plugin.ssh.key.script.SshKeyProvider) SshSessionFactory(org.eclipse.jgit.transport.SshSessionFactory) ResolveMerger(org.eclipse.jgit.merge.ResolveMerger) BatchingProgressMonitor(org.eclipse.jgit.lib.BatchingProgressMonitor) AndTreeFilter(org.eclipse.jgit.treewalk.filter.AndTreeFilter) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) AddParams(org.eclipse.che.api.git.params.AddParams) GitUserResolver(org.eclipse.che.api.git.GitUserResolver) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) CreateBranchCommand(org.eclipse.jgit.api.CreateBranchCommand) ConfigConstants(org.eclipse.jgit.lib.ConfigConstants) ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) CheckoutCommand(org.eclipse.jgit.api.CheckoutCommand) ObjectId(org.eclipse.jgit.lib.ObjectId) TransportException(org.eclipse.jgit.api.errors.TransportException) OWNER_READ(java.nio.file.attribute.PosixFilePermission.OWNER_READ) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) LsRemoteCommand(org.eclipse.jgit.api.LsRemoteCommand) CheckoutParams(org.eclipse.che.api.git.params.CheckoutParams) TrackingRefUpdate(org.eclipse.jgit.transport.TrackingRefUpdate) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Git(org.eclipse.jgit.api.Git) DetachedHeadException(org.eclipse.jgit.api.errors.DetachedHeadException) DiffEntry(org.eclipse.jgit.diff.DiffEntry) OWNER_WRITE(java.nio.file.attribute.PosixFilePermission.OWNER_WRITE) GitUser(org.eclipse.che.api.git.shared.GitUser) Collections(java.util.Collections) JschConfigSessionFactory(org.eclipse.jgit.transport.JschConfigSessionFactory) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Ref(org.eclipse.jgit.lib.Ref) GitException(org.eclipse.che.api.git.exception.GitException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) LsRemoteCommand(org.eclipse.jgit.api.LsRemoteCommand)

Example 34 with GitAPIException

use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.

the class JGitConnection method getCommiters.

@Override
public List<GitUser> getCommiters() throws GitException {
    List<GitUser> gitUsers = new ArrayList<>();
    try {
        LogCommand logCommand = getGit().log();
        for (RevCommit commit : logCommand.call()) {
            PersonIdent committerIdentity = commit.getCommitterIdent();
            GitUser gitUser = newDto(GitUser.class).withName(committerIdentity.getName()).withEmail(committerIdentity.getEmailAddress());
            if (!gitUsers.contains(gitUser)) {
                gitUsers.add(gitUser);
            }
        }
    } catch (GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
    return gitUsers;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LogCommand(org.eclipse.jgit.api.LogCommand) GitException(org.eclipse.che.api.git.exception.GitException) ArrayList(java.util.ArrayList) GitUser(org.eclipse.che.api.git.shared.GitUser) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 35 with GitAPIException

use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.

the class JGitConnection method branchCreate.

@Override
public Branch branchCreate(String name, String startPoint) throws GitException {
    CreateBranchCommand createBranchCommand = getGit().branchCreate().setName(name);
    if (startPoint != null) {
        createBranchCommand.setStartPoint(startPoint);
    }
    try {
        Ref brRef = createBranchCommand.call();
        String refName = brRef.getName();
        String displayName = Repository.shortenRefName(refName);
        return newDto(Branch.class).withName(refName).withDisplayName(displayName).withActive(false).withRemote(false);
    } catch (GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
}
Also used : CreateBranchCommand(org.eclipse.jgit.api.CreateBranchCommand) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Ref(org.eclipse.jgit.lib.Ref) GitException(org.eclipse.che.api.git.exception.GitException)

Aggregations

GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)60 IOException (java.io.IOException)25 Git (org.eclipse.jgit.api.Git)22 GitException (org.eclipse.che.api.git.exception.GitException)18 File (java.io.File)16 Ref (org.eclipse.jgit.lib.Ref)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ArrayList (java.util.ArrayList)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 RefSpec (org.eclipse.jgit.transport.RefSpec)11 Repository (org.eclipse.jgit.lib.Repository)9 URISyntaxException (java.net.URISyntaxException)8 PushResult (org.eclipse.jgit.transport.PushResult)8 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)8 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)8 PushCommand (org.eclipse.jgit.api.PushCommand)7 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)6 FetchCommand (org.eclipse.jgit.api.FetchCommand)6 HashMap (java.util.HashMap)5 DiffCommitFile (org.eclipse.che.api.git.shared.DiffCommitFile)5