From b76645a14490ebf2d607a8abf20c8e95dbfb5670 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 2 Jan 2020 18:47:55 +0100 Subject: [PATCH] Add a .gitIgnore file if missing This way we always have at least one commit, cause not having any commits makes a lot of the git commands fail. --- lib/screens/githostsetup_screens.dart | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/screens/githostsetup_screens.dart b/lib/screens/githostsetup_screens.dart index d1b34d9c..b634a74b 100644 --- a/lib/screens/githostsetup_screens.dart +++ b/lib/screens/githostsetup_screens.dart @@ -12,6 +12,7 @@ import 'package:gitjournal/analytics.dart'; import 'package:gitjournal/apis/githost_factory.dart'; import 'package:gitjournal/state_container.dart'; import 'package:gitjournal/utils.dart'; +import 'package:gitjournal/settings.dart'; import 'package:path/path.dart' as p; import 'package:url_launcher/url_launcher.dart'; @@ -373,9 +374,10 @@ class GitHostSetupScreenState extends State { // Just in case it was half cloned because of an error await _removeExistingClone(basePath); + String repoPath = p.join(basePath, "journal"); String error; try { - await GitRepo.clone(p.join(basePath, "journal"), _gitCloneUrl); + await GitRepo.clone(repoPath, _gitCloneUrl); } on GitException catch (e) { error = e.cause; } @@ -393,6 +395,24 @@ class GitHostSetupScreenState extends State { return; } + // + // Add a GitIgnore file. This way we always at least have one commit + // It makes doing a git pull and push easier + // + var gitIgnorePath = p.join(repoPath, ".gitignore"); + var ignoreFile = File(gitIgnorePath); + if (!ignoreFile.existsSync()) { + ignoreFile.createSync(); + + var repo = GitRepo( + folderPath: repoPath, + authorName: Settings.instance.gitAuthor, + authorEmail: Settings.instance.gitAuthorEmail, + ); + await repo.add('.gitignore'); + await repo.commit(message: "Add gitignore file"); + } + getAnalytics().logEvent( name: "onboarding_complete", parameters: {},