summaryrefslogtreecommitdiff
path: root/app/src
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
parentd284e292377e152768c264a807325f98206312ae (diff)
detect error during push
fix #280
Diffstat (limited to 'app/src')
-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
-rw-r--r--app/src/main/res/values/strings.xml4
4 files changed, 32 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) {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0641385c..7805ad08 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -204,4 +204,8 @@
<string name="autofill_ins_1_hint">Screenshot of accessibility services</string>
<string name="autofill_ins_2_hint">Screenshot of toggle in accessibility services</string>
<string name="autofill_ins_3_hint">Screenshot of autofill service in action</string>
+ <string name="git_push_nff_error">Push was rejected by remote, run pull before pushing again. You can use Synchronize rather than pull/push as it implements both</string>
+ <string name="git_push_generic_error">Push was rejected by remote, reason:</string>
+ <string name="git_push_other_error">Remote rejected non-fast-forward push. Check receive.denyNonFastForwards variable in config file of destination repository.</string>
+ <string name="jgit_error_push_dialog_text">Error occurred during the push operation:</string>
</resources>