Skip to content

Commit b76645a

Browse files
committed
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.
1 parent 3285712 commit b76645a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/screens/githostsetup_screens.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:gitjournal/analytics.dart';
1212
import 'package:gitjournal/apis/githost_factory.dart';
1313
import 'package:gitjournal/state_container.dart';
1414
import 'package:gitjournal/utils.dart';
15+
import 'package:gitjournal/settings.dart';
1516
import 'package:path/path.dart' as p;
1617
import 'package:url_launcher/url_launcher.dart';
1718

@@ -373,9 +374,10 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
373374
// Just in case it was half cloned because of an error
374375
await _removeExistingClone(basePath);
375376

377+
String repoPath = p.join(basePath, "journal");
376378
String error;
377379
try {
378-
await GitRepo.clone(p.join(basePath, "journal"), _gitCloneUrl);
380+
await GitRepo.clone(repoPath, _gitCloneUrl);
379381
} on GitException catch (e) {
380382
error = e.cause;
381383
}
@@ -393,6 +395,24 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
393395
return;
394396
}
395397

398+
//
399+
// Add a GitIgnore file. This way we always at least have one commit
400+
// It makes doing a git pull and push easier
401+
//
402+
var gitIgnorePath = p.join(repoPath, ".gitignore");
403+
var ignoreFile = File(gitIgnorePath);
404+
if (!ignoreFile.existsSync()) {
405+
ignoreFile.createSync();
406+
407+
var repo = GitRepo(
408+
folderPath: repoPath,
409+
authorName: Settings.instance.gitAuthor,
410+
authorEmail: Settings.instance.gitAuthorEmail,
411+
);
412+
await repo.add('.gitignore');
413+
await repo.commit(message: "Add gitignore file");
414+
}
415+
396416
getAnalytics().logEvent(
397417
name: "onboarding_complete",
398418
parameters: <String, dynamic>{},

0 commit comments

Comments
 (0)