Search in sources :

Example 16 with StopTaskException

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

the class CommitChangesTask method commit.

public static void commit(Repo repo, boolean stageAll, boolean isAmend, String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, GitAPIException, StopTaskException {
    Context context = SGitApplication.getContext();
    StoredConfig config = repo.getGit().getRepository().getConfig();
    String committerEmail = config.getString("user", null, "email");
    String committerName = config.getString("user", null, "name");
    if (committerName == null || committerName.equals("")) {
        committerName = Profile.getUsername(context);
    }
    if (committerEmail == null || committerEmail.equals("")) {
        committerEmail = Profile.getEmail(context);
    }
    if (committerName.isEmpty() || committerEmail.isEmpty()) {
        throw new Exception("Please set your name and email");
    }
    if (msg.isEmpty()) {
        throw new Exception("Please include a commit message");
    }
    CommitCommand cc = repo.getGit().commit().setCommitter(committerName, committerEmail).setAll(stageAll).setAmend(isAmend).setMessage(msg);
    if (authorName != null && authorEmail != null) {
        cc.setAuthor(authorName, authorEmail);
    }
    cc.call();
    repo.updateLatestCommitInfo();
}
Also used : Context(android.content.Context) StoredConfig(org.eclipse.jgit.lib.StoredConfig) CommitCommand(org.eclipse.jgit.api.CommitCommand) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) StopTaskException(me.sheimi.sgit.exception.StopTaskException) UnmergedPathsException(org.eclipse.jgit.api.errors.UnmergedPathsException) NoMessageException(org.eclipse.jgit.api.errors.NoMessageException)

Example 17 with StopTaskException

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

the class DeleteFileFromRepoTask method removeFile.

public boolean removeFile() {
    try {
        switch(mOperationType) {
            case DELETE:
                File fileToDelete = FsUtils.joinPath(mRepo.getDir(), mFilePattern);
                FsUtils.deleteFile(fileToDelete);
                break;
            case REMOVE_CACHED:
                mRepo.getGit().rm().setCached(true).addFilepattern(mFilePattern).call();
                break;
            case REMOVE_FORCE:
                mRepo.getGit().rm().addFilepattern(mFilePattern).call();
                break;
        }
    } catch (StopTaskException e) {
        return false;
    } catch (Throwable e) {
        setException(e);
        return false;
    }
    return true;
}
Also used : File(java.io.File) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 18 with StopTaskException

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

the class CherryPickTask method cherrypick.

public boolean cherrypick() {
    try {
        ObjectId commit = mRepo.getGit().getRepository().resolve(mCommitStr);
        mRepo.getGit().cherryPick().include(commit).call();
    } catch (StopTaskException e) {
        return false;
    } catch (Throwable e) {
        setException(e);
        return false;
    }
    return true;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 19 with StopTaskException

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

the class CommitDiffTask method parseDiffEntry.

private String parseDiffEntry(DiffEntry diffEntry) throws StopTaskException {
    try {
        mDiffOutput.reset();
        mDiffFormatter.format(diffEntry);
        mDiffFormatter.flush();
        String diffText = mDiffOutput.toString("UTF-8");
        return diffText;
    } catch (UnsupportedEncodingException e) {
        setException(e, R.string.error_diff_failed);
        throw new StopTaskException();
    } catch (IOException e) {
        setException(e, R.string.error_diff_failed);
        throw new StopTaskException();
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) StopTaskException(me.sheimi.sgit.exception.StopTaskException)

Example 20 with StopTaskException

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

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