Search in sources :

Example 11 with StopTaskException

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

the class ConfigAction method execute.

@Override
public void execute() {
    try {
        DialogRepoConfigBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mActivity), R.layout.dialog_repo_config, null, false);
        GitConfig gitConfig = new GitConfig(mRepo);
        binding.setViewModel(gitConfig);
        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
        builder.setView(binding.getRoot()).setNeutralButton(R.string.label_done, null).create().show();
    } catch (StopTaskException e) {
        // FIXME: show error to user
        Timber.e(e);
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogRepoConfigBinding(me.sheimi.sgit.databinding.DialogRepoConfigBinding) GitConfig(me.sheimi.sgit.database.models.GitConfig) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 12 with StopTaskException

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

the class Repo method getRemoteOriginURL.

public String getRemoteOriginURL() {
    try {
        StoredConfig config = getStoredConfig();
        String origin = config.getString("remote", "origin", "url");
        if (origin != null && !origin.isEmpty())
            return origin;
        Set<String> remoteNames = config.getSubsections("remote");
        if (remoteNames.size() == 0)
            return "";
        String url = config.getString("remote", remoteNames.iterator().next(), "url");
        return url;
    } catch (StopTaskException e) {
    }
    return "";
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 13 with StopTaskException

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

the class Repo method getBranches.

public String[] getBranches() {
    try {
        Set<String> branchSet = new HashSet<String>();
        List<String> branchList = new ArrayList<String>();
        List<Ref> localRefs = getGit().branchList().call();
        for (Ref ref : localRefs) {
            branchSet.add(ref.getName());
            branchList.add(ref.getName());
        }
        List<Ref> remoteRefs = getGit().branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
        for (Ref ref : remoteRefs) {
            String name = ref.getName();
            String localName = convertRemoteName(name);
            if (branchSet.contains(localName))
                continue;
            branchList.add(name);
        }
        return branchList.toArray(new String[0]);
    } catch (GitAPIException | StopTaskException e) {
        Timber.e(e);
    }
    return new String[0];
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Ref(org.eclipse.jgit.lib.Ref) ArrayList(java.util.ArrayList) StopTaskException(me.sheimi.sgit.exception.StopTaskException) HashSet(java.util.HashSet)

Example 14 with StopTaskException

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

the class Repo method getRemotes.

public Set<String> getRemotes() {
    if (mRemotes != null)
        return mRemotes;
    try {
        StoredConfig config = getStoredConfig();
        Set<String> remotes = config.getSubsections("remote");
        mRemotes = new HashSet<String>(remotes);
        return mRemotes;
    } catch (StopTaskException e) {
    }
    return new HashSet<String>();
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) StopTaskException(me.sheimi.sgit.exception.StopTaskException) HashSet(java.util.HashSet)

Example 15 with StopTaskException

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

the class Repo method getCommitByRevStr.

private RevCommit getCommitByRevStr(String commitRevStr) {
    try {
        Repository repository = getGit().getRepository();
        ObjectId id = repository.resolve(commitRevStr);
        RevWalk revWalk = new RevWalk(getGit().getRepository());
        return (id != null) ? revWalk.parseCommit(id) : null;
    } catch (StopTaskException | IOException e) {
        Timber.e(e, "error parsing commit id: %s", commitRevStr);
        return null;
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

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