Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Put every key of a Git setting back as it was before Peel turned it on
Țugui Dragoș80aba7b07f29
diff --git a/Packages/PeelCore/Sources/PeelCore/Terminal/GitLedger.swift b/Packages/PeelCore/Sources/PeelCore/Terminal/GitLedger.swiftindex e0498ff2..3034ff86 100644--- a/Packages/PeelCore/Sources/PeelCore/Terminal/GitLedger.swift+++ b/Packages/PeelCore/Sources/PeelCore/Terminal/GitLedger.swift@@ -1,5 +1,6 @@-/// What Peel wrote to Git's settings and what each key held before, so turning a setting off puts back what the-/// person had. A key the person changed after Peel did is theirs, and is left as it is.+/// What each key of a setting held before Peel turned the setting on, and what Peel wrote or found there, so+/// turning the setting off puts back exactly what the person had: a key found already at its value stays. A key+/// the person changed after Peel did is theirs, and is left as it is.public struct GitLedger {public enum Outcome: Sendable, Equatable {case changed@@ -27,9 +28,11 @@ public struct GitLedger {for wanted in values {let name = wanted.key.lowercased()let before = settings[name]- guard before != .some(.some(wanted.value)) else { continue }let isPeels = written[name].map { before == .some(.some($0)) } ?? false- guard await config.set(wanted.key, to: wanted.value) else { return .refused }+ if before != .some(.some(wanted.value)) {+ guard await config.set(wanted.key, to: wanted.value) else { return .refused }+ outcome = .changed+ }if !isPeels {switch before {case .none: previous.removeValue(forKey: name)@@ -38,7 +41,6 @@ public struct GitLedger {}}written[name] = wanted.value- outcome = .changed}return outcome}@@ -50,7 +52,7 @@ public struct GitLedger {let name = key.lowercased()let now = settings[name]if let mine = written[name] {- if now == .some(.some(mine)) {+ if now == .some(.some(mine)), previous[name] != mine {let restored = if let before = previous[name] {await config.set(key, to: before)} else {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swiftindex a5790e79..a91bac74 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift@@ -116,6 +116,24 @@ struct GitSettingsTests {#expect(settings["user.signingkey"] == .some(key))}+ @Test func signingThePersonHadWithGPGComesBackWhole() async throws {+ let git = try await GitHome()+ let key = try git.publicKey("id_ed25519.pub")+ for (name, value) in [("gpg.format", "openpgp"), ("user.signingKey", "ABCDEF0123"), ("commit.gpgSign", "true")] {+ #expect(await git.config.set(name, to: value))+ }+ var ledger = GitLedger()+ #expect(await ledger.turnOn(.signCommits, signingKey: key, in: git.config) == .changed)+ #expect(GitSetting.signCommits.isOn(in: try await git.settings()))+ #expect(await ledger.turnOff(.signCommits, in: git.config) == .changed)+ let settings = try await git.settings()+ #expect(settings["gpg.format"] == "openpgp")+ #expect(settings["user.signingkey"] == "ABCDEF0123")+ #expect(settings["commit.gpgsign"] == "true")+ #expect(!GitSetting.signCommits.isOn(in: settings))+ #expect(ledger.written.isEmpty && ledger.previous.isEmpty)+ }+@Test func everyWayGitWritesTrueCountsAsOn() {for written in ["true", "TRUE", "yes", "on", "1"] {#expect(GitSetting.pruneOnFetch.isOn(in: ["fetch.prune": written]), "\(written)")diff --git a/TERMINAL.md b/TERMINAL.mdindex 5dc73564..5c96c8eb 100644--- a/TERMINAL.md+++ b/TERMINAL.md@@ -396,7 +396,7 @@ git config --global column.ui auto| Setting | What it does || --- | --- |-| [Sign commits with your SSH key](https://git-scm.com/docs/git-config#Documentation/git-config.txt-commitgpgSign) | Every commit is signed with your SSH key, and GitHub shows it as Verified once you add the key there as a signing key. Peel offers it when one of `id_ed25519.pub`, `id_ecdsa.pub`, and `id_rsa.pub` is in `~/.ssh`, or when signing is already on, and uses the first of them. Turning it off stops the signing, and puts the format and the key back as they were before Peel set them, leaving them alone if Peel didn't. |+| [Sign commits with your SSH key](https://git-scm.com/docs/git-config#Documentation/git-config.txt-commitgpgSign) | Every commit is signed with your SSH key, and GitHub shows it as Verified once you add the key there as a signing key. Peel offers it when one of `id_ed25519.pub`, `id_ecdsa.pub`, and `id_rsa.pub` is in `~/.ssh`, or when signing is already on, and uses the first of them. Turning it off puts the three keys back as they were before Peel set them: a key Peel found already set stays, so signing you had with another format, such as GPG, goes on as before, and signing you set up yourself with an SSH key stops, as a setting you made yourself goes back to Git's default. |```sh# Sign commits with your SSH key