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ˆ
This commit is contained in:
Mohamed Zenadi
2016-12-11 16:57:17 +01:00
committed by GitHub
parent fd9e958d40
commit 737d281927
8 changed files with 190 additions and 111 deletions

View File

@@ -28,13 +28,13 @@ import android.widget.TextView;
import com.zeapo.pwdstore.crypto.PgpHandler; import com.zeapo.pwdstore.crypto.PgpHandler;
import com.zeapo.pwdstore.git.GitActivity; import com.zeapo.pwdstore.git.GitActivity;
import com.zeapo.pwdstore.git.GitAsyncTask; import com.zeapo.pwdstore.git.GitAsyncTask;
import com.zeapo.pwdstore.git.GitOperation;
import com.zeapo.pwdstore.pwgen.PRNGFixes; import com.zeapo.pwdstore.pwgen.PRNGFixes;
import com.zeapo.pwdstore.utils.PasswordItem; import com.zeapo.pwdstore.utils.PasswordItem;
import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter; import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter;
import com.zeapo.pwdstore.utils.PasswordRepository; import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@@ -57,6 +57,7 @@ public class PasswordStore extends AppCompatActivity {
private final static int HOME = 403; private final static int HOME = 403;
private final static int REQUEST_EXTERNAL_STORAGE = 50; private final static int REQUEST_EXTERNAL_STORAGE = 50;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
@@ -74,7 +75,7 @@ public class PasswordStore extends AppCompatActivity {
} }
@Override @Override
public void onResume(){ public void onResume() {
super.onResume(); super.onResume();
// do not attempt to checkLocalRepository() if no storage permission: immediate crash // do not attempt to checkLocalRepository() if no storage permission: immediate crash
if (settings.getBoolean("git_external", false)) { if (settings.getBoolean("git_external", false)) {
@@ -373,10 +374,9 @@ public class PasswordStore extends AppCompatActivity {
} }
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if ((null != plist) && plist.isNotEmpty()) { if ((null != plist) && plist.isNotEmpty()) {
plist.popBack(); plist.popBack();
} else { } else {
super.onBackPressed(); super.onBackPressed();
@@ -438,20 +438,12 @@ public class PasswordStore extends AppCompatActivity {
.setPositiveButton(this.getResources().getString(R.string.dialog_yes), new DialogInterface.OnClickListener() { .setPositiveButton(this.getResources().getString(R.string.dialog_yes), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
String path = item.getFile().getAbsolutePath();
item.getFile().delete(); item.getFile().delete();
adapter.remove(position); adapter.remove(position);
it.remove(); it.remove();
adapter.updateSelectedItems(position, selectedItems); adapter.updateSelectedItems(position, selectedItems);
setResult(RESULT_CANCELED); commit("[ANDROID PwdStore] Remove " + item + " from store.");
Repository repo = PasswordRepository.getRepository(PasswordRepository.getRepositoryDirectory(activity));
Git git = new Git(repo);
GitAsyncTask tasks = new GitAsyncTask(activity, false, true, CommitCommand.class);
tasks.execute(
git.rm().addFilepattern(path.replace(PasswordRepository.getWorkTree() + "/", "")),
git.commit().setMessage("[ANDROID PwdStore] Remove " + item + " from store.")
);
deletePasswords(adapter, selectedItems); deletePasswords(adapter, selectedItems);
} }
}) })
@@ -468,10 +460,10 @@ public class PasswordStore extends AppCompatActivity {
public void movePasswords(ArrayList<PasswordItem> values) { public void movePasswords(ArrayList<PasswordItem> values) {
Intent intent = new Intent(this, PgpHandler.class); Intent intent = new Intent(this, PgpHandler.class);
ArrayList<String> fileLocations = new ArrayList<>(); ArrayList<String> fileLocations = new ArrayList<>();
for (PasswordItem passwordItem : values){ for (PasswordItem passwordItem : values) {
fileLocations.add(passwordItem.getFile().getAbsolutePath()); fileLocations.add(passwordItem.getFile().getAbsolutePath());
} }
intent.putExtra("Files",fileLocations); intent.putExtra("Files", fileLocations);
intent.putExtra("Operation", "SELECTFOLDER"); intent.putExtra("Operation", "SELECTFOLDER");
startActivityForResult(intent, PgpHandler.REQUEST_CODE_SELECT_FOLDER); startActivityForResult(intent, PgpHandler.REQUEST_CODE_SELECT_FOLDER);
} }
@@ -480,7 +472,7 @@ public class PasswordStore extends AppCompatActivity {
* clears adapter's content and updates it with a fresh list of passwords from the root * clears adapter's content and updates it with a fresh list of passwords from the root
*/ */
public void updateListAdapter() { public void updateListAdapter() {
if ((null != plist)) { if ((null != plist)) {
plist.updateAdapter(); plist.updateAdapter();
} }
} }
@@ -489,31 +481,36 @@ public class PasswordStore extends AppCompatActivity {
* Updates the adapter with the current view of passwords * Updates the adapter with the current view of passwords
*/ */
public void refreshListAdapter() { public void refreshListAdapter() {
if ((null != plist)) { if ((null != plist)) {
plist.refreshAdapter(); plist.refreshAdapter();
} }
} }
public void filterListAdapter(String filter) { public void filterListAdapter(String filter) {
if ((null != plist)) { if ((null != plist)) {
plist.filterAdapter(filter); plist.filterAdapter(filter);
} }
} }
private File getCurrentDir() { private File getCurrentDir() {
if ((null != plist)) { if ((null != plist)) {
return plist.getCurrentDir(); return plist.getCurrentDir();
} }
return PasswordRepository.getWorkTree(); return PasswordRepository.getWorkTree();
} }
private void commit(String message) { private void commit(final String message) {
Git git = new Git(PasswordRepository.getRepository(new File(""))); new GitOperation(PasswordRepository.getRepositoryDirectory(activity), activity) {
GitAsyncTask tasks = new GitAsyncTask(this, false, false, CommitCommand.class); @Override
tasks.execute( public void execute() {
git.add().addFilepattern("."), Git git = new Git(this.repository);
git.commit().setMessage(message) GitAsyncTask tasks = new GitAsyncTask(activity, false, true, this);
); tasks.execute(
git.add().addFilepattern("."),
git.commit().setMessage(message)
);
}
};
} }
protected void onActivityResult(int requestCode, int resultCode, protected void onActivityResult(int requestCode, int resultCode,
@@ -573,31 +570,29 @@ public class PasswordStore extends AppCompatActivity {
startActivityForResult(intent, GitActivity.REQUEST_CLONE); startActivityForResult(intent, GitActivity.REQUEST_CLONE);
break; break;
case PgpHandler.REQUEST_CODE_SELECT_FOLDER: case PgpHandler.REQUEST_CODE_SELECT_FOLDER:
Log.d("Moving","Moving passwords to "+data.getStringExtra("SELECTED_FOLDER_PATH")); Log.d("Moving", "Moving passwords to " + data.getStringExtra("SELECTED_FOLDER_PATH"));
Log.d("Moving", TextUtils.join(", ", data.getStringArrayListExtra("Files"))); Log.d("Moving", TextUtils.join(", ", data.getStringArrayListExtra("Files")));
File target = new File(data.getStringExtra("SELECTED_FOLDER_PATH")); File target = new File(data.getStringExtra("SELECTED_FOLDER_PATH"));
if (!target.isDirectory()){ if (!target.isDirectory()) {
Log.e("Moving","Tried moving passwords to a non-existing folder."); Log.e("Moving", "Tried moving passwords to a non-existing folder.");
break; break;
} }
Repository repo = PasswordRepository.getRepository(PasswordRepository.getRepositoryDirectory(activity)); for (String string : data.getStringArrayListExtra("Files")) {
Git git = new Git(repo);
GitAsyncTask tasks = new GitAsyncTask(activity, false, true, CommitCommand.class);
for (String string : data.getStringArrayListExtra("Files")){
File source = new File(string); File source = new File(string);
if (!source.exists()){ if (!source.exists()) {
Log.e("Moving","Tried moving something that appears non-existent."); Log.e("Moving", "Tried moving something that appears non-existent.");
continue; continue;
} }
if (!source.renameTo(new File(target.getAbsolutePath()+"/"+source.getName()))){ if (!source.renameTo(new File(target.getAbsolutePath() + "/" + source.getName()))) {
Log.e("Moving","Something went wrong while moving."); // TODO this should show a warning to the user
}else{ Log.e("Moving", "Something went wrong while moving.");
tasks.execute( } else {
git.add().addFilepattern(source.getAbsolutePath().replace(PasswordRepository.getWorkTree() + "/", "")), commit("[ANDROID PwdStore] Moved "
git.commit().setMessage("[ANDROID PwdStore] Moved "+string.replace(PasswordRepository.getWorkTree() + "/", "")+" to "+target.getAbsolutePath().replace(PasswordRepository.getWorkTree() + "/","")+target.getAbsolutePath()+"/"+source.getName()+".") + string.replace(PasswordRepository.getWorkTree() + "/", "")
); + " to "
+ target.getAbsolutePath().replace(PasswordRepository.getWorkTree() + "/", "")
+ target.getAbsolutePath() + "/" + source.getName() + ".");
} }
} }
updateListAdapter(); updateListAdapter();

View File

@@ -1,7 +1,13 @@
package com.zeapo.pwdstore.git; package com.zeapo.pwdstore.git;
import android.app.Activity; 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.CloneCommand;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
@@ -12,7 +18,8 @@ public class CloneOperation extends GitOperation {
/** /**
* Creates a new clone operation * Creates a new clone operation
* @param fileDir the git working tree directory *
* @param fileDir the git working tree directory
* @param callingActivity the calling activity * @param callingActivity the calling activity
*/ */
public CloneOperation(File fileDir, Activity callingActivity) { public CloneOperation(File fileDir, Activity callingActivity) {
@@ -21,6 +28,7 @@ public class CloneOperation extends GitOperation {
/** /**
* Sets the command using the repository uri * Sets the command using the repository uri
*
* @param uri the uri of the repository * @param uri the uri of the repository
* @return the current object * @return the current object
*/ */
@@ -34,6 +42,7 @@ public class CloneOperation extends GitOperation {
/** /**
* sets the authentication for user/pwd scheme * sets the authentication for user/pwd scheme
*
* @param username the username * @param username the username
* @param password the password * @param password the password
* @return the current object * @return the current object
@@ -46,6 +55,7 @@ public class CloneOperation extends GitOperation {
/** /**
* sets the authentication for the ssh-key scheme * sets the authentication for the ssh-key scheme
*
* @param sshKey the ssh-key file * @param sshKey the ssh-key file
* @param username the username * @param username the username
* @param passphrase the passphrase * @param passphrase the passphrase
@@ -58,10 +68,31 @@ public class CloneOperation extends GitOperation {
} }
@Override @Override
public void execute() throws Exception { public void execute() {
if (this.provider != null) { if (this.provider != null) {
((CloneCommand) this.command).setCredentialsProvider(this.provider); ((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();
} }
} }

View File

@@ -2,16 +2,11 @@ package com.zeapo.pwdstore.git;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import com.zeapo.pwdstore.PasswordStore; import com.zeapo.pwdstore.PasswordStore;
import com.zeapo.pwdstore.R; 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.GitCommand; import org.eclipse.jgit.api.GitCommand;
@@ -20,9 +15,9 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
private boolean finishOnEnd; private boolean finishOnEnd;
private boolean refreshListOnEnd; private boolean refreshListOnEnd;
private ProgressDialog dialog; private ProgressDialog dialog;
private Class operation; private GitOperation operation;
public GitAsyncTask(Activity activity, boolean finishOnEnd, boolean refreshListOnEnd, Class operation) { public GitAsyncTask(Activity activity, boolean finishOnEnd, boolean refreshListOnEnd, GitOperation operation) {
this.activity = activity; this.activity = activity;
this.finishOnEnd = finishOnEnd; this.finishOnEnd = finishOnEnd;
this.refreshListOnEnd = refreshListOnEnd; this.refreshListOnEnd = refreshListOnEnd;
@@ -63,26 +58,7 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
result = "Unexpected error"; result = "Unexpected error";
if (!result.isEmpty()) { if (!result.isEmpty()) {
new AlertDialog.Builder(activity). this.operation.onTaskEnded(result);
setTitle(activity.getResources().getString(R.string.jgit_error_dialog_title)).
setMessage(activity.getResources().getString(R.string.jgit_error_dialog_text) + result).
setPositiveButton(activity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (operation.equals(CloneCommand.class)) {
// if we were unable to finish the job
try {
FileUtils.deleteDirectory(PasswordRepository.getWorkTree());
} catch (Exception e) {
e.printStackTrace();
}
} else {
activity.setResult(Activity.RESULT_CANCELED);
activity.finish();
}
}
}).show();
} else { } else {
if (finishOnEnd) { if (finishOnEnd) {
this.activity.setResult(Activity.RESULT_OK); this.activity.setResult(Activity.RESULT_OK);

View File

@@ -10,6 +10,7 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.KeyPair; import com.jcraft.jsch.KeyPair;
import com.zeapo.pwdstore.R; import com.zeapo.pwdstore.R;
import com.zeapo.pwdstore.UserPreference; import com.zeapo.pwdstore.UserPreference;
@@ -75,10 +76,8 @@ public abstract class GitOperation {
/** /**
* Executes the GitCommand in an async task * Executes the GitCommand in an async task
*
* @throws Exception
*/ */
public abstract void execute() throws Exception; public abstract void execute();
/** /**
* Executes the GitCommand in an async task after creating the authentication * Executes the GitCommand in an async task after creating the authentication
@@ -86,9 +85,8 @@ public abstract class GitOperation {
* @param connectionMode the server-connection mode * @param connectionMode the server-connection mode
* @param username the username * @param username the username
* @param sshKey the ssh-key file * @param sshKey the ssh-key file
* @throws Exception
*/ */
public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey) throws Exception { public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey) {
executeAfterAuthentication(connectionMode, username, sshKey, false); executeAfterAuthentication(connectionMode, username, sshKey, false);
} }
@@ -99,9 +97,8 @@ public abstract class GitOperation {
* @param username the username * @param username the username
* @param sshKey the ssh-key file * @param sshKey the ssh-key file
* @param showError show the passphrase edit text in red * @param showError show the passphrase edit text in red
* @throws Exception
*/ */
private void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, final boolean showError) throws Exception { private void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, final boolean showError) {
if (connectionMode.equalsIgnoreCase("ssh-key")) { if (connectionMode.equalsIgnoreCase("ssh-key")) {
if (sshKey == null || !sshKey.exists()) { if (sshKey == null || !sshKey.exists()) {
new AlertDialog.Builder(callingActivity) new AlertDialog.Builder(callingActivity)
@@ -152,15 +149,16 @@ public abstract class GitOperation {
passphrase.setError("Wrong passphrase"); passphrase.setError("Wrong passphrase");
} }
JSch jsch = new JSch(); JSch jsch = new JSch();
final KeyPair keyPair = KeyPair.load(jsch, callingActivity.getFilesDir() + "/.ssh_key"); try {
if (keyPair.isEncrypted()) { final KeyPair keyPair = KeyPair.load(jsch, callingActivity.getFilesDir() + "/.ssh_key");
new AlertDialog.Builder(callingActivity)
.setTitle(callingActivity.getResources().getString(R.string.passphrase_dialog_title)) if (keyPair.isEncrypted()) {
.setMessage(callingActivity.getResources().getString(R.string.passphrase_dialog_text)) new AlertDialog.Builder(callingActivity)
.setView(passphrase) .setTitle(callingActivity.getResources().getString(R.string.passphrase_dialog_title))
.setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { .setMessage(callingActivity.getResources().getString(R.string.passphrase_dialog_text))
public void onClick(DialogInterface dialog, int whichButton) { .setView(passphrase)
try { .setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (keyPair.decrypt(passphrase.getText().toString())) { if (keyPair.decrypt(passphrase.getText().toString())) {
// Authenticate using the ssh-key and then execute the command // Authenticate using the ssh-key and then execute the command
setAuthentication(sshKey, username, passphrase.getText().toString()).execute(); setAuthentication(sshKey, username, passphrase.getText().toString()).execute();
@@ -168,18 +166,25 @@ public abstract class GitOperation {
// call back the method // call back the method
executeAfterAuthentication(connectionMode, username, sshKey, true); executeAfterAuthentication(connectionMode, username, sshKey, true);
} }
} catch (Exception e) {
e.printStackTrace();
} }
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}).show();
} else {
setAuthentication(sshKey, username, "").execute();
}
} catch (JSchException e) {
new AlertDialog.Builder(callingActivity)
.setTitle("Unable to open the ssh-key")
.setMessage("Please check that it was imported.")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
} }
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { }).show();
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}).show();
} else {
setAuthentication(sshKey, username, "").execute();
} }
} }
} else { } else {
@@ -195,11 +200,7 @@ public abstract class GitOperation {
.setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { .setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
// authenticate using the user/pwd and then execute the command // authenticate using the user/pwd and then execute the command
try { setAuthentication(username, password.getText().toString()).execute();
setAuthentication(username, password.getText().toString()).execute();
} catch (Exception e) {
e.printStackTrace();
}
} }
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { }).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
@@ -209,4 +210,20 @@ public abstract class GitOperation {
}).show(); }).show();
} }
} }
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.").
setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
callingActivity.setResult(Activity.RESULT_CANCELED);
callingActivity.finish();
}
}).show();
}
} }

