From ca934f79d559e7d4b80bbc2e3c0e207594353770 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Fri, 15 May 2020 15:31:16 +0200 Subject: [PATCH] CloneRepo: Avoid creating a .gitignore file if not required It's easier if there is always at least 1 commit in a repo. Creating a commit with a .gitignore file was a simple way to ensure that. However, we can also just check for the presence of any other file. This way, we avoid the extra commit. --- lib/setup/screens.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/setup/screens.dart b/lib/setup/screens.dart index 529994e5..f5c85b0e 100644 --- a/lib/setup/screens.dart +++ b/lib/setup/screens.dart @@ -496,9 +496,13 @@ class GitHostSetupScreenState extends State { // 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()) { + var anyFileInRepo = Directory(repoPath).list().firstWhere( + (fs) => fs.statSync().type == FileSystemEntityType.file, + orElse: () => null, + ); + if (anyFileInRepo == null) { + Log.i("Adding .ignore file"); + var ignoreFile = File(p.join(repoPath, ".gitignore")); ignoreFile.createSync(); var repo = GitRepo(