Search in sources :

Example 6 with StopTaskException

use of me.sheimi.sgit.exception.StopTaskException in project MGit by maks.

the class CommitDiffTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    boolean result = getCommitDiff();
    if (!result) {
        return false;
    }
    mDiffStrs = new ArrayList<String>(mDiffEntries.size());
    for (DiffEntry diffEntry : mDiffEntries) {
        try {
            String diffStr = parseDiffEntry(diffEntry);
            mDiffStrs.add(diffStr);
        } catch (StopTaskException e) {
            return false;
        }
    }
    return true;
}
Also used : StopTaskException(me.sheimi.sgit.exception.StopTaskException) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Example 7 with StopTaskException

use of me.sheimi.sgit.exception.StopTaskException 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 8 with StopTaskException

use of me.sheimi.sgit.exception.StopTaskException in project MGit by maks.

the class GetCommitTask method getCommitsList.

public boolean getCommitsList() {
    try {
        LogCommand cmd = mRepo.getGit().log();
        if (mFile != null)
            cmd.addPath(mFile);
        Iterable<RevCommit> commits = cmd.call();
        mResult = new ArrayList<RevCommit>();
        for (RevCommit commit : commits) {
            mResult.add(commit);
        }
    } catch (GitAPIException e) {
        setException(e);
        return false;
    } catch (StopTaskException e) {
        return false;
    } catch (Throwable e) {
        setException(e);
        return false;
    }
    return true;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) LogCommand(org.eclipse.jgit.api.LogCommand) StopTaskException(me.sheimi.sgit.exception.StopTaskException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 9 with StopTaskException

use of me.sheimi.sgit.exception.StopTaskException 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 10 with StopTaskException

use of me.sheimi.sgit.exception.StopTaskException in project MGit by maks.

the class BranchChooserActivity method onActionItemClicked.

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_mode_rename_branch:
            Bundle pathArg = new Bundle();
            pathArg.putString(RenameBranchDialog.FROM_COMMIT, mChosenCommit);
            pathArg.putSerializable(Repo.TAG, mRepo);
            mode.finish();
            RenameBranchDialog rbd = new RenameBranchDialog();
            rbd.setArguments(pathArg);
            rbd.show(getFragmentManager(), "rename-dialog");
            return true;
        case R.id.action_mode_delete:
            AlertDialog.Builder alert = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(getString(R.string.dialog_branch_delete) + " " + mChosenCommit).setMessage(R.string.dialog_branch_delete_msg).setPositiveButton(R.string.label_delete, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int commitType = Repo.getCommitType(mChosenCommit);
                    try {
                        switch(commitType) {
                            case Repo.COMMIT_TYPE_HEAD:
                                mRepo.getGit().branchDelete().setBranchNames(mChosenCommit).setForce(true).call();
                                break;
                            case Repo.COMMIT_TYPE_TAG:
                                mRepo.getGit().tagDelete().setTags(mChosenCommit).call();
                                break;
                        }
                    } catch (StopTaskException e) {
                        Log.e(LOGTAG, "can't delete " + mChosenCommit, e);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(BranchChooserActivity.this, getString(R.string.cannot_delete_branch, mChosenCommit), Toast.LENGTH_LONG).show();
                            }
                        });
                    } catch (CannotDeleteCurrentBranchException e) {
                        Log.e(LOGTAG, "can't delete " + mChosenCommit, e);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(BranchChooserActivity.this, getString(R.string.cannot_delete_current_branch, mChosenCommit), Toast.LENGTH_LONG).show();
                            }
                        });
                    } catch (GitAPIException e) {
                        Log.e(LOGTAG, "can't delete " + mChosenCommit, e);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(BranchChooserActivity.this, getString(R.string.cannot_delete_branch, mChosenCommit), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                    refreshList();
                }
            }).setNegativeButton(R.string.label_cancel, null);
            mode.finish();
            alert.show();
            return true;
        default:
            return false;
    }
}
Also used : AlertDialog(android.app.AlertDialog) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RenameBranchDialog(me.sheimi.sgit.dialogs.RenameBranchDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) StopTaskException(me.sheimi.sgit.exception.StopTaskException) CannotDeleteCurrentBranchException(org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException)

Aggregations

StopTaskException (me.sheimi.sgit.exception.StopTaskException)20 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 IOException (java.io.IOException)6 StoredConfig (org.eclipse.jgit.lib.StoredConfig)5 SgitTransportCallback (me.sheimi.sgit.ssh.SgitTransportCallback)3 Git (org.eclipse.jgit.api.Git)3 TransportException (org.eclipse.jgit.api.errors.TransportException)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 AlertDialog (android.app.AlertDialog)2 File (java.io.File)2 HashSet (java.util.HashSet)2 Ref (org.eclipse.jgit.lib.Ref)2 Repository (org.eclipse.jgit.lib.Repository)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1