mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-24 02:37:41 +08:00
Allow the remote main branch to give an error
In the case of empty repos.
This commit is contained in:
@ -405,14 +405,22 @@ class Repository with ChangeNotifier {
|
|||||||
|
|
||||||
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 = "master";
|
||||||
|
try {
|
||||||
|
remoteBranchName = await _gitRepo.defaultBranch(remoteName);
|
||||||
|
} catch (ex) {
|
||||||
|
Log.w("Could not get git main branch - assuming master", ex: ex);
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
var branches = await repo.branches();
|
||||||
if (branches.isEmpty) {
|
if (branches.isEmpty) {
|
||||||
Log.i("Completing - no local branch");
|
Log.i("Completing - no local branch");
|
||||||
if (remoteBranchName != null && remoteBranchName.isNotEmpty) {
|
if (remoteBranchName != null &&
|
||||||
|
remoteBranchName.isNotEmpty &&
|
||||||
|
remoteBranch != null) {
|
||||||
await repo.checkoutBranch(remoteBranchName, remoteBranch.hash);
|
await repo.checkoutBranch(remoteBranchName, remoteBranch.hash);
|
||||||
}
|
}
|
||||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||||
|
Reference in New Issue
Block a user