aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/git
diff options
context:
space:
mode:
authorMohamed Zenadi <mohamed@zenadi.com>2017-03-27 22:47:33 +0200
committerMohamed Zenadi <mohamed@zenadi.com>2017-03-27 22:47:33 +0200
commit824845bf41227c9ee0891f6d0299efe0f067ce00 (patch)
tree99570fbcde21a737b635ae54e64a8fedaa8d0f8e /app/src/main/java/com/zeapo/pwdstore/git
parentd888e5e2f25ca1308a5a34a17b5c585edeb30881 (diff)
downloadHardenedPass-824845bf41227c9ee0891f6d0299efe0f067ce00.tar.gz
HardenedPass-824845bf41227c9ee0891f6d0299efe0f067ce00.zip
fix git rm and sync
fixes #276 fixes #283
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java22
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java8
2 files changed, 23 insertions, 7 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 42984338..f2e689d9 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
@@ -7,7 +7,9 @@ import android.os.AsyncTask;
import com.zeapo.pwdstore.PasswordStore;
import com.zeapo.pwdstore.R;
+import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.GitCommand;
+import org.eclipse.jgit.api.StatusCommand;
public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
@@ -33,10 +35,21 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
}
@Override
- protected String doInBackground(GitCommand... cmd) {
- for (GitCommand aCmd : cmd) {
+ protected String doInBackground(GitCommand... commands) {
+ Integer nbChanges = null;
+ for (GitCommand command : commands) {
try {
- aCmd.call();
+ if (command instanceof StatusCommand) {
+ // in case we have changes, we want to keep track of it
+ nbChanges = ((StatusCommand) command).call().getChanged().size();
+ } else if (command instanceof CommitCommand) {
+ // the previous status will eventually be used to avoid a commit
+ if (nbChanges == null || nbChanges > 0)
+ command.call();
+ } else {
+ command.call();
+ }
+
} catch (Exception e) {
e.printStackTrace();
return e.getMessage() + "\nCaused by:\n" + e.getCause();
@@ -49,8 +62,7 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
if (this.dialog != null)
try {
this.dialog.dismiss();
- } catch (Exception e)
- {
+ } catch (Exception e) {
// ignore
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java
index 6c7e637d..b5c0e6d2 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java
@@ -11,11 +11,13 @@ import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PullCommand;
import org.eclipse.jgit.api.PushCommand;
+import org.eclipse.jgit.api.StatusCommand;
import java.io.File;
public class SyncOperation extends GitOperation {
protected AddCommand addCommand;
+ protected StatusCommand statusCommand;
protected CommitCommand commitCommand;
protected PullCommand pullCommand;
protected PushCommand pushCommand;
@@ -32,11 +34,13 @@ public class SyncOperation extends GitOperation {
/**
* Sets the command
+ *
* @return the current object
*/
public SyncOperation setCommands() {
Git git = new Git(repository);
- this.addCommand = git.add().addFilepattern(".");
+ this.addCommand = git.add().setUpdate(true).addFilepattern(".");
+ this.statusCommand = git.status();
this.commitCommand = git.commit().setMessage("[Android Password Store] Sync");
this.pullCommand = git.pull().setRebase(true).setRemote("origin");
this.pushCommand = git.push().setPushAll().setRemote("origin");
@@ -49,7 +53,7 @@ public class SyncOperation extends GitOperation {
this.pullCommand.setCredentialsProvider(this.provider);
this.pushCommand.setCredentialsProvider(this.provider);
}
- new GitAsyncTask(callingActivity, true, false, this).execute(this.addCommand, this.commitCommand, this.pullCommand, this.pushCommand);
+ new GitAsyncTask(callingActivity, true, false, this).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand);
}
@Override