mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-04 14:49:44 +08:00
Add Git rm support
This commit is contained in:
54
android/app/src/main/java/com/example/journal/GitRmTask.java
Normal file
54
android/app/src/main/java/com/example/journal/GitRmTask.java
Normal 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;
|
||||
}
|
||||
}
|
@ -91,6 +91,19 @@ public class MainActivity extends FlutterActivity {
|
||||
|
||||
new GitAddTask(result).execute(cloneLocation, filePattern);
|
||||
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")) {
|
||||
String folderName = call.argument("folderName");
|
||||
String authorName = call.argument("authorName");
|
||||
|
@ -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 {
|
||||
print("Going to git push");
|
||||
try {
|
||||
|
Reference in New Issue
Block a user