mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
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:
@ -329,11 +329,35 @@ class StateContainer with ChangeNotifier {
|
|||||||
() async {
|
() async {
|
||||||
var repo = await GitRepository.load(_gitRepo.gitDirPath);
|
var repo = await GitRepository.load(_gitRepo.gitDirPath);
|
||||||
var remote = repo.config.remote(remoteName);
|
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();
|
await _persistConfig();
|
||||||
_loadNotes();
|
_loadNotes();
|
||||||
|
@ -181,7 +181,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: HEAD
|
ref: HEAD
|
||||||
resolved-ref: "09bc129de57f8c179305a99ca1b9a885a4807c3f"
|
resolved-ref: "156ac4e589cf8a67c126e5c7c18f6ca76c6c232e"
|
||||||
url: "https://github.com/GitJournal/dart_git.git"
|
url: "https://github.com/GitJournal/dart_git.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
|
Reference in New Issue
Block a user