From c64d30ec2a31852b4ebd40420040f661ec14cdaa Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 16 Dec 2020 11:43:21 +0100 Subject: [PATCH] Stop guessing the default branch Talk to the remote via ssh and ask it which is the default branch. This has only been implemented for Android right now, so this breaks the ios build. Fixes #363 --- lib/core/git_repo.dart | 14 ++++++++++++++ lib/repository.dart | 8 ++++---- pubspec.lock | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/core/git_repo.dart b/lib/core/git_repo.dart index a9a66336..37b8996e 100644 --- a/lib/core/git_repo.dart +++ b/lib/core/git_repo.dart @@ -241,6 +241,20 @@ class GitNoteRepository { } } + Future defaultBranch(String remoteName) async { + try { + return await _gitRepo.defaultBranch( + remote: remoteName, + publicKey: settings.sshPublicKey, + privateKey: settings.sshPrivateKey, + password: settings.sshPassword, + ); + } on GitException catch (ex, stackTrace) { + Log.e("GitDefaultBranch Failed", ex: ex, stacktrace: stackTrace); + rethrow; + } + } + Future numChanges() async { try { var repo = await git.GitRepository.load(gitDirPath); diff --git a/lib/repository.dart b/lib/repository.dart index 471d4960..286f9cf5 100644 --- a/lib/repository.dart +++ b/lib/repository.dart @@ -450,14 +450,14 @@ class Repository with ChangeNotifier { var repo = await GitRepository.load(repoPath); var remote = repo.config.remote(remoteName); - var remoteBranch = await repo.guessRemoteHead(remoteName); - var remoteBranchName = - remoteBranch != null ? remoteBranch.name.branchName() : "master"; + 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 (remoteBranch != null) { + if (remoteBranchName != null && remoteBranchName.isNotEmpty) { await repo.checkoutBranch(remoteBranchName, remoteBranch.hash); } await repo.setUpstreamTo(remote, remoteBranchName); diff --git a/pubspec.lock b/pubspec.lock index 79fd623a..57c42e96 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -458,7 +458,7 @@ packages: description: path: "." ref: HEAD - resolved-ref: "2598c4cf21c4e23639b7eb5f3e1dd66cfd8eccd9" + resolved-ref: b6ae8855561bfe82b82417f9251917e1f29740a0 url: "https://github.com/GitJournal/git_bindings.git" source: git version: "0.0.18"