mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 17:29:50 +08:00
Git: Add a simplistic way to migrate between 2 git repos
This way initially all the changes are performed on the local git repo, and then later they are applied on the remote git repo. Currently we just copy the files, but we should be cherry-picking each commit and applying it properly.
This commit is contained in:
43
lib/apis/git_migration.dart
Normal file
43
lib/apis/git_migration.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:journal/storage/git.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 toGitBasePath,
|
||||
}) async {
|
||||
print("migrateGitRepo " + fromGitBasePath + " " + toGitBasePath);
|
||||
var fromBasePath = p.join(gitBasePath, fromGitBasePath);
|
||||
var toBasePath = p.join(gitBasePath, toGitBasePath);
|
||||
|
||||
final dir = new Directory(fromBasePath);
|
||||
var lister = dir.list(recursive: false);
|
||||
await for (var fileEntity in lister) {
|
||||
if (fileEntity is! File) {
|
||||
continue;
|
||||
}
|
||||
var file = fileEntity as File;
|
||||
var fileName = p.basename(file.path);
|
||||
var toPath = p.join(toBasePath, fileName);
|
||||
|
||||
print("Migrating " + file.path + " --> " + toPath);
|
||||
|
||||
await file.copy(toPath);
|
||||
await gitAdd(toGitBasePath, fileName);
|
||||
await gitCommit(
|
||||
gitFolder: toGitBasePath,
|
||||
authorEmail: "app@gitjournal.io",
|
||||
authorName: "GitJournal",
|
||||
message: "Migrated Journal Entry",
|
||||
);
|
||||
}
|
||||
print("migrateGitRepo: Done");
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:journal/storage/git.dart';
|
||||
|
||||
import 'package:journal/apis/git_migration.dart';
|
||||
|
||||
const basePath = "journal";
|
||||
|
||||
class GitApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -28,37 +32,49 @@ buildGitButtons() {
|
||||
RaisedButton(
|
||||
child: Text("Git Clone"),
|
||||
onPressed: () async {
|
||||
gitClone("root@bcn.vhanda.in:git/test", "journal");
|
||||
gitClone("root@bcn.vhanda.in:git/test", basePath);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Git Pull"),
|
||||
onPressed: () async {
|
||||
gitPull("journal");
|
||||
gitPull(basePath);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Git Add"),
|
||||
onPressed: () async {
|
||||
await gitAdd("journal", ".");
|
||||
await gitAdd(basePath, ".");
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Git Push"),
|
||||
onPressed: () async {
|
||||
gitPush("journal");
|
||||
gitPush(basePath);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Git Commit"),
|
||||
onPressed: () async {
|
||||
gitCommit(
|
||||
gitFolder: "journal",
|
||||
authorEmail: "noemail@example.com",
|
||||
authorName: "Vishesh Handa",
|
||||
message: "Default message from GitJournal",
|
||||
when: "2017-10-20T01:21:10+02:00",
|
||||
);
|
||||
}),
|
||||
child: Text("Git Commit"),
|
||||
onPressed: () async {
|
||||
gitCommit(
|
||||
gitFolder: basePath,
|
||||
authorEmail: "noemail@example.com",
|
||||
authorName: "Vishesh Handa",
|
||||
message: "Default message from GitJournal",
|
||||
when: "2017-10-20T01:21:10+02:00",
|
||||
);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Git Migrate"),
|
||||
onPressed: () async {
|
||||
var baseGitPath = await getGitBaseDirectory();
|
||||
await migrateGitRepo(
|
||||
fromGitBasePath: "journal_local",
|
||||
toGitBasePath: "journal",
|
||||
gitBasePath: baseGitPath.path,
|
||||
);
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -129,10 +129,10 @@ Future gitPush(String folderName) async {
|
||||
}
|
||||
|
||||
Future gitCommit({
|
||||
String gitFolder,
|
||||
String authorName,
|
||||
String authorEmail,
|
||||
String message,
|
||||
@required String gitFolder,
|
||||
@required String authorName,
|
||||
@required String authorEmail,
|
||||
@required String message,
|
||||
String when,
|
||||
}) async {
|
||||
print("Going to git commit");
|
||||
|
@ -12,8 +12,7 @@ class AppDrawer extends StatelessWidget {
|
||||
title: new Text('Setup Git Sync'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
// Update the state of the app
|
||||
// ...
|
||||
Navigator.pushNamed(context, "/setupRemoteGit");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user