From ee1009b08790e75190e0a930c6897f33702a8dff Mon Sep 17 00:00:00 2001
From: Vishesh Handa <me@vhanda.in>
Date: Tue, 26 May 2020 18:39:10 +0200
Subject: [PATCH] Avoid hardcoding the git repo folder's name everywhere

This way, in the future we can support multiple repos, and more
importantly it will be easier to reconfigure the git host.
---
 lib/app.dart             |  5 ++++-
 lib/setup/screens.dart   | 13 +++++++------
 lib/state_container.dart |  4 ++--
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/app.dart b/lib/app.dart
index b1d2ed9b..4ab946a0 100644
--- a/lib/app.dart
+++ b/lib/app.dart
@@ -329,7 +329,10 @@ class _JournalAppState extends State<JournalApp> {
       case '/settings':
         return SettingsScreen();
       case '/setupRemoteGit':
-        return GitHostSetupScreen(stateContainer.completeGitHostSetup);
+        return GitHostSetupScreen(
+          "journal",
+          stateContainer.completeGitHostSetup,
+        );
       case '/onBoarding':
         return OnBoardingScreen(stateContainer.completeOnBoarding);
       case '/purchase':
diff --git a/lib/setup/screens.dart b/lib/setup/screens.dart
index d87d750e..5a18d489 100644
--- a/lib/setup/screens.dart
+++ b/lib/setup/screens.dart
@@ -27,9 +27,10 @@ import 'loading_error.dart';
 import 'sshkey.dart';
 
 class GitHostSetupScreen extends StatefulWidget {
-  final Func0<void> onCompletedFunction;
+  final String repoFolderName;
+  final Func1<String, void> onCompletedFunction;
 
-  GitHostSetupScreen(this.onCompletedFunction);
+  GitHostSetupScreen(this.repoFolderName, this.onCompletedFunction);
 
   @override
   GitHostSetupScreenState createState() {
@@ -469,9 +470,9 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
     var basePath = appState.gitBaseDirectory;
 
     // Just in case it was half cloned because of an error
-    await _removeExistingClone(basePath);
+    String repoPath = p.join(basePath, widget.repoFolderName);
+    await _removeExistingClone(repoPath);
 
-    String repoPath = p.join(basePath, "journal");
     String error;
     try {
       Log.d("Cloning " + _gitCloneUrl);
@@ -523,7 +524,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
       parameters: _buildOnboardingAnalytics(),
     );
     Navigator.pop(context);
-    widget.onCompletedFunction();
+    widget.onCompletedFunction(widget.repoFolderName);
   }
 
   Future<void> _completeAutoConfigure() async {
@@ -594,7 +595,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
   }
 
   Future _removeExistingClone(String baseDirPath) async {
-    var baseDir = Directory(p.join(baseDirPath, "journal"));
+    var baseDir = Directory(baseDirPath);
     var dotGitDir = Directory(p.join(baseDir.path, ".git"));
     bool exists = dotGitDir.existsSync();
     if (exists) {
diff --git a/lib/state_container.dart b/lib/state_container.dart
index cb0d39a2..2512d72b 100644
--- a/lib/state_container.dart
+++ b/lib/state_container.dart
@@ -323,10 +323,10 @@ class StateContainer with ChangeNotifier {
     });
   }
 
-  void completeGitHostSetup() {
+  void completeGitHostSetup(String repoFolderName) {
     () async {
       appState.remoteGitRepoConfigured = true;
-      appState.remoteGitRepoFolderName = "journal";
+      appState.remoteGitRepoFolderName = repoFolderName;
 
       await migrateGitRepo(
         fromGitBasePath: appState.localGitRepoFolderName,