use of org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException in project egit by eclipse.
the class DeleteBranchOperation method execute.
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor actMonitor) throws CoreException {
String taskName;
if (branches.size() == 1)
taskName = NLS.bind(CoreText.DeleteBranchOperation_TaskName, branches.iterator().next().getName());
else {
StringBuilder names = new StringBuilder();
for (Iterator<Ref> it = branches.iterator(); it.hasNext(); ) {
Ref ref = it.next();
names.append(ref.getName());
if (it.hasNext())
// $NON-NLS-1$
names.append(", ");
}
taskName = NLS.bind(CoreText.DeleteBranchOperation_TaskName, names);
}
SubMonitor progress = SubMonitor.convert(actMonitor, taskName, branches.size());
for (Ref branch : branches) {
if (progress.isCanceled()) {
throw new OperationCanceledException(CoreText.DeleteBranchOperation_Canceled);
}
try (Git git = new Git(repository)) {
git.branchDelete().setBranchNames(branch.getName()).setForce(force).call();
status = OK;
} catch (NotMergedException e) {
status = REJECTED_UNMERGED;
break;
} catch (CannotDeleteCurrentBranchException e) {
status = REJECTED_CURRENT;
break;
} catch (JGitInternalException e) {
throw new CoreException(Activator.error(e.getMessage(), e));
} catch (GitAPIException e) {
throw new CoreException(Activator.error(e.getMessage(), e));
}
progress.worked(1);
}
}
};
// lock workspace to protect working tree changes
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
use of org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException 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