Search in sources :

Example 1 with StopTaskException

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

the class Repo method getGit.

public Git getGit() throws StopTaskException {
    if (mGit != null)
        return mGit;
    try {
        File repoFile = getDir();
        mGit = Git.open(repoFile);
        return mGit;
    } catch (IOException e) {
        Timber.e(e);
        throw new StopTaskException();
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 2 with StopTaskException

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

the class Repo method setRemote.

public void setRemote(String remote, String url) throws IOException {
    try {
        StoredConfig config = getStoredConfig();
        Set<String> remoteNames = config.getSubsections("remote");
        if (remoteNames.contains(remote)) {
            throw new IOException(String.format("Remote %s already exists.", remote));
        }
        config.setString("remote", remote, "url", url);
        String fetch = String.format("+refs/heads/*:refs/remotes/%s/*", remote);
        config.setString("remote", remote, "fetch", fetch);
        config.save();
        mRemotes.add(remote);
    } catch (StopTaskException e) {
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) IOException(java.io.IOException) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 3 with StopTaskException

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

the class Repo method removeRemote.

public void removeRemote(String remote) throws IOException {
    try {
        StoredConfig config = getStoredConfig();
        Set<String> remoteNames = config.getSubsections("remote");
        if (!remoteNames.contains(remote)) {
            throw new IOException(String.format("Remote %s does not exist.", remote));
        }
        config.unsetSection("remote", remote);
        config.save();
        mRemotes.remove(remote);
    } catch (StopTaskException e) {
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) IOException(java.io.IOException) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 4 with StopTaskException

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

the class RenameBranchDialog method onClick.

@Override
public void onClick(View view) {
    String newBranchname = mNewBranchname.getText().toString().trim();
    if (newBranchname.equals("")) {
        Toast.makeText(mActivity, getString(R.string.alert_new_branchname_required), Toast.LENGTH_LONG).show();
        mNewBranchname.setError(getString(R.string.alert_new_branchname_required));
        return;
    }
    int commitType = Repo.getCommitType(mFromCommit);
    boolean fail = false;
    try {
        switch(commitType) {
            case Repo.COMMIT_TYPE_HEAD:
                mRepo.getGit().branchRename().setOldName(mFromCommit).setNewName(newBranchname).call();
                break;
            case Repo.COMMIT_TYPE_TAG:
                RevTag tag = null;
                List<Ref> refs = mRepo.getGit().tagList().call();
                for (int i = 0; i < refs.size(); ++i) {
                    if (refs.get(i).getName().equals(mFromCommit)) {
                        tag = new RevWalk(mRepo.getGit().getRepository()).lookupTag(refs.get(i).getObjectId());
                        break;
                    }
                }
                if (tag == null) {
                    fail = true;
                    break;
                }
                mRepo.getGit().tag().setMessage(tag.getFullMessage()).setName(newBranchname).setObjectId(tag.getObject()).setTagger(tag.getTaggerIdent()).call();
                mRepo.getGit().tagDelete().setTags(mFromCommit).call();
                break;
        }
    } catch (StopTaskException e) {
        fail = true;
    } catch (GitAPIException e) {
        fail = true;
    }
    if (fail) {
        mActivity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(mActivity, "can't rename " + mFromCommit, Toast.LENGTH_LONG).show();
            }
        });
    }
    mActivity.refreshList();
    dismiss();
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Ref(org.eclipse.jgit.lib.Ref) RevTag(org.eclipse.jgit.revwalk.RevTag) RevWalk(org.eclipse.jgit.revwalk.RevWalk) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 5 with StopTaskException

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

the class CommitDiffTask method getCommitDiff.

public boolean getCommitDiff() {
    try {
        Repository repo = mRepo.getGit().getRepository();
        mDiffOutput = new ByteArrayOutputStream();
        mDiffFormatter = new DiffFormatter(mDiffOutput);
        mDiffFormatter.setRepository(repo);
        AbstractTreeIterator mOldCommitTreeIterator = mRepo.isInitialCommit(mNewCommit) ? new EmptyTreeIterator() : getTreeIterator(repo, mOldCommit);
        AbstractTreeIterator mNewCommitTreeIterator = getTreeIterator(repo, mNewCommit);
        mDiffEntries = mDiffFormatter.scan(mOldCommitTreeIterator, mNewCommitTreeIterator);
        if (mShowDescription) {
            ObjectId newCommitId = repo.resolve(mNewCommit);
            mCommits = mRepo.getGit().log().add(newCommitId).setMaxCount(1).call();
        } else {
            mCommits = new ArrayList<RevCommit>();
        }
        return true;
    } catch (GitAPIException e) {
        setException(e);
    } catch (IncorrectObjectTypeException e) {
        setException(e, R.string.error_diff_failed);
    } catch (AmbiguousObjectException e) {
        setException(e, R.string.error_diff_failed);
    } catch (IOException e) {
        setException(e, R.string.error_diff_failed);
    } catch (IllegalStateException e) {
        setException(e, R.string.error_diff_failed);
    } catch (NullPointerException e) {
        setException(e, R.string.error_diff_failed);
    } catch (StopTaskException e) {
    }
    return false;
}
Also used : AmbiguousObjectException(org.eclipse.jgit.errors.AmbiguousObjectException) ObjectId(org.eclipse.jgit.lib.ObjectId) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) AbstractTreeIterator(org.eclipse.jgit.treewalk.AbstractTreeIterator) Repository(org.eclipse.jgit.lib.Repository) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) StopTaskException(me.sheimi.sgit.exception.StopTaskException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

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