Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clone: Split into multiple files and make it more pluggable
This way I can more easily choose if I want to use libgit2 or the git executable or whatever. It's being done so that one can wrtie automated tests for this cloneRemote function. There are still some users for whom this doesn't work, and after so so many iterations, it's time to write tests. This is just way too complex for me without tests.
- Loading branch information
Showing
5 changed files
with
251 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'dart:io' show Platform; | ||
|
||
import 'clone_gitExec.dart' as git_exec; | ||
import 'clone_libgit2.dart' as libgit2; | ||
|
||
final isMobileApp = Platform.isIOS || Platform.isAndroid; | ||
|
||
var cloneRemote = isMobileApp ? libgit2.cloneRemote : git_exec.cloneRemote; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:dart_git/dart_git.dart'; | ||
import 'package:dart_git/utils/result.dart'; | ||
import 'package:function_types/function_types.dart'; | ||
|
||
import 'package:gitjournal/utils/git_desktop.dart'; | ||
import 'clone.dart'; | ||
|
||
Future<Result<void>> cloneRemote({ | ||
required String repoPath, | ||
required String cloneUrl, | ||
required String remoteName, | ||
required String sshPublicKey, | ||
required String sshPrivateKey, | ||
required String sshPassword, | ||
required String authorName, | ||
required String authorEmail, | ||
required Func1<GitTransferProgress, void> progressUpdate, | ||
}) => | ||
cloneRemotePluggable( | ||
repoPath: repoPath, | ||
cloneUrl: cloneUrl, | ||
remoteName: remoteName, | ||
sshPublicKey: sshPublicKey, | ||
sshPrivateKey: sshPrivateKey, | ||
sshPassword: sshPassword, | ||
authorName: authorName, | ||
authorEmail: authorEmail, | ||
progressUpdate: progressUpdate, | ||
gitFetchFn: _fetch, | ||
defaultBranchFn: _defaultBranch, | ||
gitMergeFn: _merge, | ||
); | ||
|
||
Future<Result<void>> _fetch( | ||
String repoPath, | ||
String remoteName, | ||
String sshPublicKey, | ||
String sshPrivateKey, | ||
String sshPassword, | ||
String statusFile, | ||
) { | ||
// FIXME: Stop ignoring the statusFile | ||
return gitFetchViaExecutable( | ||
repoPath: repoPath, | ||
privateKey: sshPrivateKey, | ||
privateKeyPassword: sshPassword, | ||
remoteName: remoteName, | ||
); | ||
} | ||
|
||
Future<Result<String>> _defaultBranch( | ||
String repoPath, | ||
String remoteName, | ||
String sshPublicKey, | ||
String sshPrivateKey, | ||
String sshPassword, | ||
) { | ||
return gitDefaultBranchViaExecutable( | ||
repoPath: repoPath, | ||
privateKey: sshPrivateKey, | ||
privateKeyPassword: sshPassword, | ||
remoteName: remoteName, | ||
); | ||
} | ||
|
||
Future<Result<void>> _merge( | ||
String repoPath, | ||
String remoteName, | ||
String remoteBranchName, | ||
String authorName, | ||
String authorEmail, | ||
) { | ||
return catchAll(() async { | ||
var repo = await GitRepository.load(repoPath).getOrThrow(); | ||
var author = GitAuthor(name: authorName, email: authorEmail); | ||
await repo.mergeCurrentTrackingBranch(author: author).throwOnError(); | ||
return Result(null); | ||
}); | ||
} |
Oops, something went wrong.