mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-06 15:21:21 +08:00
Handle branch is null bug
Hopefully I've now handled every single case of it.
This commit is contained in:
@ -93,7 +93,10 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
if (remoteConfigured) {
|
if (remoteConfigured) {
|
||||||
// Code path for 'branch is null' exception
|
// Code path for 'branch is null' exception
|
||||||
var branch = await repo.currentBranch();
|
var branch = await repo.currentBranch();
|
||||||
if (branch == null) {
|
var head = await repo.head();
|
||||||
|
var branchConfig = repo.config.branch(branch);
|
||||||
|
|
||||||
|
if (branch == null || head == null || branchConfig == null) {
|
||||||
var remoteConfig = repo.config.remotes[0];
|
var remoteConfig = repo.config.remotes[0];
|
||||||
await cloneRemote(
|
await cloneRemote(
|
||||||
repoPath: repoPath,
|
repoPath: repoPath,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:dart_git/dart_git.dart';
|
import 'package:dart_git/dart_git.dart';
|
||||||
import 'package:git_bindings/git_bindings.dart' as git_bindings;
|
import 'package:git_bindings/git_bindings.dart' as git_bindings;
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ Future<void> cloneRemote({
|
|||||||
if (remoteBranchName != null &&
|
if (remoteBranchName != null &&
|
||||||
remoteBranchName.isNotEmpty &&
|
remoteBranchName.isNotEmpty &&
|
||||||
remoteBranch != null) {
|
remoteBranch != null) {
|
||||||
await repo.createBranch(remoteBranchName, remoteBranch.hash);
|
await repo.createBranch(remoteBranchName, hash: remoteBranch.hash);
|
||||||
await repo.checkoutBranch(remoteBranchName);
|
await repo.checkoutBranch(remoteBranchName);
|
||||||
}
|
}
|
||||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||||
@ -55,6 +56,14 @@ Future<void> cloneRemote({
|
|||||||
if (branch == remoteBranchName) {
|
if (branch == remoteBranchName) {
|
||||||
Log.i("Completing - localBranch: $branch");
|
Log.i("Completing - localBranch: $branch");
|
||||||
|
|
||||||
|
var currentBranch = await repo.currentBranch();
|
||||||
|
if (currentBranch != branch) {
|
||||||
|
// Shit happens sometimes
|
||||||
|
// There is only one local branch, and that branch is not the current
|
||||||
|
// branch, wtf?
|
||||||
|
await repo.checkoutBranch(branch);
|
||||||
|
}
|
||||||
|
|
||||||
await repo.setUpstreamTo(remote, remoteBranchName);
|
await repo.setUpstreamTo(remote, remoteBranchName);
|
||||||
var remoteBranch = await repo.remoteBranch(remoteName, remoteBranchName);
|
var remoteBranch = await repo.remoteBranch(remoteName, remoteBranchName);
|
||||||
if (remoteBranch != null) {
|
if (remoteBranch != null) {
|
||||||
@ -69,7 +78,7 @@ Future<void> cloneRemote({
|
|||||||
Log.i("Completing - localBranch diff remote: $branch $remoteBranchName");
|
Log.i("Completing - localBranch diff remote: $branch $remoteBranchName");
|
||||||
|
|
||||||
var headRef = await repo.resolveReference(await repo.head());
|
var headRef = await repo.resolveReference(await repo.head());
|
||||||
await repo.createBranch(remoteBranchName, headRef.hash);
|
await repo.createBranch(remoteBranchName, hash: headRef.hash);
|
||||||
await repo.checkoutBranch(remoteBranchName);
|
await repo.checkoutBranch(remoteBranchName);
|
||||||
|
|
||||||
await repo.deleteBranch(branch);
|
await repo.deleteBranch(branch);
|
||||||
|
@ -188,7 +188,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: HEAD
|
ref: HEAD
|
||||||
resolved-ref: "897107cd1cacee207eadb63a6a2961cc3ed4c37f"
|
resolved-ref: "98bffd6e738a5687ed29dd5e7a9c9b6004152510"
|
||||||
url: "https://github.com/GitJournal/dart-git.git"
|
url: "https://github.com/GitJournal/dart-git.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.2"
|
version: "0.0.2"
|
||||||
|
Reference in New Issue
Block a user