Sync: Allow the merge to fail

This commit is contained in:
Vishesh Handa
2021-07-25 11:44:28 +02:00
parent 1161449ea4
commit 23541f7466
2 changed files with 17 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:dart_git/config.dart';
import 'package:dart_git/dart_git.dart';
import 'package:dart_git/exceptions.dart';
import 'package:git_bindings/git_bindings.dart';
import 'package:path/path.dart' as p;
import 'package:shared_preferences/shared_preferences.dart';
@ -176,7 +177,15 @@ class GitJournalRepo with ChangeNotifier {
Future? noteLoadingFuture;
try {
await _gitRepo.fetch().throwOnError();
await _gitRepo.merge().throwOnError();
var r = await _gitRepo.merge();
if (r.isFailure) {
var ex = r.error!;
// When there is nothing to merge into
if (ex is! GitRefNotFound) {
throw ex;
}
}
syncStatus = SyncStatus.Pushing;
notifyListeners();

View File

@ -104,6 +104,7 @@ Future<Result<void>> cloneRemotePluggable({
var remoteBranchName = branchNameR.getOrThrow();
Log.i("Using remote branch: $remoteBranchName");
var skipCheckout = false;
var branches = await repo.branches().getOrThrow();
if (branches.isEmpty) {
@ -115,6 +116,7 @@ Future<Result<void>> cloneRemotePluggable({
}
// remoteBranch doesn't exist - do nothing? Are you sure?
skipCheckout = true;
} else {
// remote branch exists
var remoteBranch = remoteBranchR.getOrThrow();
@ -172,9 +174,11 @@ Future<Result<void>> cloneRemotePluggable({
// - Pack files are read into memory, this causes OOM issues
// https://sentry.io/organizations/gitjournal/issues/2254310735/?project=5168082&query=is%3Aunresolved
//
var r = await repo.checkout(".");
if (r.isFailure) {
return fail(r);
if (!skipCheckout) {
var r = await repo.checkout(".");
if (r.isFailure) {
return fail(r);
}
}
return Result(null);