Files
GitJournal/lib/apis/git_migration.dart
Vishesh Handa 7ba8faa57f Remove the entire concept of a subFolder
When configuring the Git Repo server, we could optionally track one folder
in the root git repo, instead of just the root folder. This was
specifically to address my use case where I have my journals in a
sub-directory. The setup screen was super ugly, though.

Since now I'm in the process of adding folder support because of #18, I
can remove this hack. It simplifies the code a lot.
2019-12-01 12:04:45 +01:00

47 lines
1.3 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'package:fimber/fimber.dart';
import 'package:flutter/foundation.dart';
import 'package:gitjournal/apis/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(
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");
}