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.
This commit is contained in:
Danny Moesch 2020-07-26 16:43:13 +02:00 committed by Mingshen Sun
parent bf8f2078f5
commit b503e5f613
4 changed files with 15 additions and 11 deletions

View file

@ -67,6 +67,8 @@
"FileNotFoundError." = "Die Datei '%@' kann nicht gelesen werden."; "FileNotFoundError." = "Die Datei '%@' kann nicht gelesen werden.";
"PasswordDuplicatedError." = "Passwort kann nicht hinzugefügt werden; es existiert bereits."; "PasswordDuplicatedError." = "Passwort kann nicht hinzugefügt werden; es existiert bereits.";
"GitResetError." = "Der zuletzt synchronisierte Commit kann nicht identifiziert werden."; "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 ."; "WrongPasswordFilenameError." = "Schreiben der Passwort-Datei nicht möglich .";
"DecryptionError." = "Passwort kann nicht entschlüsselt werden."; "DecryptionError." = "Passwort kann nicht entschlüsselt werden.";
"EncodingError." = "Schlüssel ist nicht in ASCII kodiert."; "EncodingError." = "Schlüssel ist nicht in ASCII kodiert.";

View file

@ -67,6 +67,8 @@
"FileNotFoundError." = "File '%@' cannot be read."; "FileNotFoundError." = "File '%@' cannot be read.";
"PasswordDuplicatedError." = "Cannot add the password; password is duplicated."; "PasswordDuplicatedError." = "Cannot add the password; password is duplicated.";
"GitResetError." = "Cannot identify the latest synced commit."; "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."; "WrongPasswordFilenameError." = "Cannot write to the password file.";
"DecryptionError." = "Cannot decrypt password."; "DecryptionError." = "Cannot decrypt password.";
"EncodingError." = "Key is not ASCII encoded."; "EncodingError." = "Key is not ASCII encoded.";

View file

@ -14,7 +14,8 @@ public enum AppError: Error, Equatable {
case ReadingFile(_: String) case ReadingFile(_: String)
case PasswordDuplicated case PasswordDuplicated
case GitReset case GitReset
case GitCommit case GitCreateSignature
case GitPushNotSuccessful
case PasswordEntity case PasswordEntity
case PgpPublicKeyNotFound(keyID: String) case PgpPublicKeyNotFound(keyID: String)
case PgpPrivateKeyNotFound(keyID: String) case PgpPrivateKeyNotFound(keyID: String)

View file

@ -448,7 +448,7 @@ public class PasswordStore {
try commitEnum.pushSHA(headReference.targetOID!.sha) try commitEnum.pushSHA(headReference.targetOID!.sha)
let parent = commitEnum.nextObject() as! GTCommit let parent = commitEnum.nextObject() as! GTCommit
guard let signature = gitSignatureForNow else { 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) let commit = try storeRepository.createCommit(with: newTree, message: message, author: signature, committer: signature, parents: [parent], updatingReferenceNamed: headReference.name)
return commit return commit
@ -467,15 +467,14 @@ public class PasswordStore {
guard let storeRepository = storeRepository else { guard let storeRepository = storeRepository else {
throw AppError.RepositoryNotSet throw AppError.RepositoryNotSet
} }
do {
let credentialProvider = try credential.credentialProvider(requestCredentialPassword: requestCredentialPassword) let credentialProvider = try credential.credentialProvider(requestCredentialPassword: requestCredentialPassword)
let options = [GTRepositoryRemoteOptionsCredentialProvider: credentialProvider] let options = [GTRepositoryRemoteOptionsCredentialProvider: credentialProvider]
if let branch = try getLocalBranch(withName: Defaults.gitBranchName) { if let branch = try getLocalBranch(withName: Defaults.gitBranchName) {
let remote = try GTRemote(name: "origin", in: storeRepository) let remote = try GTRemote(name: "origin", in: storeRepository)
try storeRepository.push(branch, to: remote, withOptions: options, progress: transferProgressBlock) try storeRepository.push(branch, to: remote, withOptions: options, progress: transferProgressBlock)
} }
} catch { if numberOfLocalCommits != 0 {
throw(error) throw AppError.GitPushNotSuccessful
} }
} }