Search in sources :

Example 1 with SgitTransportCallback

use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.

the class PullTask method pullRepo.

public boolean pullRepo() {
    Git git;
    try {
        git = mRepo.getGit();
    } catch (StopTaskException e) {
        return false;
    }
    PullCommand pullCommand = git.pull().setRemote(mRemote).setProgressMonitor(new BasicProgressMonitor()).setTransportConfigCallback(new SgitTransportCallback());
    setCredentials(pullCommand);
    try {
        String branch = null;
        if (mForcePull) {
            branch = git.getRepository().getFullBranch();
            if (!branch.startsWith("refs/heads/")) {
                setException(new GitAPIException("not on branch") {
                }, R.string.error_pull_failed_not_on_branch);
                return false;
            }
            branch = branch.substring(11);
            BasicProgressMonitor bpm = new BasicProgressMonitor();
            bpm.beginTask("clearing repo state", 3);
            git.getRepository().writeMergeCommitMsg(null);
            git.getRepository().writeMergeHeads(null);
            bpm.update(1);
            try {
                git.rebase().setOperation(RebaseCommand.Operation.ABORT).call();
            } catch (Exception e) {
            }
            bpm.update(2);
            git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
            bpm.endTask();
        }
        pullCommand.call();
        if (mForcePull) {
            BasicProgressMonitor bpm = new BasicProgressMonitor();
            bpm.beginTask("resetting to " + mRemote + "/" + branch, 1);
            git.reset().setMode(ResetCommand.ResetType.HARD).setRef(mRemote + "/" + branch).call();
            bpm.endTask();
        }
    } catch (TransportException e) {
        setException(e);
        handleAuthError(this);
        return false;
    } catch (Exception e) {
        setException(e, R.string.error_pull_failed);
        return false;
    } catch (OutOfMemoryError e) {
        setException(e, R.string.error_out_of_memory);
        return false;
    } catch (Throwable e) {
        setException(e);
        return false;
    }
    mRepo.updateLatestCommitInfo();
    return true;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PullCommand(org.eclipse.jgit.api.PullCommand) SgitTransportCallback(me.sheimi.sgit.ssh.SgitTransportCallback) Git(org.eclipse.jgit.api.Git) StopTaskException(me.sheimi.sgit.exception.StopTaskException) TransportException(org.eclipse.jgit.api.errors.TransportException) TransportException(org.eclipse.jgit.api.errors.TransportException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 2 with SgitTransportCallback

use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.

the class PushTask method pushRepo.

public boolean pushRepo() {
    Git git;
    try {
        git = mRepo.getGit();
    } catch (StopTaskException e1) {
        return false;
    }
    PushCommand pushCommand = git.push().setPushTags().setProgressMonitor(new BasicProgressMonitor()).setTransportConfigCallback(new SgitTransportCallback()).setRemote(mRemote);
    if (mPushAll) {
        pushCommand.setPushAll();
    } else {
        RefSpec spec = new RefSpec(mRepo.getBranchName());
        pushCommand.setRefSpecs(spec);
    }
    if (mForcePush) {
        pushCommand.setForce(true);
    }
    setCredentials(pushCommand);
    try {
        Iterable<PushResult> result = pushCommand.call();
        for (PushResult r : result) {
            Collection<RemoteRefUpdate> updates = r.getRemoteUpdates();
            for (RemoteRefUpdate update : updates) {
                parseRemoteRefUpdate(update);
            }
        }
    } catch (TransportException e) {
        setException(e);
        handleAuthError(this);
        return false;
    } catch (Exception e) {
        setException(e);
        return false;
    } catch (OutOfMemoryError e) {
        setException(e, R.string.error_out_of_memory);
        return false;
    } catch (Throwable e) {
        setException(e);
        return false;
    }
    return true;
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushResult(org.eclipse.jgit.transport.PushResult) TransportException(org.eclipse.jgit.api.errors.TransportException) PushCommand(org.eclipse.jgit.api.PushCommand) TransportException(org.eclipse.jgit.api.errors.TransportException) StopTaskException(me.sheimi.sgit.exception.StopTaskException) SgitTransportCallback(me.sheimi.sgit.ssh.SgitTransportCallback) Git(org.eclipse.jgit.api.Git) RefSpec(org.eclipse.jgit.transport.RefSpec) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 3 with SgitTransportCallback

use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.

the class CloneTask method cloneRepo.

public boolean cloneRepo() {
    File localRepo = mRepo.getDir();
    CloneCommand cloneCommand = Git.cloneRepository().setURI(mRepo.getRemoteURL()).setCloneAllBranches(true).setProgressMonitor(new RepoCloneMonitor()).setTransportConfigCallback(new SgitTransportCallback()).setDirectory(localRepo).setCloneSubmodules(mCloneRecursive);
    setCredentials(cloneCommand);
    try {
        cloneCommand.call();
        Profile.setLastCloneSuccess();
    } catch (InvalidRemoteException e) {
        setException(e, R.string.error_invalid_remote);
        Profile.setLastCloneFailed(mRepo);
        return false;
    } catch (TransportException e) {
        setException(e);
        Profile.setLastCloneFailed(mRepo);
        handleAuthError(this);
        return false;
    } catch (GitAPIException e) {
        setException(e, R.string.error_clone_failed);
        return false;
    } catch (JGitInternalException e) {
        setException(e);
        return false;
    } catch (OutOfMemoryError e) {
        setException(e, R.string.error_out_of_memory);
        return false;
    } catch (Throwable e) {
        setException(e);
        return false;
    }
    return true;
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) SgitTransportCallback(me.sheimi.sgit.ssh.SgitTransportCallback) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) File(java.io.File) TransportException(org.eclipse.jgit.api.errors.TransportException)

Example 4 with SgitTransportCallback

use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.

the class FetchTask method fetchRepo.

private boolean fetchRepo(String remote) {
    Git git;
    try {
        git = mRepo.getGit();
    } catch (StopTaskException e) {
        return false;
    }
    final FetchCommand fetchCommand = git.fetch().setProgressMonitor(new BasicProgressMonitor()).setTransportConfigCallback(new SgitTransportCallback()).setRemote(remote);
    setCredentials(fetchCommand);
    try {
        fetchCommand.call();
    } catch (TransportException e) {
        setException(e);
        handleAuthError(this);
        return false;
    } catch (Exception e) {
        setException(e, R.string.error_pull_failed);
        return false;
    } catch (OutOfMemoryError e) {
        setException(e, R.string.error_out_of_memory);
        return false;
    } catch (Throwable e) {
        setException(e);
        return false;
    }
    mRepo.updateLatestCommitInfo();
    return true;
}
Also used : SgitTransportCallback(me.sheimi.sgit.ssh.SgitTransportCallback) Git(org.eclipse.jgit.api.Git) FetchCommand(org.eclipse.jgit.api.FetchCommand) StopTaskException(me.sheimi.sgit.exception.StopTaskException) TransportException(org.eclipse.jgit.api.errors.TransportException) TransportException(org.eclipse.jgit.api.errors.TransportException) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Aggregations

SgitTransportCallback (me.sheimi.sgit.ssh.SgitTransportCallback)4 TransportException (org.eclipse.jgit.api.errors.TransportException)4 StopTaskException (me.sheimi.sgit.exception.StopTaskException)3 Git (org.eclipse.jgit.api.Git)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 File (java.io.File)1 CloneCommand (org.eclipse.jgit.api.CloneCommand)1 FetchCommand (org.eclipse.jgit.api.FetchCommand)1 PullCommand (org.eclipse.jgit.api.PullCommand)1 PushCommand (org.eclipse.jgit.api.PushCommand)1 InvalidRemoteException (org.eclipse.jgit.api.errors.InvalidRemoteException)1 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)1 PushResult (org.eclipse.jgit.transport.PushResult)1 RefSpec (org.eclipse.jgit.transport.RefSpec)1 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)1