Fix a bug about "discard all changes"
- Show the number of (not pushed) commits discarded.
This commit is contained in:
parent
0dccd911fd
commit
c131de0551
2 changed files with 8 additions and 8 deletions
|
|
@ -40,10 +40,10 @@ class AdvancedSettingsTableViewController: UITableViewController {
|
||||||
SVProgressHUD.show(withStatus: "Resetting ...")
|
SVProgressHUD.show(withStatus: "Resetting ...")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
do {
|
do {
|
||||||
try PasswordStore.shared.reset()
|
let numberDiscarded = try PasswordStore.shared.reset()
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreChangeDiscarded")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordStoreChangeDiscarded")))
|
||||||
self.navigationController!.popViewController(animated: true)
|
self.navigationController!.popViewController(animated: true)
|
||||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
SVProgressHUD.showSuccess(withStatus: "Discarded \(numberDiscarded) commits")
|
||||||
SVProgressHUD.dismiss(withDelay: 1)
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
} catch {
|
} catch {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
|
||||||
|
|
@ -605,7 +605,8 @@ class PasswordStore {
|
||||||
storeRepository = nil
|
storeRepository = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func reset() throws {
|
// return the number of discarded commits
|
||||||
|
func reset() throws -> Int {
|
||||||
// get the remote origin/master branch
|
// get the remote origin/master branch
|
||||||
guard let remoteBranches = try storeRepository?.remoteBranches(),
|
guard let remoteBranches = try storeRepository?.remoteBranches(),
|
||||||
let index = remoteBranches.index(where: { $0.shortName == "master" })
|
let index = remoteBranches.index(where: { $0.shortName == "master" })
|
||||||
|
|
@ -618,9 +619,8 @@ class PasswordStore {
|
||||||
// get a list of local commits
|
// get a list of local commits
|
||||||
if let localCommits = try storeRepository?.localCommitsRelative(toRemoteBranch: remoteMasterBranch),
|
if let localCommits = try storeRepository?.localCommitsRelative(toRemoteBranch: remoteMasterBranch),
|
||||||
localCommits.count > 0 {
|
localCommits.count > 0 {
|
||||||
//print("PasswordStore.reset: \(localCommits.count)")
|
// get the oldest local commit
|
||||||
// get the first local commit
|
guard let firstLocalCommit = localCommits.last,
|
||||||
guard let firstLocalCommit = localCommits.first,
|
|
||||||
firstLocalCommit.parents.count == 1,
|
firstLocalCommit.parents.count == 1,
|
||||||
let newHead = firstLocalCommit.parents.first else {
|
let newHead = firstLocalCommit.parents.first else {
|
||||||
throw NSError(domain: "me.mssun.pass.error", code: 1, userInfo: [NSLocalizedDescriptionKey: "Cannot decide how to reset."])
|
throw NSError(domain: "me.mssun.pass.error", code: 1, userInfo: [NSLocalizedDescriptionKey: "Cannot decide how to reset."])
|
||||||
|
|
@ -629,9 +629,9 @@ class PasswordStore {
|
||||||
self.updatePasswordEntityCoreData()
|
self.updatePasswordEntityCoreData()
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||||
self.setAllSynced()
|
self.setAllSynced()
|
||||||
|
return localCommits.count
|
||||||
} else {
|
} else {
|
||||||
//print("PasswordStore.reset: no new commit")
|
return 0 // no new commit
|
||||||
return; // no new commit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue