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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations