Handle setting up remote with a blank repo

This isn't perfect as we're guessing the remote's main branch, but it'll
do. We need this as I'm no longer ever calling 'git clone'. It's always
a fetch.

The good part is that this uses dart_git a lot :)
This commit is contained in:
Vishesh Handa
2020-10-20 14:07:27 +02:00
parent 9f53115616
commit c34b329852
2 changed files with 28 additions and 4 deletions

View File

@ -329,11 +329,35 @@ class StateContainer with ChangeNotifier {
() async {
var repo = await GitRepository.load(_gitRepo.gitDirPath);
var remote = repo.config.remote(remoteName);
var remoteBranchName = await repo.guessRemoteHead(remoteName);
var remoteBranch = await repo.guessRemoteHead(remoteName);
var remoteBranchName = remoteBranch.name.branchName();
await repo.setUpstreamTo(remote, remoteBranchName);
var branches = await repo.branches();
if (branches.isEmpty) {
assert(remoteBranch.isHash);
await repo.checkoutBranch(remoteBranchName, remoteBranch.hash);
await repo.setUpstreamTo(remote, remoteBranchName);
} else {
var branch = branches[0];
await _gitRepo.merge();
if (branch == remoteBranchName) {
await repo.setUpstreamTo(remote, remoteBranchName);
await _gitRepo.merge();
} else {
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 ..
}
await _persistConfig();
_loadNotes();

View File

@ -181,7 +181,7 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: "09bc129de57f8c179305a99ca1b9a885a4807c3f"
resolved-ref: "156ac4e589cf8a67c126e5c7c18f6ca76c6c232e"
url: "https://github.com/GitJournal/dart_git.git"
source: git
version: "0.0.1"