Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Read a signing key written in Git's settings as a key, not a path

Țugui Dragoș3679ed6d72b7
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 150fe9c8..f5c55889 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -224957,6 +224957,112 @@
}
}
},
+ "With the key written in your Git settings" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Pomocí klíče zapsaného ve vašem nastavení Gitu"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mit dem Schlüssel, der in deinen Git-Einstellungen steht"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Con la clave escrita en tus ajustes de Git"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Avec la clé écrite dans vos réglages Git"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Con la chiave scritta nelle tue impostazioni di Git"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Gitの設定に記述された鍵を使用"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Git 설정에 적힌 키 사용"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Met de sleutel die in je Git-instellingen staat"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Z kluczem zapisanym w Twoich ustawieniach Gita"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Com a chave escrita nos seus ajustes do Git"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Cu cheia scrisă în configurările dvs. Git"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "С ключом, записанным в Ваших настройках Git"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Med nyckeln inskriven i dina Git-inställningar"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Git ayarlarınızda yazılı anahtarla"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "З ключем, записаним у ваших налаштуваннях Git"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "使用写在你的Git设置中的密钥"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "使用寫在你的Git設定中的密鑰"
+ }
+ }
+ }
+ },
"With this off, Peel contacts nothing on its own. Homebrew goes online only when you ask it to: Update, Upgrade (there or on an app’s own page), Repair Taps, and the vulnerability scan, and to get its own copy of Ruby again when a failed update left it behind. Your own Homebrew settings, in a brew.env file, can change that, and the Homebrew page then says what they change." : {
"comment" : "The note of Check for app updates in Settings > Privacy. Ruby is a programming language's name; brew.env is a file name.",
"localizations" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swift b/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swift
index 9d999041..f1777819 100644
--- a/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swift
@@ -43,6 +43,19 @@ public enum GitSetting: CaseIterable, Sendable {
.first { FileManager.default.fileExists(atPath: $0) }
}
+ /// Whether `user.signingKey` holds the public key itself rather than a path to one: `git-config(1)` writes it after
+ /// `key::`, and Git still takes it bare.
+ public static func isTheKeyItself(_ signingKey: String) -> Bool {
+ signingKey.hasPrefix("key::") || signingKey.hasPrefix("ssh-")
+ }
+
+ public func commands(signingKey: String?) -> [String] {
+ values(signingKey: signingKey).map { value in
+ let shown = value.value.contains(" ") ? value.value.quotedForTheShell : value.value
+ return "git config --global \(value.key) \(shown)"
+ }
+ }
+
/// What turning the setting on writes. Signing needs a public key, so without one it writes nothing.
public func values(signingKey: String?) -> [Value] {
switch self {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift
index 0f6ab1e9..69453372 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift
@@ -32,6 +32,22 @@ private struct GitHome: ~Copyable {
}
struct GitSettingsTests {
+ @Test func aSigningKeyWrittenInTheSettingsIsNoPath() {
+ let written = "key::ssh-ed25519 AAAAC3Nz laptop"
+
+ #expect(GitSetting.isTheKeyItself(written))
+ #expect(GitSetting.isTheKeyItself("ssh-ed25519 AAAAC3Nz laptop"))
+ #expect(!GitSetting.isTheKeyItself("~/.ssh/id_ed25519.pub"))
+ #expect(!GitSetting.isTheKeyItself("/Users/me/.ssh/key::old.pub"))
+ #expect(GitSetting.signCommits.commands(signingKey: written) == [
+ "git config --global gpg.format ssh",
+ "git config --global user.signingKey 'key::ssh-ed25519 AAAAC3Nz laptop'",
+ "git config --global commit.gpgSign true",
+ ])
+ #expect(GitSetting.signCommits.commands(signingKey: "~/.ssh/id_ed25519.pub")[1]
+ == "git config --global user.signingKey ~/.ssh/id_ed25519.pub")
+ }
+
@Test func everySettingTurnsOnAndOffThroughGitAndLeavesNothingBehind() async throws {
let git = try await GitHome()
let key = try git.publicKey("id_ed25519.pub")
diff --git a/Peel/Views/Terminal/GitTab.swift b/Peel/Views/Terminal/GitTab.swift
index 28e8c286..d0607102 100644
--- a/Peel/Views/Terminal/GitTab.swift
+++ b/Peel/Views/Terminal/GitTab.swift
@@ -70,8 +70,7 @@ private struct GitSettingRow: View {
TerminalSwitchRow(
title: setting.title,
detail: setting.detail,
- footnote: setting.values(signingKey: git.state?.signingKey ?? "~/.ssh/id_ed25519.pub")
- .map { "git config --global \($0.key) \($0.value)" }
+ footnote: setting.commands(signingKey: git.state?.signingKey ?? "~/.ssh/id_ed25519.pub")
.joined(separator: "\n"),
caption: caption,
isOn: Binding(
@@ -86,6 +85,8 @@ private struct GitSettingRow: View {
if git.isSetInIncludedFiles(setting) { return "Set in a file your Git settings include" }
guard setting == .signCommits else { return nil }
guard let key = git.state?.signingKey else { return "Needs an SSH key in ~/.ssh" }
- return "With \(URL(filePath: key).abbreviatedPath)"
+ return GitSetting.isTheKeyItself(key)
+ ? "With the key written in your Git settings"
+ : "With \(URL(filePath: key).abbreviatedPath)"
}
}