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();
}
}
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) {
}
}
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) {
}
}
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();
}
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;
}
Aggregations