Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Sources/SwiftGitX/Collections/ConfigCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,39 @@ public struct ConfigCollection {
/// - key: The key to set the value for.
///
/// This will set the configuration value for the repository.
@available(*, deprecated, message: "Use set(_:to:) instead. Be careful, parameter order is reversed.")
public func set(_ string: String, forKey key: String) throws(SwiftGitXError) {
try self.set(key, to: string)
}

/// Sets a configuration value for the repository.
///
/// - Parameters:
/// - key: The key to set the value for.
/// - value: The value to set.
///
/// This will set the configuration value for the repository, if a repository instance is provided.
/// Otherwise, it will set the global configuration value.
///
/// ### Example
///
/// ```swift
/// // Set repository-specific configuration values
/// try repository.config.set("user.name", to: "John Doe")
/// try repository.config.set("user.email", to: "john.doe@example.com")
/// ```
///
/// ```swift
/// // Set global configuration values
/// try Repository.config.set("user.name", to: "John Doe")
/// try Repository.config.set("user.email", to: "john.doe@example.com")
/// ```
public func set(_ key: String, to value: String) throws(SwiftGitXError) {
let configPointer = try self.configPointer()
defer { git_config_free(configPointer) }

try git(operation: .config) {
git_config_set_string(configPointer, key, string)
git_config_set_string(configPointer, key, value)
}
}

Expand Down