diff --git a/lib/repository.dart b/lib/repository.dart index 3946a28d..737f67a9 100644 --- a/lib/repository.dart +++ b/lib/repository.dart @@ -93,7 +93,10 @@ class GitJournalRepo with ChangeNotifier { if (remoteConfigured) { // Code path for 'branch is null' exception 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]; await cloneRemote( repoPath: repoPath, diff --git a/lib/setup/clone.dart b/lib/setup/clone.dart index c8ac5c14..b4578323 100644 --- a/lib/setup/clone.dart +++ b/lib/setup/clone.dart @@ -1,6 +1,7 @@ import 'package:dart_git/dart_git.dart'; import 'package:git_bindings/git_bindings.dart' as git_bindings; import 'package:meta/meta.dart'; +import 'package:path/path.dart' as p; import 'package:gitjournal/utils/logger.dart'; @@ -44,7 +45,7 @@ Future cloneRemote({ if (remoteBranchName != null && remoteBranchName.isNotEmpty && remoteBranch != null) { - await repo.createBranch(remoteBranchName, remoteBranch.hash); + await repo.createBranch(remoteBranchName, hash: remoteBranch.hash); await repo.checkoutBranch(remoteBranchName); } await repo.setUpstreamTo(remote, remoteBranchName); @@ -55,6 +56,14 @@ Future cloneRemote({ if (branch == remoteBranchName) { 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); var remoteBranch = await repo.remoteBranch(remoteName, remoteBranchName); if (remoteBranch != null) { @@ -69,7 +78,7 @@ Future cloneRemote({ Log.i("Completing - localBranch diff remote: $branch $remoteBranchName"); 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.deleteBranch(branch); diff --git a/pubspec.lock b/pubspec.lock index 22d3f357..079ebc9e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -188,7 +188,7 @@ packages: description: path: "." ref: HEAD - resolved-ref: "897107cd1cacee207eadb63a6a2961cc3ed4c37f" + resolved-ref: "98bffd6e738a5687ed29dd5e7a9c9b6004152510" url: "https://github.com/GitJournal/dart-git.git" source: git version: "0.0.2"