mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
Add a GitResetLast command
This way we can revert the last committed change.
This commit is contained in:
@ -0,0 +1,54 @@
|
||||
package io.gitjournal.gitjournal;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.ResetCommand;
|
||||
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 GitResetLastTask extends AsyncTask<String, Void, Void> {
|
||||
private final static String TAG = "GitResetLastTask";
|
||||
private Result result;
|
||||
|
||||
public GitResetLastTask(Result _result) {
|
||||
result = _result;
|
||||
}
|
||||
|
||||
protected Void doInBackground(String... params) {
|
||||
final String cloneDirPath = params[0];
|
||||
|
||||
File cloneDir = new File(cloneDirPath);
|
||||
Log.d("GitResetLastTask", "Clone Path: " + cloneDirPath);
|
||||
|
||||
try {
|
||||
Git git = Git.open(cloneDir);
|
||||
|
||||
ResetCommand command = git.reset();
|
||||
command.setMode(ResetCommand.ResetType.HARD);
|
||||
command.setRef("HEAD^");
|
||||
command.call();
|
||||
|
||||
} catch (TransportException e) {
|
||||
Log.d(TAG, e.toString());
|
||||
result.error("FAILED", e.getMessage(), null);
|
||||
return null;
|
||||
} catch (GitAPIException e) {
|
||||
Log.d(TAG, e.toString());
|
||||
result.error("FAILED", e.getMessage(), null);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, e.toString());
|
||||
result.error("FAILED", e.getMessage(), null);
|
||||
return null;
|
||||
}
|
||||
|
||||
result.success(null);
|
||||
return null;
|
||||
}
|
||||
}
|
@ -171,6 +171,18 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
|
||||
|
||||
new GitInitTask(result).execute(initLocation);
|
||||
return;
|
||||
} else if (call.method.equals("gitResetLast")) {
|
||||
String folderName = call.argument("folderName");
|
||||
|
||||
if (folderName == null || folderName.isEmpty()) {
|
||||
result.error("Invalid Parameters", "folderName Invalid", null);
|
||||
return;
|
||||
}
|
||||
|
||||
String cloneLocation = filesDir + "/" + folderName;
|
||||
|
||||
new GitResetLastTask(result).execute(cloneLocation);
|
||||
return;
|
||||
} else if (call.method.equals("generateSSHKeys")) {
|
||||
String comment = call.argument("comment");
|
||||
if (comment == null || comment.isEmpty()) {
|
||||
|
@ -150,6 +150,19 @@ Future gitPush(String folderName) async {
|
||||
}
|
||||
}
|
||||
|
||||
Future gitResetLast(String folderName) async {
|
||||
print("Going to git reset last");
|
||||
try {
|
||||
await _platform.invokeMethod('gitResetLast', {
|
||||
'folderName': folderName,
|
||||
});
|
||||
print("Done");
|
||||
} on PlatformException catch (e) {
|
||||
print("gitResetLast Failed: '${e.message}'.");
|
||||
throw createGitException(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future gitCommit({
|
||||
@required String gitFolder,
|
||||
@required String authorName,
|
||||
|
@ -88,6 +88,12 @@ class GitApp extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Git Reset Last"),
|
||||
onPressed: () async {
|
||||
gitResetLast(basePath);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Git Migrate"),
|
||||
onPressed: () async {
|
||||
|
Reference in New Issue
Block a user