Fix setting up an empty repo

Fixes APP-EQ
This commit is contained in:
Vishesh Handa
2020-10-21 15:32:33 +02:00
parent ad787158c7
commit 704329e3d5
5 changed files with 29 additions and 12 deletions

View File

@ -194,6 +194,15 @@ class GitNoteRepository {
assert(branchConfig.name != null); assert(branchConfig.name != null);
assert(branchConfig.merge != null); assert(branchConfig.merge != null);
var remoteRef = await repo.remoteBranch(
branchConfig.remote,
branchConfig.trackingBranch(),
);
if (remoteRef == null) {
Log.i('Remote has no refs');
return;
}
try { try {
await _gitRepo.merge( await _gitRepo.merge(
branch: branchConfig.remoteTrackingBranch(), branch: branchConfig.remoteTrackingBranch(),

View File

@ -516,6 +516,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
} }
if (error != null && error.isNotEmpty) { if (error != null && error.isNotEmpty) {
Log.i("Not completing gitClone because of error");
setState(() { setState(() {
logEvent(Event.GitHostSetupGitCloneError, parameters: { logEvent(Event.GitHostSetupGitCloneError, parameters: {
'error': error, 'error': error,
@ -529,10 +530,11 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
// Add a GitIgnore file. This way we always at least have one commit // Add a GitIgnore file. This way we always at least have one commit
// It makes doing a git pull and push easier // It makes doing a git pull and push easier
// //
var anyFileInRepo = Directory(repoPath).list().firstWhere( var dirList = await Directory(repoPath).list().toList();
(fs) => fs.statSync().type == FileSystemEntityType.file, var anyFileInRepo = dirList.firstWhere(
orElse: () => null, (fs) => fs.statSync().type == FileSystemEntityType.file,
); orElse: () => null,
);
if (anyFileInRepo == null) { if (anyFileInRepo == null) {
Log.i("Adding .ignore file"); Log.i("Adding .ignore file");
var ignoreFile = File(p.join(repoPath, ".gitignore")); var ignoreFile = File(p.join(repoPath, ".gitignore"));

View File

@ -335,13 +335,15 @@ class StateContainer with ChangeNotifier {
var repo = await GitRepository.load(repoPath); var repo = await GitRepository.load(repoPath);
var remote = repo.config.remote(remoteName); var remote = repo.config.remote(remoteName);
var remoteBranch = await repo.guessRemoteHead(remoteName); var remoteBranch = await repo.guessRemoteHead(remoteName);
var remoteBranchName = remoteBranch.name.branchName(); var remoteBranchName =
remoteBranch != null ? remoteBranch.name.branchName() : "master";
var branches = await repo.branches(); var branches = await repo.branches();
if (branches.isEmpty) { if (branches.isEmpty) {
Log.i("Completing - no local branch"); Log.i("Completing - no local branch");
assert(remoteBranch.isHash); if (remoteBranch != null) {
await repo.checkoutBranch(remoteBranchName, remoteBranch.hash); await repo.checkoutBranch(remoteBranchName, remoteBranch.hash);
}
await repo.setUpstreamTo(remote, remoteBranchName); await repo.setUpstreamTo(remote, remoteBranchName);
} else { } else {
var branch = branches[0]; var branch = branches[0];

View File

@ -181,7 +181,7 @@ packages:
description: description:
path: "." path: "."
ref: HEAD ref: HEAD
resolved-ref: "156ac4e589cf8a67c126e5c7c18f6ca76c6c232e" resolved-ref: "071cb643a4924a45986920f44c0e2433ee9159ed"
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"
@ -435,9 +435,11 @@ packages:
git_bindings: git_bindings:
dependency: "direct main" dependency: "direct main"
description: description:
name: git_bindings path: "."
url: "https://pub.dartlang.org" ref: HEAD
source: hosted resolved-ref: e7e957acdaff208744b5b1fff9a611cbfbd1de34
url: "https://github.com/GitJournal/git_bindings.git"
source: git
version: "0.0.18" version: "0.0.18"
git_url_parse2: git_url_parse2:
dependency: "direct main" dependency: "direct main"

View File

@ -29,7 +29,9 @@ dependencies:
dynamic_theme: ^1.0.0 dynamic_theme: ^1.0.0
flutter_staggered_grid_view: ^0.3.0 flutter_staggered_grid_view: ^0.3.0
provider: ^4.3.2+2 provider: ^4.3.2+2
git_bindings: ^0.0.18 git_bindings: #^0.0.18
#path: /Users/vishesh/src/gitjournal/git_bindings
git: https://github.com/GitJournal/git_bindings.git
dart_git: dart_git:
git: https://github.com/GitJournal/dart_git.git git: https://github.com/GitJournal/dart_git.git
#path: /Users/vishesh/src/gitjournal/dart_git #path: /Users/vishesh/src/gitjournal/dart_git