From 24a77b90284ee6a0832245c7f8d1d432b9db3710 Mon Sep 17 00:00:00 2001 From: zeapo Date: Thu, 10 Aug 2017 14:19:24 +0200 Subject: detect error during push fix #280 --- .../java/com/zeapo/pwdstore/git/GitAsyncTask.java | 26 ++++++++++++++++++++++ .../java/com/zeapo/pwdstore/git/GitOperation.java | 5 +---- .../java/com/zeapo/pwdstore/git/PushOperation.java | 5 +---- app/src/main/res/values/strings.xml | 4 ++++ 4 files changed, 32 insertions(+), 8 deletions(-) (limited to 'app/src') 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 { @@ -49,6 +52,29 @@ public class GitAsyncTask extends AsyncTask { // 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 @@ Screenshot of accessibility services Screenshot of toggle in accessibility services Screenshot of autofill service in action + Push was rejected by remote, run pull before pushing again. You can use Synchronize rather than pull/push as it implements both + Push was rejected by remote, reason: + Remote rejected non-fast-forward push. Check receive.denyNonFastForwards variable in config file of destination repository. + Error occurred during the push operation: -- cgit v1.2.3