From 737d2819273e7ba07d3a993422b138b93b852415 Mon Sep 17 00:00:00 2001 From: Mohamed Zenadi Date: Sun, 11 Dec 2016 16:57:17 +0100 Subject: Handle jgit errors (#243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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ˆ --- .../com/zeapo/pwdstore/git/CloneOperation.java | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java') 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(); } } -- cgit v1.2.3