View File

@@ -1,6 +1,10 @@
package com.zeapo.pwdstore.git; package com.zeapo.pwdstore.git;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import com.zeapo.pwdstore.R;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PullCommand; import org.eclipse.jgit.api.PullCommand;
@@ -32,10 +36,26 @@ public class PullOperation extends GitOperation {
} }
@Override @Override
public void execute() throws Exception { public void execute() {
if (this.provider != null) { if (this.provider != null) {
((PullCommand) this.command).setCredentialsProvider(this.provider); ((PullCommand) this.command).setCredentialsProvider(this.provider);
} }
new GitAsyncTask(callingActivity, true, false, PullCommand.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 pull 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) {
callingActivity.finish();
}
}).show();
} }
} }

View File

@@ -1,6 +1,10 @@
package com.zeapo.pwdstore.git; package com.zeapo.pwdstore.git;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import com.zeapo.pwdstore.R;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PushCommand; import org.eclipse.jgit.api.PushCommand;
@@ -32,10 +36,27 @@ public class PushOperation extends GitOperation {
} }
@Override @Override
public void execute() throws Exception { public void execute() {
if (this.provider != null) { if (this.provider != null) {
((PushCommand) this.command).setCredentialsProvider(this.provider); ((PushCommand) this.command).setCredentialsProvider(this.provider);
} }
new GitAsyncTask(callingActivity, true, false, PushCommand.class).execute(this.command); new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
}
@Override
public void onTaskEnded(String result) {
// 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.").
setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
callingActivity.finish();
}
}).show();
} }
} }

