mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-21 07:38:19 +08:00
Replace git pull with git fetch + merge
This way we can swap the merge out easily for our own custom merge code. Also, this makes it easier to do a merge as a way of migrating. This commit probably breaks stuff on ios
This commit is contained in:
@ -9,6 +9,7 @@ import 'package:git_bindings/git_bindings.dart';
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
import 'package:gitjournal/error_reporting.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/utils/logger.dart';
|
||||
|
||||
@ -168,14 +169,30 @@ class GitNoteRepository {
|
||||
return _addNote(note, "Edited Note");
|
||||
}
|
||||
|
||||
Future<void> pull() async {
|
||||
Future<void> fetch() async {
|
||||
try {
|
||||
await _gitRepo.pull(
|
||||
await _gitRepo.fetch("origin");
|
||||
} on GitException catch (ex, stackTrace) {
|
||||
Log.e("GitPull Failed", ex: ex, stacktrace: stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> merge() async {
|
||||
var repo = await git.GitRepository.load(gitDirPath);
|
||||
var branch = await repo.currentBranch();
|
||||
if (branch == null) {
|
||||
logExceptionWarning(Exception("Current Branch null"), StackTrace.current);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await _gitRepo.merge(
|
||||
branch: branch.remoteTrackingBranch(),
|
||||
authorEmail: settings.gitAuthorEmail,
|
||||
authorName: settings.gitAuthor,
|
||||
);
|
||||
} on GitException catch (ex, stackTrace) {
|
||||
Log.e("GitPull Failed", ex: ex, stacktrace: stackTrace);
|
||||
Log.e("Git Merge Failed", ex: ex, stacktrace: stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,10 +206,11 @@ class GitNoteRepository {
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
await _gitRepo.push();
|
||||
await _gitRepo.push("origin");
|
||||
} on GitException catch (ex, stackTrace) {
|
||||
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
||||
await pull();
|
||||
await fetch();
|
||||
await merge();
|
||||
return push();
|
||||
}
|
||||
Log.e("GitPush Failed", ex: ex, stacktrace: stackTrace);
|
||||
|
Reference in New Issue
Block a user