Sources/Orgstar/GitSettings.swift
54 lines · 2777 bytes
1#if !APPSTORE
2import OrgApp
3import OrgPrograms
4import SwiftUI
5
6/// Settings ▸ Git: automatic commits for each sidebar folder that is a git repository.
7struct GitSettingsForm: View {
8 let workspace: WorkspaceModel?
9 @State private var settings = GitFolderSettings.shared
10 @State private var gitInstalled = true
11
12 var body: some View {
13 Form {
14 Section {
15 let roots = workspace?.rootPaths ?? []
16 if roots.isEmpty {
17 Text("Add a folder to the sidebar to commit its changes automatically.", tableName: "DeveloperID").foregroundStyle(.secondary)
18 }
19 ForEach(roots, id: \.self) { root in
20 let name = (root as NSString).lastPathComponent
21 if GitBranch.current(for: (root as NSString).appendingPathComponent("x")) == nil {
22 LabeledContent {
23 Text("Not a git repository", tableName: "DeveloperID").foregroundStyle(.secondary)
24 } label: {
25 Text(verbatim: name).help(root)
26 }
27 } else {
28 Picker(selection: Binding(get: { settings.mode(for: root) }, set: { settings.set($0, for: root) })) {
29 Text("Off", tableName: "DeveloperID").tag(GitFolderSettings.Mode.off)
30 Text("Commit", tableName: "DeveloperID").tag(GitFolderSettings.Mode.commit)
31 Text("Commit, Pull and Push", tableName: "DeveloperID").tag(GitFolderSettings.Mode.sync)
32 } label: {
33 Text(verbatim: name).help(root)
34 }
35 .disabled(!gitInstalled)
36 }
37 }
38 } header: {
39 Text("Commit changes automatically", tableName: "DeveloperID")
40 } footer: {
41 VStack(alignment: .leading, spacing: 4) {
42 if !gitInstalled {
43 Text("git isn't installed. Install the Xcode command line tools or git from Homebrew.", tableName: "DeveloperID").settingsFooter()
44 }
45 Text("A minute after the last save in a folder, and when orgstar quits, orgstar commits the files it saved there, and only those. Commit, Pull and Push pulls with --ff-only first and pushes after the commit. orgstar never merges or resolves a conflict, and doesn't commit while a merge, rebase or cherry-pick is in progress.", tableName: "DeveloperID").settingsFooter()
46 }
47 }
48 }
49 .formStyle(.grouped)
50 .frame(height: 330)
51 .task { gitInstalled = Git.find() != nil }
52 }
53}
54#endif