mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +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) {
|
Future<void> completeGitHostSetup(
|
||||||
() async {
|
String repoFolderName, String remoteName) async {
|
||||||
var repoPath = p.join(gitBaseDirectory, repoFolderName);
|
var repoPath = p.join(gitBaseDirectory, repoFolderName);
|
||||||
Log.i("completeGitHostSetup repoPath: $repoPath");
|
Log.i("completeGitHostSetup repoPath: $repoPath");
|
||||||
|
|
||||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
||||||
|
|
||||||
var repo = await GitRepository.load(repoPath);
|
var repo = await GitRepository.load(repoPath);
|
||||||
var remote = repo.config.remote(remoteName);
|
var remote = repo.config.remote(remoteName);
|
||||||
var remoteBranchName = await _gitRepo.defaultBranch(remoteName);
|
var remoteBranchName = await _gitRepo.defaultBranch(remoteName);
|
||||||
var remoteBranch = await repo.remoteBranch(remoteName, remoteBranchName);
|
var remoteBranch = await repo.remoteBranch(remoteName, remoteBranchName);
|
||||||
Log.i("Using remote branch: $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 repo.setUpstreamTo(remote, remoteBranchName);
|
||||||
|
await _gitRepo.merge();
|
||||||
} else {
|
} else {
|
||||||
var branch = branches[0];
|
Log.i(
|
||||||
|
"Completing - localBranch diff remote: $branch $remoteBranchName");
|
||||||
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 ..
|
|
||||||
|
|
||||||
|
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;
|
await _addFileInRepo(repo: this, settings: settings);
|
||||||
settings.save();
|
|
||||||
|
|
||||||
await _persistConfig();
|
this.repoPath = repoPath;
|
||||||
_loadNotes();
|
_notesCache.clear();
|
||||||
_syncNotes();
|
remoteGitRepoConfigured = true;
|
||||||
|
notesFolder.reset(repoPath);
|
||||||
|
|
||||||
notifyListeners();
|
settings.folderName = repoFolderName;
|
||||||
}();
|
settings.save();
|
||||||
|
|
||||||
|
await _persistConfig();
|
||||||
|
_loadNotes();
|
||||||
|
_syncNotes();
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _persistConfig() async {
|
Future _persistConfig() async {
|
||||||
|
@ -31,7 +31,7 @@ import 'package:gitjournal/utils/logger.dart';
|
|||||||
class GitHostSetupScreen extends StatefulWidget {
|
class GitHostSetupScreen extends StatefulWidget {
|
||||||
final String repoFolderName;
|
final String repoFolderName;
|
||||||
final String remoteName;
|
final String remoteName;
|
||||||
final Func2<String, String, void> onCompletedFunction;
|
final Func2<String, String, Future<void>> onCompletedFunction;
|
||||||
|
|
||||||
GitHostSetupScreen({
|
GitHostSetupScreen({
|
||||||
@required this.repoFolderName,
|
@required this.repoFolderName,
|
||||||
@ -555,8 +555,8 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
Event.GitHostSetupComplete,
|
Event.GitHostSetupComplete,
|
||||||
parameters: _buildOnboardingAnalytics(),
|
parameters: _buildOnboardingAnalytics(),
|
||||||
);
|
);
|
||||||
|
await widget.onCompletedFunction(widget.repoFolderName, widget.remoteName);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
widget.onCompletedFunction(widget.repoFolderName, widget.remoteName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _completeAutoConfigure() async {
|
Future<void> _completeAutoConfigure() async {
|
||||||
|
Reference in New Issue
Block a user