mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-13 14:40:54 +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/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.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';
|
import 'package:journal/storage/git.dart';
|
||||||
|
|
||||||
class OnBoardingScreen extends StatefulWidget {
|
class OnBoardingScreen extends StatefulWidget {
|
||||||
@ -272,6 +277,9 @@ class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
|||||||
var pref = await SharedPreferences.getInstance();
|
var pref = await SharedPreferences.getInstance();
|
||||||
String sshCloneUrl = pref.getString("sshCloneUrl");
|
String sshCloneUrl = pref.getString("sshCloneUrl");
|
||||||
|
|
||||||
|
// Just in case it was half cloned because of an error
|
||||||
|
await _removeExistingClone();
|
||||||
|
|
||||||
String error = await gitClone(sshCloneUrl, "journal");
|
String error = await gitClone(sshCloneUrl, "journal");
|
||||||
if (error != null && error.isNotEmpty) {
|
if (error != null && error.isNotEmpty) {
|
||||||
setState(() {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var children = <Widget>[];
|
var children = <Widget>[];
|
||||||
|
@ -63,11 +63,11 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
_loadNotesFromDisk();
|
_loadNotesFromDisk();
|
||||||
_syncNotes();
|
_syncNotes();
|
||||||
} else {
|
} else {
|
||||||
_removeExistingClone();
|
removeExistingClone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _removeExistingClone() async {
|
void removeExistingClone() async {
|
||||||
var baseDir = await getNotesDir();
|
var baseDir = await getNotesDir();
|
||||||
var dotGitDir = new Directory(p.join(baseDir.path, ".git"));
|
var dotGitDir = new Directory(p.join(baseDir.path, ".git"));
|
||||||
bool exists = await dotGitDir.exists();
|
bool exists = await dotGitDir.exists();
|
||||||
|
Reference in New Issue
Block a user