From 7b1204373dc44d16e4e443067825eb946905857a Mon Sep 17 00:00:00 2001 From: zeapo Date: Wed, 17 Dec 2014 23:33:30 +0100 Subject: add support for pull and push operations --- .../java/com/zeapo/pwdstore/git/PullOperation.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java (limited to 'app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java new file mode 100644 index 00000000..0d43216d --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java @@ -0,0 +1,36 @@ +package com.zeapo.pwdstore.git; + +import android.app.Activity; + +import com.zeapo.pwdstore.utils.PasswordRepository; + +import org.eclipse.jgit.api.Git; + +import java.io.File; + +public class PullOperation extends GitOperation { + + /** + * Creates a new git operation + * + * @param fileDir the git working tree directory + * @param callingActivity the calling activity + */ + public PullOperation(File fileDir, Activity callingActivity) { + super(fileDir, callingActivity); + } + + /** + * Sets the command using the repository uri + * @param uri the uri of the repository + * @return the current object + */ + public PullOperation setCommand(String uri) { + this.command = new Git(repository) + .pull() + .setRebase(true) + .setRemote("origin") + .setCredentialsProvider(provider); + return this; + } +} -- cgit v1.2.3 From 3ca806d699182f3233c2425bd407988540083758 Mon Sep 17 00:00:00 2001 From: zeapo Date: Thu, 18 Dec 2014 21:52:38 +0100 Subject: set credential after they've been intialized --- .../main/java/com/zeapo/pwdstore/git/CloneOperation.java | 10 ++++++++-- app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java | 4 +--- .../main/java/com/zeapo/pwdstore/git/PullOperation.java | 14 ++++++++++---- .../main/java/com/zeapo/pwdstore/git/PushOperation.java | 12 ++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/PullOperation.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 3c5c20c6..dc94ce3b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java @@ -4,7 +4,6 @@ import android.app.Activity; import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import java.io.File; @@ -27,7 +26,6 @@ public class CloneOperation extends GitOperation { */ public CloneOperation setCommand(String uri) { this.command = Git.cloneRepository(). - setCredentialsProvider(provider). setCloneAllBranches(true). setDirectory(repository.getWorkTree()). setURI(uri); @@ -58,4 +56,12 @@ public class CloneOperation extends GitOperation { super.setAuthentication(sshKey, username, passphrase); return this; } + + @Override + public void execute() throws Exception { + if (this.provider != null) { + ((CloneCommand) this.command).setCredentialsProvider(this.provider); + } + new GitAsyncTask(callingActivity, true, false, CloneCommand.class).execute(this.command); + } } 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 65436969..60112c90 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java @@ -78,9 +78,7 @@ public abstract class GitOperation { * * @throws Exception */ - public void execute() throws Exception { - new GitAsyncTask(callingActivity, true, false, GitCommand.class).execute(command); - } + public abstract void execute() throws Exception; /** * Executes the GitCommand in an async task after creating the authentication diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java index 0d43216d..2d499b4e 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java @@ -2,9 +2,8 @@ package com.zeapo.pwdstore.git; import android.app.Activity; -import com.zeapo.pwdstore.utils.PasswordRepository; - import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PullCommand; import java.io.File; @@ -29,8 +28,15 @@ public class PullOperation extends GitOperation { this.command = new Git(repository) .pull() .setRebase(true) - .setRemote("origin") - .setCredentialsProvider(provider); + .setRemote("origin"); return this; } + + @Override + public void execute() throws Exception { + if (this.provider != null) { + ((PullCommand) this.command).setCredentialsProvider(this.provider); + } + new GitAsyncTask(callingActivity, true, false, PullCommand.class).execute(this.command); + } } 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 fa3e4dd9..fd4fb229 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java @@ -3,6 +3,7 @@ package com.zeapo.pwdstore.git; import android.app.Activity; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PushCommand; import java.io.File; @@ -27,8 +28,15 @@ public class PushOperation extends GitOperation { this.command = new Git(repository) .push() .setPushAll() - .setRemote("origin") - .setCredentialsProvider(provider); + .setRemote("origin"); return this; } + + @Override + public void execute() throws Exception { + if (this.provider != null) { + ((PushCommand) this.command).setCredentialsProvider(this.provider); + } + new GitAsyncTask(callingActivity, true, false, PushCommand.class).execute(this.command); + } } -- cgit v1.2.3 From e170ef281b4d8f9b4c49d41faa077b06b1c9a84a Mon Sep 17 00:00:00 2001 From: zeapo Date: Sun, 4 Jan 2015 16:27:26 +0100 Subject: uri is useless here --- app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java | 10 +++++----- app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java | 5 ++--- app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java | 5 ++--- 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java index 5bb44b32..6307fd0d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java @@ -464,7 +464,7 @@ public class GitActivity extends ActionBarActivity { username = hostname.split("@")[0]; } - if (localDir.exists()) { + if (localDir.exists() && localDir.listFiles().length != 0) { new AlertDialog.Builder(this). setTitle(R.string.dialog_delete_title). setMessage(R.string.dialog_delete_msg). @@ -565,9 +565,9 @@ public class GitActivity extends ActionBarActivity { GitOperation op; if (operation == REQUEST_PULL) { - op = new PullOperation(localDir, activity).setCommand(hostname); + op = new PullOperation(localDir, activity).setCommand(); } else if (operation == REQUEST_PUSH) { - op = new PushOperation(localDir, activity).setCommand(hostname); + op = new PushOperation(localDir, activity).setCommand(); } else { Log.e(TAG, "Sync operation not recognized : " + operation); return; @@ -594,11 +594,11 @@ public class GitActivity extends ActionBarActivity { switch (requestCode) { case REQUEST_PULL: - op = new PullOperation(localDir, activity).setCommand(hostname); + op = new PullOperation(localDir, activity).setCommand(); break; case REQUEST_PUSH: - op = new PushOperation(localDir, activity).setCommand(hostname); + op = new PushOperation(localDir, activity).setCommand(); break; case GitOperation.GET_SSH_KEY_FROM_CLONE: diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java index 2d499b4e..abf4bfe6 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java @@ -20,11 +20,10 @@ public class PullOperation extends GitOperation { } /** - * Sets the command using the repository uri - * @param uri the uri of the repository + * Sets the command * @return the current object */ - public PullOperation setCommand(String uri) { + public PullOperation setCommand() { this.command = new Git(repository) .pull() .setRebase(true) 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 fd4fb229..73ed05ff 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java @@ -20,11 +20,10 @@ public class PushOperation extends GitOperation { } /** - * Sets the command using the repository uri - * @param uri the uri of the repository + * Sets the command * @return the current object */ - public PushOperation setCommand(String uri) { + public PushOperation setCommand() { this.command = new Git(repository) .push() .setPushAll() -- cgit v1.2.3