Repository: CodeEditApp/CodeEdit
File: CodeEditModules/Modules/AppPreferences/src/Model/Source Control/SourceControlPreferences.swift (Swift)

Code before:
        public init() {}
        /// Explicit decoder init for setting default values when key is not present in `JSON`
        public init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)
            self.general = try container.decodeIfPresent(SourceControlGeneral.self, forKey: .general) ?? .init()
            self.git = try container.decodeIfPresent(SourceControlGit.self, forKey: .git) ?? .init()
        }
    }

    struct SourceControlGeneral: Codable {
        /// Indicates whether or not the source control is active
        public var enableSourceControl: Bool = true
        /// Indicates whether or not we should include the upsteam changes
        public var refreshStatusLocaly: Bool = false
        /// Indicates whether or not we should include the upsteam changes
        public var fetchRefreshServerStatus: Bool = false
        /// Indicates whether or not we should include the upsteam changes
        public var addRemoveAutomatically: Bool = false
        /// Indicates whether or not we should include the upsteam changes
        public var selectFilesToCommit: Bool = false
        /// Indicates whether or not to show the source control changes
        public var showSourceControlChanges: Bool = true
        /// Indicates whether or not we should include the upsteam
        public var includeUpstreamChanges: Bool = false
        /// The selected value of the comparison view
        public var comparisonView: ComparisonView = .localLeft
        /// The selected value of the control navigator
        public var controlNavigator: ControlNavigator = .sortName
        /// The name of the default branch
        public var defaultBranchName: String = "main"
        /// Default initializer
        public init() {}
        /// Explicit decoder init for setting default values when key is not present in `JSON`
        public init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)
            self.enableSourceControl = try container.decodeIfPresent(Bool.self, forKey: .enableSourceControl) ?? true
            self.refreshStatusLocaly = try container.decodeIfPresent(Bool.self, forKey: .refreshStatusLocaly) ?? true
            self.fetchRefreshServerStatus = try container.decodeIfPresent(Bool.self,
                                                                          forKey: .fetchRefreshServerStatus) ?? true
            self.addRemoveAutomatically = try container.decodeIfPresent(Bool.self,
                                                                        forKey: .addRemoveAutomatically) ?? true
            self.selectFilesToCommit = try container.decodeIfPresent(Bool.self, forKey: .selectFilesToCommit) ?? true
            self.showSourceControlChanges = try container.decodeIfPresent(Bool.self,
                                                                          forKey: .showSourceControlChanges) ?? true
            self.includeUpstreamChanges = try container.decodeIfPresent(Bool.self,
                                                                        forKey: .includeUpstreamChanges) ?? true
            self.comparisonView = try container.decodeIfPresent(ComparisonView.self,
                                                                forKey: .comparisonView) ?? .localLeft
            self.controlNavigator = try container.decodeIfPresent(ControlNavigator.self,
                                                                  forKey: .controlNavigator) ?? .sortName
            self.defaultBranchName = try container.decodeIfPresent(String.self, forKey: .defaultBranchName) ?? "main"

Review comment (suggestion):
Since this is a setting which will be in `preferences.json` make sure to choose a name that is descriptive to what it does.

Code after:
        public init() {}
        /// Explicit decoder init for setting default values when key is not present in `JSON`
        public init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)
            self.general = try container.decodeIfPresent(SourceControlGeneral.self, forKey: .general) ?? .init()
            self.git = try container.decodeIfPresent(SourceControlGit.self, forKey: .git) ?? .init()
        }
    }

    struct SourceControlGeneral: Codable {
        /// Indicates whether or not the source control is active
        public var enableSourceControl: Bool = true
        /// Indicates whether or not we should include the upsteam changes
        public var refreshStatusLocaly: Bool = false
        /// Indicates whether or not we should include the upsteam changes
        public var fetchRefreshServerStatus: Bool = false
        /// Indicates whether or not we should include the upsteam changes
        public var addRemoveAutomatically: Bool = false
        /// Indicates whether or not we should include the upsteam changes
        public var selectFilesToCommit: Bool = false
        /// Indicates whether or not to show the source control changes
        public var showSourceControlChanges: Bool = true
        /// Indicates whether or not we should include the upsteam
        public var includeUpstreamChanges: Bool = false
        /// The selected value of the comparison view
        public var revisionComparisonLayout: RevisionComparisonLayout = .localLeft
        /// The selected value of the control navigator
        public var controlNavigatorOrder: ControlNavigatorOrder = .sortByName
        /// The name of the default branch
        public var defaultBranchName: String = "main"
        /// Default initializer
        public init() {}
        /// Explicit decoder init for setting default values when key is not present in `JSON`
        public init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)
            self.enableSourceControl = try container.decodeIfPresent(Bool.self, forKey: .enableSourceControl) ?? true
            self.refreshStatusLocaly = try container.decodeIfPresent(Bool.self, forKey: .refreshStatusLocaly) ?? true
            self.fetchRefreshServerStatus = try container.decodeIfPresent(Bool.self,
                                                                          forKey: .fetchRefreshServerStatus) ?? true
            self.addRemoveAutomatically = try container.decodeIfPresent(Bool.self,
                                                                        forKey: .addRemoveAutomatically) ?? true
            self.selectFilesToCommit = try container.decodeIfPresent(Bool.self, forKey: .selectFilesToCommit) ?? true
            self.showSourceControlChanges = try container.decodeIfPresent(Bool.self,
                                                                          forKey: .showSourceControlChanges) ?? true
            self.includeUpstreamChanges = try container.decodeIfPresent(Bool.self,
                                                                        forKey: .includeUpstreamChanges) ?? true
            self.revisionComparisonLayout = try container.decodeIfPresent(RevisionComparisonLayout.self,
                                                                forKey: .revisionComparisonLayout) ?? .localLeft
            self.controlNavigatorOrder = try container.decodeIfPresent(ControlNavigatorOrder.self,
                                                                  forKey: .controlNavigatorOrder) ?? .sortByName
            self.defaultBranchName = try container.decodeIfPresent(String.self, forKey: .defaultBranchName) ?? "main"