From b503e5f6138227aa213871cbbc684d254adce6a7 Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Sun, 26 Jul 2020 16:43:13 +0200 Subject: [PATCH] Inform the user about a failed push In case there are uncommitted changes in the remote repository the push ran through successfully but there were still unpushed changes in the app. This change notfies the user about this situation. Strangely, the push method from Objective-Git does not inform about this, although the command line Git does. Thus, the check for the number of local changes is used after the push operation, which can actually have several reasons. Important is that there is at least some hint, though. --- pass/de.lproj/Localizable.strings | 2 ++ pass/en.lproj/Localizable.strings | 2 ++ passKit/Helpers/AppError.swift | 3 ++- passKit/Models/PasswordStore.swift | 19 +++++++++---------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pass/de.lproj/Localizable.strings b/pass/de.lproj/Localizable.strings index f4245e8..8cb12a9 100644 --- a/pass/de.lproj/Localizable.strings +++ b/pass/de.lproj/Localizable.strings @@ -67,6 +67,8 @@ "FileNotFoundError." = "Die Datei '%@' kann nicht gelesen werden."; "PasswordDuplicatedError." = "Passwort kann nicht hinzugefügt werden; es existiert bereits."; "GitResetError." = "Der zuletzt synchronisierte Commit kann nicht identifiziert werden."; +"GitCreateSignatureError." = "Es konnte keine valide Signatur für den Author/Committer angelegt werden."; +"GitPushNotSuccessfulError." = "Die Übertragung der lokalen Änderungen war nicht erfolgreich. Stelle bitte sicher, dass auf dem Remote-Repository alle Änderungen commitet sind."; "WrongPasswordFilenameError." = "Schreiben der Passwort-Datei nicht möglich ."; "DecryptionError." = "Passwort kann nicht entschlüsselt werden."; "EncodingError." = "Schlüssel ist nicht in ASCII kodiert."; diff --git a/pass/en.lproj/Localizable.strings b/pass/en.lproj/Localizable.strings index 487d277..668b580 100644 --- a/pass/en.lproj/Localizable.strings +++ b/pass/en.lproj/Localizable.strings @@ -67,6 +67,8 @@ "FileNotFoundError." = "File '%@' cannot be read."; "PasswordDuplicatedError." = "Cannot add the password; password is duplicated."; "GitResetError." = "Cannot identify the latest synced commit."; +"GitCreateSignatureError." = "Cannot create a valid author/committer signature."; +"GitPushNotSuccessfulError." = "Pushing local changes was not successful. Make sure there are no uncommitted changes on the remote repository."; "WrongPasswordFilenameError." = "Cannot write to the password file."; "DecryptionError." = "Cannot decrypt password."; "EncodingError." = "Key is not ASCII encoded."; diff --git a/passKit/Helpers/AppError.swift b/passKit/Helpers/AppError.swift index ad5ca64..e2ca7b7 100644 --- a/passKit/Helpers/AppError.swift +++ b/passKit/Helpers/AppError.swift @@ -14,7 +14,8 @@ public enum AppError: Error, Equatable { case ReadingFile(_: String) case PasswordDuplicated case GitReset - case GitCommit + case GitCreateSignature + case GitPushNotSuccessful case PasswordEntity case PgpPublicKeyNotFound(keyID: String) case PgpPrivateKeyNotFound(keyID: String) diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index 256283c..7897772 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -448,7 +448,7 @@ public class PasswordStore { try commitEnum.pushSHA(headReference.targetOID!.sha) let parent = commitEnum.nextObject() as! GTCommit guard let signature = gitSignatureForNow else { - throw AppError.GitCommit + throw AppError.GitCreateSignature } let commit = try storeRepository.createCommit(with: newTree, message: message, author: signature, committer: signature, parents: [parent], updatingReferenceNamed: headReference.name) return commit @@ -467,15 +467,14 @@ public class PasswordStore { guard let storeRepository = storeRepository else { throw AppError.RepositoryNotSet } - do { - let credentialProvider = try credential.credentialProvider(requestCredentialPassword: requestCredentialPassword) - let options = [GTRepositoryRemoteOptionsCredentialProvider: credentialProvider] - if let branch = try getLocalBranch(withName: Defaults.gitBranchName) { - let remote = try GTRemote(name: "origin", in: storeRepository) - try storeRepository.push(branch, to: remote, withOptions: options, progress: transferProgressBlock) - } - } catch { - throw(error) + let credentialProvider = try credential.credentialProvider(requestCredentialPassword: requestCredentialPassword) + let options = [GTRepositoryRemoteOptionsCredentialProvider: credentialProvider] + if let branch = try getLocalBranch(withName: Defaults.gitBranchName) { + let remote = try GTRemote(name: "origin", in: storeRepository) + try storeRepository.push(branch, to: remote, withOptions: options, progress: transferProgressBlock) + } + if numberOfLocalCommits != 0 { + throw AppError.GitPushNotSuccessful } }