aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorzeapo <mohamed@zenadi.com>2017-08-10 14:19:24 +0200
committerzeapo <mohamed@zenadi.com>2017-08-10 14:19:24 +0200
commit24a77b90284ee6a0832245c7f8d1d432b9db3710 (patch)
tree44ffcc402cd6c6dc3737267565e1c18539629ed1 /app/src/main/java
parentd284e292377e152768c264a807325f98206312ae (diff)
detect error during push
fix #280
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java26
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java5
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java5
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) {