mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +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/note.dart';
|
||||||
import 'package:gitjournal/core/notes_folder.dart';
|
import 'package:gitjournal/core/notes_folder.dart';
|
||||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
|
import 'package:gitjournal/error_reporting.dart';
|
||||||
import 'package:gitjournal/settings.dart';
|
import 'package:gitjournal/settings.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
@ -168,14 +169,30 @@ class GitNoteRepository {
|
|||||||
return _addNote(note, "Edited Note");
|
return _addNote(note, "Edited Note");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pull() async {
|
Future<void> fetch() async {
|
||||||
try {
|
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,
|
authorEmail: settings.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: settings.gitAuthor,
|
||||||
);
|
);
|
||||||
} on GitException catch (ex, stackTrace) {
|
} 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 (_) {}
|
} catch (_) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await _gitRepo.push();
|
await _gitRepo.push("origin");
|
||||||
} on GitException catch (ex, stackTrace) {
|
} on GitException catch (ex, stackTrace) {
|
||||||
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
||||||
await pull();
|
await fetch();
|
||||||
|
await merge();
|
||||||
return push();
|
return push();
|
||||||
}
|
}
|
||||||
Log.e("GitPush Failed", ex: ex, stacktrace: stackTrace);
|
Log.e("GitPush Failed", ex: ex, stacktrace: stackTrace);
|
||||||
|
@ -114,7 +114,8 @@ class StateContainer with ChangeNotifier {
|
|||||||
|
|
||||||
Future noteLoadingFuture;
|
Future noteLoadingFuture;
|
||||||
try {
|
try {
|
||||||
await _gitRepo.pull();
|
await _gitRepo.fetch();
|
||||||
|
await _gitRepo.merge();
|
||||||
|
|
||||||
appState.syncStatus = SyncStatus.Pushing;
|
appState.syncStatus = SyncStatus.Pushing;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -77,7 +77,7 @@ packages:
|
|||||||
name: buffer
|
name: buffer
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.6"
|
version: "1.0.7"
|
||||||
cached_network_image:
|
cached_network_image:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -174,7 +174,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: HEAD
|
ref: HEAD
|
||||||
resolved-ref: "27fe7ee9b5713c72dd7a3db3018ff16e6b06945b"
|
resolved-ref: "8e7e782f32f6cb1f39e39036d795f06ddecc56aa"
|
||||||
url: "https://github.com/GitJournal/dart_git.git"
|
url: "https://github.com/GitJournal/dart_git.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
@ -410,7 +410,7 @@ packages:
|
|||||||
name: git_bindings
|
name: git_bindings
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.0.14"
|
version: "0.0.15"
|
||||||
git_url_parse2:
|
git_url_parse2:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -29,7 +29,7 @@ dependencies:
|
|||||||
dynamic_theme: ^1.0.0
|
dynamic_theme: ^1.0.0
|
||||||
flutter_staggered_grid_view: ^0.3.0
|
flutter_staggered_grid_view: ^0.3.0
|
||||||
provider: ^3.2.0
|
provider: ^3.2.0
|
||||||
git_bindings: ^0.0.14
|
git_bindings: ^0.0.15
|
||||||
dart_git:
|
dart_git:
|
||||||
git: https://github.com/GitJournal/dart_git.git
|
git: https://github.com/GitJournal/dart_git.git
|
||||||
#path: /Users/vishesh/src/gitjournal/dart_git
|
#path: /Users/vishesh/src/gitjournal/dart_git
|
||||||
|
Reference in New Issue
Block a user