Files
GitJournal/lib/apis/git_migration.dart
Vishesh Handa 63170445d7 Move libgit2 code to git_bindings repo
We now have a much clearer separation between Git code and this app
specific code. This is awesome, it will allow other people to easily
integrate Git within their apps. Also, eventually it will be trivial to
switch to another implemention of Git (via JGit or a git client written
completely in Dart)

This breaks the iOS version as I haven't moved the code to build the ios
version. Maybe this will be a good excuse for me to setup a proper CI/CD
system for ios builds.

There is also a chance this breaks Crashalytics NDK symbols :(
2019-12-21 01:06:15 +01:00

48 lines
1.3 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'package:fimber/fimber.dart';
import 'package:flutter/foundation.dart';
import 'package:git_bindings/git.dart';
import 'package:gitjournal/settings.dart';
import 'package:path/path.dart' as p;
//
// FIXME: This isn't ideal as we are skipping all the edits / deletes
//
Future migrateGitRepo({
@required String gitBasePath,
@required String fromGitBasePath,
@required String toGitBaseFolder,
}) async {
Fimber.d("migrateGitRepo $fromGitBasePath $toGitBaseFolder");
var fromBasePath = p.join(gitBasePath, fromGitBasePath);
var toGitRepoPath = p.join(gitBasePath, toGitBaseFolder);
Fimber.d("toGitRemotePath $toGitRepoPath");
final dir = Directory(fromBasePath);
var lister = dir.list(recursive: false);
await for (var fileEntity in lister) {
if (fileEntity is! File) {
continue;
}
File file = fileEntity;
var fileName = p.basename(file.path);
var toPath = p.join(toGitRepoPath, fileName);
Fimber.d("Migrating " + file.path + " --> " + toPath);
await file.copy(toPath);
var gitRepo = GitRepo(
folderPath: toGitRepoPath,
authorEmail: Settings.instance.gitAuthorEmail,
authorName: Settings.instance.gitAuthor,
);
await gitRepo.add(fileName);
await gitRepo.commit(message: "Added Note");
}
Fimber.d("migrateGitRepo: Done");
}