Fix a bug about "discard all changes"

- Show the number of (not pushed) commits discarded.
This commit is contained in:
Yishi Lin 2017-03-07 01:43:23 +08:00
parent 0dccd911fd
commit c131de0551
2 changed files with 8 additions and 8 deletions

View file

@ -605,7 +605,8 @@ class PasswordStore {
storeRepository = nil
}
func reset() throws {
// return the number of discarded commits
func reset() throws -> Int {
// get the remote origin/master branch
guard let remoteBranches = try storeRepository?.remoteBranches(),
let index = remoteBranches.index(where: { $0.shortName == "master" })
@ -618,9 +619,8 @@ class PasswordStore {
// get a list of local commits
if let localCommits = try storeRepository?.localCommitsRelative(toRemoteBranch: remoteMasterBranch),
localCommits.count > 0 {
//print("PasswordStore.reset: \(localCommits.count)")
// get the first local commit
guard let firstLocalCommit = localCommits.first,
// get the oldest local commit
guard let firstLocalCommit = localCommits.last,
firstLocalCommit.parents.count == 1,
let newHead = firstLocalCommit.parents.first else {
throw NSError(domain: "me.mssun.pass.error", code: 1, userInfo: [NSLocalizedDescriptionKey: "Cannot decide how to reset."])
@ -629,9 +629,9 @@ class PasswordStore {
self.updatePasswordEntityCoreData()
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
self.setAllSynced()
return localCommits.count
} else {
//print("PasswordStore.reset: no new commit")
return; // no new commit
return 0 // no new commit
}
}
}