View File

@@ -1,6 +1,10 @@
package com.zeapo.pwdstore.git; package com.zeapo.pwdstore.git;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import com.zeapo.pwdstore.R;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PullCommand; import org.eclipse.jgit.api.PullCommand;
@@ -39,12 +43,27 @@ public class SyncOperation extends GitOperation {
} }
@Override @Override
public void execute() throws Exception { public void execute() {
if (this.provider != null) { if (this.provider != null) {
this.pullCommand.setCredentialsProvider(this.provider); this.pullCommand.setCredentialsProvider(this.provider);
this.pushCommand.setCredentialsProvider(this.provider); this.pushCommand.setCredentialsProvider(this.provider);
} }
new GitAsyncTask(callingActivity, true, false, PullCommand.class).execute(this.pullCommand, this.pushCommand); new GitAsyncTask(callingActivity, true, false, this).execute(this.pullCommand, this.pushCommand);
}
@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 sync 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) {
callingActivity.finish();
}
}).show();
} }
} }

View File

@@ -41,7 +41,7 @@
<!-- Git Async Task --> <!-- Git Async Task -->
<string name="running_dialog_text">Running command...</string> <string name="running_dialog_text">Running command...</string>
<string name="jgit_error_dialog_title">Internal exception occurred</string> <string name="jgit_error_dialog_title">An error occurred during a Git operation</string>
<string name="jgit_error_dialog_text">Message from jgit: \n</string> <string name="jgit_error_dialog_text">Message from jgit: \n</string>
<!-- Git Handler --> <!-- Git Handler -->