mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-14 15:33:04 +08:00
Remove half cloned git repos
It can fail to clone and leave some residual .git files
This commit is contained in:
@ -1,7 +1,12 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import 'package:journal/state_container.dart';
|
||||
import 'package:journal/storage/git.dart';
|
||||
|
||||
class OnBoardingScreen extends StatefulWidget {
|
||||
@ -272,6 +277,9 @@ class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
String sshCloneUrl = pref.getString("sshCloneUrl");
|
||||
|
||||
// Just in case it was half cloned because of an error
|
||||
await _removeExistingClone();
|
||||
|
||||
String error = await gitClone(sshCloneUrl, "journal");
|
||||
if (error != null && error.isNotEmpty) {
|
||||
setState(() {
|
||||
@ -282,6 +290,16 @@ class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
||||
}
|
||||
}
|
||||
|
||||
Future _removeExistingClone() async {
|
||||
var baseDir = await getNotesDir();
|
||||
var dotGitDir = new Directory(p.join(baseDir.path, ".git"));
|
||||
bool exists = await dotGitDir.exists();
|
||||
if (exists) {
|
||||
await baseDir.delete(recursive: true);
|
||||
await baseDir.create();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var children = <Widget>[];
|
||||
|
@ -63,11 +63,11 @@ class StateContainerState extends State<StateContainer> {
|
||||
_loadNotesFromDisk();
|
||||
_syncNotes();
|
||||
} else {
|
||||
_removeExistingClone();
|
||||
removeExistingClone();
|
||||
}
|
||||
}
|
||||
|
||||
void _removeExistingClone() async {
|
||||
void removeExistingClone() async {
|
||||
var baseDir = await getNotesDir();
|
||||
var dotGitDir = new Directory(p.join(baseDir.path, ".git"));
|
||||
bool exists = await dotGitDir.exists();
|
||||
|
Reference in New Issue
Block a user