diff options
| author | Mohamed Zenadi <zeapo@users.noreply.github.com> | 2016-12-11 16:57:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-12-11 16:57:17 +0100 |
| commit | 737d2819273e7ba07d3a993422b138b93b852415 (patch) | |
| tree | d3f03de3764a39560b24e1b550bc0eed2feedd38 /app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java | |
| parent | fd9e958d40a56a2a3b8dfbef86944d3d5f53fec2 (diff) | |
| download | HardenedPass-737d2819273e7ba07d3a993422b138b93b852415.tar.gz HardenedPass-737d2819273e7ba07d3a993422b138b93b852415.zip | |
Handle jgit errors (#243)
* initial work on the git error handling
* remove throws exception and handle the jsch one correctly
* move the commit task into its own operation
* get rid of the interface and rely on the abstract class GitOperation
* add error message to the pull command
* add error message to the push command
* add error message to the sync operationˆ
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java index dc94ce3b..d46513fd 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java @@ -1,7 +1,13 @@ package com.zeapo.pwdstore.git; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import com.zeapo.pwdstore.R; +import com.zeapo.pwdstore.utils.PasswordRepository; + +import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.Git; @@ -12,7 +18,8 @@ public class CloneOperation extends GitOperation { /** * Creates a new clone operation - * @param fileDir the git working tree directory + * + * @param fileDir the git working tree directory * @param callingActivity the calling activity */ public CloneOperation(File fileDir, Activity callingActivity) { @@ -21,6 +28,7 @@ public class CloneOperation extends GitOperation { /** * Sets the command using the repository uri + * * @param uri the uri of the repository * @return the current object */ @@ -34,6 +42,7 @@ public class CloneOperation extends GitOperation { /** * sets the authentication for user/pwd scheme + * * @param username the username * @param password the password * @return the current object @@ -46,6 +55,7 @@ public class CloneOperation extends GitOperation { /** * sets the authentication for the ssh-key scheme + * * @param sshKey the ssh-key file * @param username the username * @param passphrase the passphrase @@ -58,10 +68,31 @@ public class CloneOperation extends GitOperation { } @Override - public void execute() throws Exception { + public void execute() { if (this.provider != null) { ((CloneCommand) this.command).setCredentialsProvider(this.provider); } - new GitAsyncTask(callingActivity, true, false, CloneCommand.class).execute(this.command); + new GitAsyncTask(callingActivity, true, false, this).execute(this.command); + } + + @Override + public void onTaskEnded(String result) { + new AlertDialog.Builder(callingActivity). + setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). + setMessage("Error occured during the clone operation, " + + callingActivity.getResources().getString(R.string.jgit_error_dialog_text) + + result + + "\nPlease check the FAQ for possible reasons why this error might occur."). + setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + // if we were unable to finish the job + try { + FileUtils.deleteDirectory(PasswordRepository.getWorkTree()); + } catch (Exception e) { + e.printStackTrace(); + } + } + }).show(); } } |
