Files
GitJournal/lib/apis/git_migration.dart
Vishesh Handa 74d7bdd763 Use a proper logger - Fimber
It's time to start using a proper logger so we can control the number of
log messages, also - it helps to have a central configuration point for
the logs, specially since I would like to hook them up to Crashlytics in
the future.
2019-06-19 09:45:15 +02:00

49 lines
1.4 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'package:fimber/fimber.dart';
import 'package:flutter/foundation.dart';
import 'package:journal/apis/git.dart';
import 'package:journal/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,
@required String toGitBaseSubFolder,
}) async {
Fimber.d(
"migrateGitRepo $fromGitBasePath $toGitBaseFolder / $toGitBaseSubFolder");
var fromBasePath = p.join(gitBasePath, fromGitBasePath);
var toGitRepoPath = p.join(gitBasePath, toGitBaseFolder, toGitBaseSubFolder);
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(
folderName: toGitBaseFolder,
authorEmail: Settings.instance.gitAuthorEmail,
authorName: Settings.instance.gitAuthor,
);
await gitRepo.add(fileName);
await gitRepo.commit(message: "Added Journal Entry");
}
Fimber.d("migrateGitRepo: Done");
}