Change "save" to "clone" button, and clone the repo by default.

This commit is contained in:
Bob Sun 2017-04-26 22:04:44 -07:00
parent dd254b21d9
commit eccfeb19b5
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
3 changed files with 60 additions and 54 deletions

View file

@ -482,7 +482,7 @@
<segue destination="7K9-cE-9qq" kind="unwind" unwindAction="cancelGitServerSettingWithSegue:" id="SGr-tc-vDL"/> <segue destination="7K9-cE-9qq" kind="unwind" unwindAction="cancelGitServerSettingWithSegue:" id="SGr-tc-vDL"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
<barButtonItem key="rightBarButtonItem" style="done" systemItem="save" id="sgQ-zB-rxv"> <barButtonItem key="rightBarButtonItem" title="Clone" style="done" id="sgQ-zB-rxv">
<connections> <connections>
<action selector="save:" destination="ynQ-64-MfA" id="HNL-Da-fXT"/> <action selector="save:" destination="ynQ-64-MfA" id="HNL-Da-fXT"/>
</connections> </connections>

View file

@ -107,11 +107,12 @@ class GitServerSettingTableViewController: UITableViewController {
tableView.deselectRow(at: indexPath, animated: true) tableView.deselectRow(at: indexPath, animated: true)
} }
@IBAction func save(_ sender: Any) { private func doClone() {
if authenticationMethod == "Password" { if authenticationMethod == "Password" {
let alert = UIAlertController(title: "Password", message: "Please fill in the password of your Git account.", preferredStyle: UIAlertControllerStyle.alert) let alert = UIAlertController(title: "Password", message: "Please fill in the password of your Git account.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
self.password = alert.textFields!.first!.text self.password = alert.textFields!.first!.text
self.passwordStore.gitPassword = self.password
if self.shouldPerformSegue(withIdentifier: "saveGitServerSettingSegue", sender: self) { if self.shouldPerformSegue(withIdentifier: "saveGitServerSettingSegue", sender: self) {
self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self) self.performSegue(withIdentifier: "saveGitServerSettingSegue", sender: self)
} }
@ -128,6 +129,19 @@ class GitServerSettingTableViewController: UITableViewController {
} }
} }
@IBAction func save(_ sender: Any) {
if passwordStore.repositoryExisted() {
let alert = UIAlertController(title: "Erase Current Password Store Data?", message: "A cloned password store exists. This operation will erase all local data. Data on your remote server will not be affected.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Erase", style: UIAlertActionStyle.destructive, handler: { _ in
self.doClone()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
} else {
doClone()
}
}
private func gitSSHKeyExists() -> Bool { private func gitSSHKeyExists() -> Bool {
return FileManager.default.fileExists(atPath: Globals.gitSSHPublicKeyPath) && return FileManager.default.fileExists(atPath: Globals.gitSSHPublicKeyPath) &&
FileManager.default.fileExists(atPath: Globals.gitSSHPrivateKeyPath) FileManager.default.fileExists(atPath: Globals.gitSSHPrivateKeyPath)

View file

@ -101,61 +101,53 @@ class SettingsTableViewController: UITableViewController {
let password = controller.password let password = controller.password
let auth = controller.authenticationMethod let auth = controller.authenticationMethod
if Defaults[.gitURL] == nil || SVProgressHUD.setDefaultMaskType(.black)
Defaults[.gitURL]!.absoluteString != gitRepostiroyURL || SVProgressHUD.setDefaultStyle(.light)
auth != Defaults[.gitAuthenticationMethod] || SVProgressHUD.show(withStatus: "Prepare Repository")
username != Defaults[.gitUsername] || var gitCredential: GitCredential
password != self.passwordStore.gitPassword || if auth == "Password" {
self.passwordStore.repositoryExisted() == false { gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password!, requestGitPassword: requestGitPassword))
} else {
SVProgressHUD.setDefaultMaskType(.black) gitCredential = GitCredential(
SVProgressHUD.setDefaultStyle(.light) credential: GitCredential.Credential.ssh(
SVProgressHUD.show(withStatus: "Prepare Repository") userName: username,
var gitCredential: GitCredential password: Utils.getPasswordFromKeychain(name: "gitSSHPrivateKeyPassphrase") ?? "",
if auth == "Password" { publicKeyFile: Globals.gitSSHPublicKeyURL,
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password!, requestGitPassword: requestGitPassword)) privateKeyFile: Globals.gitSSHPrivateKeyURL,
} else { requestSSHKeyPassword: self.requestGitPassword
gitCredential = GitCredential(
credential: GitCredential.Credential.ssh(
userName: username,
password: Utils.getPasswordFromKeychain(name: "gitSSHPrivateKeyPassphrase") ?? "",
publicKeyFile: Globals.gitSSHPublicKeyURL,
privateKeyFile: Globals.gitSSHPrivateKeyURL,
requestSSHKeyPassword: self.requestGitPassword
)
) )
} )
let dispatchQueue = DispatchQueue.global(qos: .userInitiated) }
dispatchQueue.async { let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
do { dispatchQueue.async {
try self.passwordStore.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!, do {
credential: gitCredential, try self.passwordStore.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,
transferProgressBlock:{ (git_transfer_progress, stop) in credential: gitCredential,
DispatchQueue.main.async { transferProgressBlock:{ (git_transfer_progress, stop) in
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository") DispatchQueue.main.async {
} SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository")
}, }
checkoutProgressBlock: { (path, completedSteps, totalSteps) in },
DispatchQueue.main.async { checkoutProgressBlock: { (path, completedSteps, totalSteps) in
SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch") DispatchQueue.main.async {
} SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch")
}) }
DispatchQueue.main.async { })
Defaults[.gitURL] = URL(string: gitRepostiroyURL) DispatchQueue.main.async {
Defaults[.gitUsername] = username Defaults[.gitURL] = URL(string: gitRepostiroyURL)
Defaults[.gitAuthenticationMethod] = auth Defaults[.gitUsername] = username
Defaults[.gitPasswordAttempts] = 0 Defaults[.gitAuthenticationMethod] = auth
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]?.host Defaults[.gitPasswordAttempts] = 0
SVProgressHUD.showSuccess(withStatus: "Done") self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]?.host
SVProgressHUD.dismiss(withDelay: 1) SVProgressHUD.showSuccess(withStatus: "Done")
} SVProgressHUD.dismiss(withDelay: 1)
} catch { }
DispatchQueue.main.async { } catch {
Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil) DispatchQueue.main.async {
} Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil)
} }
} }
} }
} }
} }