mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Perform the 'git merge' in the 'cloning ..' screen
This step can take a lot of time, and I would prefer if the user didn't see a blank screen after cloning for a short while.
This commit is contained in:
@ -408,69 +408,68 @@ class Repository with ChangeNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
void completeGitHostSetup(String repoFolderName, String remoteName) {
|
||||
() async {
|
||||
var repoPath = p.join(gitBaseDirectory, repoFolderName);
|
||||
Log.i("completeGitHostSetup repoPath: $repoPath");
|
||||
Future<void> completeGitHostSetup(
|
||||
String repoFolderName, String remoteName) async {
|
||||
var repoPath = p.join(gitBaseDirectory, repoFolderName);
|
||||
Log.i("completeGitHostSetup repoPath: $repoPath");
|
||||
|
||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
||||
|
||||
var repo = await GitRepository.load(repoPath);
|
||||
var remote = repo.config.remote(remoteName);
|
||||
var remoteBranchName = await _gitRepo.defaultBranch(remoteName);
|
||||
var remoteBranch = await repo.remoteBranch(remoteName, remoteBranchName);
|
||||
Log.i("Using remote branch: $remoteBranchName");
|
||||
var repo = await GitRepository.load(repoPath);
|
||||
var remote = repo.config.remote(remoteName);
|
||||
var remoteBranchName = await _gitRepo.defaultBranch(remoteName);
|
||||
var remoteBranch = await repo.remoteBranch(remoteName, remoteBranchName);
|
||||
Log.i("Using remote branch: $remoteBranchName");
|
||||
|
||||
var branches = await repo.branches();
|
||||
if (branches.isEmpty) {
|
||||
Log.i("Completing - no local branch");
|
||||
if (remoteBranchName != null && remoteBranchName.isNotEmpty) {
|
||||
await repo.checkoutBranch(remoteBranchName, remoteBranch.hash);
|
||||
}
|
||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||
} else {
|
||||
var branch = branches[0];
|
||||
|
||||
if (branch == remoteBranchName) {
|
||||
Log.i("Completing - localBranch: $branch");
|
||||
|
||||
var branches = await repo.branches();
|
||||
if (branches.isEmpty) {
|
||||
Log.i("Completing - no local branch");
|
||||
if (remoteBranchName != null && remoteBranchName.isNotEmpty) {
|
||||
await repo.checkoutBranch(remoteBranchName, remoteBranch.hash);
|
||||
}
|
||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||
await _gitRepo.merge();
|
||||
} else {
|
||||
var branch = branches[0];
|
||||
|
||||
if (branch == remoteBranchName) {
|
||||
Log.i("Completing - localBranch: $branch");
|
||||
|
||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||
await _gitRepo.merge();
|
||||
} else {
|
||||
Log.i(
|
||||
"Completing - localBranch diff remote: $branch $remoteBranchName");
|
||||
|
||||
var headRef = await repo.resolveReference(await repo.head());
|
||||
await repo.checkoutBranch(remoteBranchName, headRef.hash);
|
||||
await repo.deleteBranch(branch);
|
||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||
await _gitRepo.merge();
|
||||
}
|
||||
|
||||
// if more than one branch
|
||||
// TODO: Check if one of the branches matches the remote branch name
|
||||
// and use that
|
||||
// if not, then just create a new branch with the remoteBranchName
|
||||
// and merge ..
|
||||
Log.i(
|
||||
"Completing - localBranch diff remote: $branch $remoteBranchName");
|
||||
|
||||
var headRef = await repo.resolveReference(await repo.head());
|
||||
await repo.checkoutBranch(remoteBranchName, headRef.hash);
|
||||
await repo.deleteBranch(branch);
|
||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||
await _gitRepo.merge();
|
||||
}
|
||||
|
||||
await _addFileInRepo(repo: this, settings: settings);
|
||||
// if more than one branch
|
||||
// TODO: Check if one of the branches matches the remote branch name
|
||||
// and use that
|
||||
// if not, then just create a new branch with the remoteBranchName
|
||||
// and merge ..
|
||||
|
||||
this.repoPath = repoPath;
|
||||
_notesCache.clear();
|
||||
remoteGitRepoConfigured = true;
|
||||
notesFolder.reset(repoPath);
|
||||
}
|
||||
|
||||
settings.folderName = repoFolderName;
|
||||
settings.save();
|
||||
await _addFileInRepo(repo: this, settings: settings);
|
||||
|
||||
await _persistConfig();
|
||||
_loadNotes();
|
||||
_syncNotes();
|
||||
this.repoPath = repoPath;
|
||||
_notesCache.clear();
|
||||
remoteGitRepoConfigured = true;
|
||||
notesFolder.reset(repoPath);
|
||||
|
||||
notifyListeners();
|
||||
}();
|
||||
settings.folderName = repoFolderName;
|
||||
settings.save();
|
||||
|
||||
await _persistConfig();
|
||||
_loadNotes();
|
||||
_syncNotes();
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future _persistConfig() async {
|
||||
|
@ -31,7 +31,7 @@ import 'package:gitjournal/utils/logger.dart';
|
||||
class GitHostSetupScreen extends StatefulWidget {
|
||||
final String repoFolderName;
|
||||
final String remoteName;
|
||||
final Func2<String, String, void> onCompletedFunction;
|
||||
final Func2<String, String, Future<void>> onCompletedFunction;
|
||||
|
||||
GitHostSetupScreen({
|
||||
@required this.repoFolderName,
|
||||
@ -555,8 +555,8 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
||||
Event.GitHostSetupComplete,
|
||||
parameters: _buildOnboardingAnalytics(),
|
||||
);
|
||||
await widget.onCompletedFunction(widget.repoFolderName, widget.remoteName);
|
||||
Navigator.pop(context);
|
||||
widget.onCompletedFunction(widget.repoFolderName, widget.remoteName);
|
||||
}
|
||||
|
||||
Future<void> _completeAutoConfigure() async {
|
||||
|
Reference in New Issue
Block a user