Polish the logic of clone

- pop the current view only after a successful clone so that editing the previous incorrect git setting is possible
This commit is contained in:
Yishi Lin 2017-06-07 18:52:53 +08:00
parent d86ee90eb7
commit 0542733f86
2 changed files with 59 additions and 67 deletions

View file

@ -96,57 +96,7 @@ class SettingsTableViewController: UITableViewController {
}
@IBAction func saveGitServerSetting(segue: UIStoryboardSegue) {
if let controller = segue.source as? GitServerSettingTableViewController {
let gitRepostiroyURL = controller.gitURLTextField.text!
let username = controller.usernameTextField.text!
let auth = controller.authenticationMethod
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
SVProgressHUD.show(withStatus: "Prepare Repository")
var gitCredential: GitCredential
if auth == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, controller: self))
} else {
gitCredential = GitCredential(
credential: GitCredential.Credential.ssh(
userName: username,
privateKeyFile: Globals.gitSSHPrivateKeyURL,
controller: self
)
)
}
let dispatchQueue = DispatchQueue.global(qos: .userInitiated)
dispatchQueue.async {
do {
try self.passwordStore.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,
credential: gitCredential,
transferProgressBlock:{ (git_transfer_progress, stop) in
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 {
SVProgressHUD.showProgress(Float(completedSteps)/Float(totalSteps), status: "Checkout Master Branch")
}
})
DispatchQueue.main.async {
Defaults[.gitURL] = URL(string: gitRepostiroyURL)
Defaults[.gitUsername] = username
Defaults[.gitAuthenticationMethod] = auth
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]?.host
SVProgressHUD.showSuccess(withStatus: "Done")
SVProgressHUD.dismiss(withDelay: 1)
}
} catch {
DispatchQueue.main.async {
Utils.alert(title: "Error", message: error.localizedDescription, controller: self, completion: nil)
}
}
}
}
self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitURL]?.host
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {