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
This commit is contained in:
Vishesh Handa
2020-12-16 11:43:21 +01:00
parent c8cb04f6e5
commit c64d30ec2a
3 changed files with 19 additions and 5 deletions

View File

@ -241,6 +241,20 @@ class GitNoteRepository {
}
}
Future<String> 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<int> numChanges() async {
try {
var repo = await git.GitRepository.load(gitDirPath);

View File

@ -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);

View File

@ -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"