use ObjectiveGit instead of SwiftGit2

This commit is contained in:
Bob Sun 2017-01-23 16:29:36 +08:00
parent 7f58e2e649
commit 1b0f8fcb05
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
7 changed files with 74 additions and 32 deletions

View file

@ -13,7 +13,7 @@
<!--All-->
<scene sceneID="2hn-YS-T8K">
<objects>
<tableViewController id="vGH-8E-Zez" sceneMemberID="viewController">
<tableViewController id="vGH-8E-Zez" customClass="PasswordsTableViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="Cow-I6-Nig">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@ -47,7 +47,11 @@
</connections>
</tableView>
<navigationItem key="navigationItem" title="All" id="2I8-8c-JEA">
<barButtonItem key="rightBarButtonItem" systemItem="refresh" id="JLS-BH-aaR"/>
<barButtonItem key="rightBarButtonItem" systemItem="refresh" id="JLS-BH-aaR">
<connections>
<action selector="refreshPasswords:" destination="vGH-8E-Zez" id="nZd-1L-MFr"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CHd-Vz-2cA" userLabel="First Responder" sceneMemberID="firstResponder"/>

View file

@ -10,5 +10,6 @@
#define Objective_CBridgingHeader_h
#import <ObjectivePGP/ObjectivePGP.h>
#import <ObjectiveGit/ObjectiveGit.h>
#endif /* Objective_CBridgingHeader_h */

View file

@ -7,26 +7,28 @@
//
import Foundation
import SwiftGit2
import Result
import CoreData
import UIKit
import SwiftyUserDefaults
import ObjectiveGit
class PasswordStore {
static let shared = PasswordStore()
let storeURL = URL(fileURLWithPath: "\(Globals.shared.documentPath)/password-store")
var storeRepo: Repository?
var storeRepository: GTRepository?
let pgp: ObjectivePGP = ObjectivePGP()
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
private init() {
let result = Repository.at(storeURL)
if case .success(let r) = result {
storeRepo = r
do {
try storeRepository = GTRepository.init(url: storeURL)
} catch {
print(error)
}
if Defaults[.pgpKeyID] != "" {
pgp.importKeys(fromFile: Globals.shared.secringPath, allowDuplicates: false)
@ -52,10 +54,10 @@ class PasswordStore {
}
func cloneRemoteRepo(remoteRepoURL: URL) -> Bool {
func cloneRepository(remoteRepoURL: URL) -> Bool {
print("start cloning remote repo")
let fm = FileManager.default
if (storeRepo != nil) {
if (storeRepository != nil) {
print("remove item")
do {
try fm.removeItem(at: storeURL)
@ -63,14 +65,23 @@ class PasswordStore {
print(error.debugDescription)
}
}
let cloneResult = Repository.clone(from: remoteRepoURL, to: storeURL)
switch cloneResult {
case let .success(clonedRepo):
storeRepo = clonedRepo
print("clone repo: \(storeURL) success")
do {
storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: storeURL, options: nil, transferProgressBlock: nil, checkoutProgressBlock: nil)
updatePasswordEntityCoreData()
return true
case let .failure(error):
} catch {
print(error)
return false
}
}
func pullRepository() -> Bool {
print("pullRepoisitory")
do {
let remote = try GTRemote(name: "origin", in: storeRepository!)
try storeRepository?.pull((storeRepository?.currentBranch())!, from: remote, withOptions: nil, progress: nil)
updatePasswordEntityCoreData()
return true
} catch {
print(error)
return false
}

View file

@ -7,21 +7,25 @@
//
import UIKit
import SwiftGit2
import Result
import SVProgressHUD
extension PasswordsTableViewController: UISearchResultsUpdating {
func updateSearchResults(for searchController: UISearchController) {
filterContentForSearchText(searchText: searchController.searchBar.text!)
}
}
class PasswordsTableViewController: UITableViewController {
private var passwordEntities: [PasswordEntity]?
var filteredPasswordEntities = [PasswordEntity]()
let searchController = UISearchController(searchResultsController: nil)
@IBAction func refreshPasswords(_ sender: UIBarButtonItem) {
DispatchQueue.global(qos: .userInitiated).async {
if PasswordStore.shared.pullRepository() {
print("pull success")
self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
self.tableView.reloadData()
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
@ -87,3 +91,10 @@ class PasswordsTableViewController: UITableViewController {
}
}
extension PasswordsTableViewController: UISearchResultsUpdating {
func updateSearchResults(for searchController: UISearchController) {
filterContentForSearchText(searchText: searchController.searchBar.text!)
}
}

View file

@ -27,7 +27,7 @@ class SettingsTableViewController: UITableViewController {
SVProgressHUD.show(withStatus: "Cloning Remote Repository")
DispatchQueue.global(qos: .userInitiated).async {
let ret = PasswordStore.shared.cloneRemoteRepo(remoteRepoURL: Defaults[.gitRepositoryURL]!)
let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: Defaults[.gitRepositoryURL]!)
DispatchQueue.main.async {
if ret {