diff options
Diffstat (limited to 'app/src/main/java')
3 files changed, 28 insertions, 8 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java index 26af4c89..a42e5d78 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java @@ -10,7 +10,10 @@ import com.zeapo.pwdstore.R; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.GitCommand; +import org.eclipse.jgit.api.PushCommand; import org.eclipse.jgit.api.StatusCommand; +import org.eclipse.jgit.transport.PushResult; +import org.eclipse.jgit.transport.RemoteRefUpdate; public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> { @@ -49,6 +52,29 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> { // the previous status will eventually be used to avoid a commit if (nbChanges == null || nbChanges > 0) command.call(); + }else if (command instanceof PushCommand) { + for (final PushResult result : ((PushCommand) command).call()) { + // Code imported (modified) from Gerrit PushOp, license Apache v2 + for (final RemoteRefUpdate rru : result.getRemoteUpdates()) { + switch (rru.getStatus()) { + case REJECTED_NONFASTFORWARD: + return activity.getString(R.string.git_push_nff_error); + case REJECTED_NODELETE: + case REJECTED_REMOTE_CHANGED: + case NON_EXISTING: + case NOT_ATTEMPTED: + return activity.getString(R.string.git_push_generic_error) + rru.getStatus().name(); + case REJECTED_OTHER_REASON: + if ("non-fast-forward".equals(rru.getMessage())) { + return activity.getString(R.string.git_push_other_error); + } else { + return activity.getString(R.string.git_push_generic_error) + rru.getMessage(); + } + default: + break; + } + } + } } else { command.call(); } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java index 6f886687..fe8a083c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java @@ -213,10 +213,7 @@ public abstract class GitOperation { public void onTaskEnded(String result) { new AlertDialog.Builder(callingActivity). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). - setMessage("Error occurred during a Git operation, " - + callingActivity.getResources().getString(R.string.jgit_error_dialog_text) - + result - + "\nPlease check the FAQ for possible reasons why this error might occur."). + setMessage(callingActivity.getResources().getString(R.string.jgit_error_dialog_text) + result). setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java index 2774af90..56e069d3 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java @@ -48,10 +48,7 @@ public class PushOperation extends GitOperation { // TODO handle the "Nothing to push" case new AlertDialog.Builder(callingActivity). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). - setMessage("Error occured during the push operation, " - + callingActivity.getResources().getString(R.string.jgit_error_dialog_text) - + result - + "\nPlease check the FAQ for possible reasons why this error might occur."). + setMessage(callingActivity.getString(R.string.jgit_error_push_dialog_text) + result). setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { |