Add Git rm support

This commit is contained in:
Vishesh Handa
2019-01-08 18:50:41 +01:00
parent fb3f3bfccf
commit 18d9601dcd
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,54 @@
package com.example.journal;
import android.os.AsyncTask;
import android.util.Log;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.RmCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.TransportException;
import java.io.File;
import io.flutter.plugin.common.MethodChannel.Result;
public class GitRmTask extends AsyncTask<String, Void, Void> {
private final static String TAG = "GitRm";
private Result result;
public GitRmTask(Result _result) {
result = _result;
}
protected Void doInBackground(String... params) {
final String cloneDirPath = params[0];
final String filePattern = params[1];
File cloneDir = new File(cloneDirPath);
Log.d("GitClone Directory", cloneDirPath);
try {
Git git = Git.open(cloneDir);
RmCommand rmCommand = git.rm();
rmCommand.addFilepattern(filePattern);
rmCommand.call();
} catch (TransportException e) {
Log.d(TAG, e.toString());
result.error("FAILED", e.toString(), null);
return null;
} catch (GitAPIException e) {
Log.d(TAG, e.toString());
result.error("FAILED", e.toString(), null);
return null;
} catch (Exception e) {
Log.d(TAG, e.toString());
result.error("FAILED", e.toString(), null);
return null;
}
result.success(null);
return null;
}
}

View File

@ -91,6 +91,19 @@ public class MainActivity extends FlutterActivity {
new GitAddTask(result).execute(cloneLocation, filePattern); new GitAddTask(result).execute(cloneLocation, filePattern);
return; return;
} else if (call.method.equals("gitRm")) {
String folderName = call.argument("folderName");
String filePattern = call.argument("filePattern");
if (folderName.isEmpty() || filePattern.isEmpty()) {
result.error("Invalid Parameters", "Arguments Invalid", null);
return;
}
String cloneLocation = filesDir + "/" + folderName;
new GitRmTask(result).execute(cloneLocation, filePattern);
return;
} else if (call.method.equals("gitCommit")) { } else if (call.method.equals("gitCommit")) {
String folderName = call.argument("folderName"); String folderName = call.argument("folderName");
String authorName = call.argument("authorName"); String authorName = call.argument("authorName");

View File

@ -61,6 +61,19 @@ Future gitAdd() async {
} }
} }
Future gitRm() async {
print("Going to git rm");
try {
await _platform.invokeMethod('gitRm', {
'folderName': "journal",
'filePattern': "1",
});
print("Done");
} on PlatformException catch (e) {
print("gitRm Failed: '${e.message}'.");
}
}
Future gitPush() async { Future gitPush() async {
print("Going to git push"); print("Going to git push");
try { try {