From ff840f012d94ff6d328cbd952bfc399cd5c8177f Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Sun, 8 Oct 2023 12:00:47 +0100 Subject: [PATCH 1/4] Swiftlint fixes --- .swiftlint.yml | 1 + .../xcschemes/Version-Control.xcscheme | 66 ++++++++++++++++++ .../Services/Models/Client/Add.swift | 2 +- .../Services/Models/Client/Apply.swift | 6 +- .../Services/Models/Client/Branch.swift | 45 ++++++++----- .../Services/Models/Client/Check.swift | 8 ++- .../Services/Models/Client/Checkout.swift | 12 ++-- .../Services/Models/Client/Cherry-Pick.swift | 11 +-- .../Services/Models/Client/Clone.swift | 2 +- .../Services/Models/Client/Commit.swift | 2 +- .../Services/Models/Client/Config.swift | 31 ++++++--- .../Services/Models/Client/Core.swift | 10 ++- .../Services/Models/Client/Diff-Index.swift | 6 +- .../Services/Models/Client/Format-Patch.swift | 12 ++-- .../Services/Models/Client/GitIgnore.swift | 9 ++- .../Services/Models/Client/GitLog.swift | 9 ++- .../Services/Models/Client/Init.swift | 10 ++- .../Services/Models/Client/LFS.swift | 11 +-- .../Services/Models/Client/RM.swift | 21 ++++-- .../Services/Models/Client/Refs.swift | 2 +- .../Services/Models/Client/Remote.swift | 10 +-- .../Services/Models/Client/Reset.swift | 2 +- .../Services/Models/Client/Rev-List.swift | 67 +++++++++++++------ .../Services/Models/Client/Rev-Parse.swift | 7 +- .../Services/Models/Client/Stash.swift | 2 +- .../Services/Models/Client/Tag.swift | 46 ++++++++----- .../Services/Models/Client/Update-Index.swift | 3 +- .../Services/Models/Client/Update-Ref.swift | 25 +++++-- .../Services/Models/CommitIdentity.swift | 10 ++- .../Services/Models/GitBranch.swift | 44 ++++++------ .../Utils/Extensions/Date.swift | 2 +- .../Utils/Extensions/String.swift | 12 ++-- .../Utils/Helpers/RemoveRemotePrefix.swift | 9 ++- .../Version-Control/Utils/ShellClient.swift | 23 +++---- 34 files changed, 366 insertions(+), 172 deletions(-) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/Version-Control.xcscheme diff --git a/.swiftlint.yml b/.swiftlint.yml index 6708aac8..78aab1b4 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -17,6 +17,7 @@ identifier_name: excluded: - id - vc + - to # (short) File extensions: - c - m diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/Version-Control.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/Version-Control.xcscheme new file mode 100644 index 00000000..c81273e0 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/Version-Control.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Version-Control/Services/Models/Client/Add.swift b/Sources/Version-Control/Services/Models/Client/Add.swift index a9d20167..148e43df 100644 --- a/Sources/Version-Control/Services/Models/Client/Add.swift +++ b/Sources/Version-Control/Services/Models/Client/Add.swift @@ -18,7 +18,7 @@ public struct Add { */ func addConflictedFile(directoryURL: URL, file: GitFileItem) async throws { - + try ShellClient().run("cd \(directoryURL.relativePath.escapedWhiteSpaces()); git add -- \(file.url)") } } diff --git a/Sources/Version-Control/Services/Models/Client/Apply.swift b/Sources/Version-Control/Services/Models/Client/Apply.swift index 958d3ab7..871526d6 100644 --- a/Sources/Version-Control/Services/Models/Client/Apply.swift +++ b/Sources/Version-Control/Services/Models/Client/Apply.swift @@ -10,7 +10,7 @@ import Foundation public struct Apply { - + /// Applies a Git patch to the Git index for a specified file in a specified directory. /// /// - Parameters: @@ -21,7 +21,9 @@ public struct Apply { /// - An error of type `Error` if any issues occur during the patch application process. /// /// - Note: - /// If the file was renamed (`file.gitStatus == .renamed`), this function recreates the rename operation by staging the removal of the old file and adding the old file's blob to the index under the new name. + /// If the file was renamed (`file.gitStatus == .renamed`), \ + /// this function recreates the rename operation by staging the removal of the old file \ + /// and adding the old file's blob to the index under the new name. /// /// - Example: /// ```swift diff --git a/Sources/Version-Control/Services/Models/Client/Branch.swift b/Sources/Version-Control/Services/Models/Client/Branch.swift index bc64f089..e625bccd 100644 --- a/Sources/Version-Control/Services/Models/Client/Branch.swift +++ b/Sources/Version-Control/Services/Models/Client/Branch.swift @@ -10,9 +10,9 @@ import Foundation public struct Branch { - + public init() {} - + /// Retrieves the name of the current Git branch in a specified directory. /// /// - Parameters: @@ -47,7 +47,8 @@ public struct Branch { /// Retrieves a list of Git branches in a specified directory. /// /// - Parameters: - /// - allBranches: A Boolean flag indicating whether to list all branches, including remote branches (default is `false`). + /// - allBranches: A Boolean flag indicating whether to list all branches, \ + /// including remote branches (default is `false`). /// - directoryURL: The URL of the directory containing the Git repository. /// /// - Throws: @@ -168,7 +169,8 @@ public struct Branch { /// - An error of type `Error` if any issues occur during the branch renaming process. /// /// - Note: - /// If the branch renaming is successful, the old branch name will no longer exist, and a new branch with the specified `newName` will be created. + /// If the branch renaming is successful, the old branch name will no longer exist, \ + /// and a new branch with the specified `newName` will be created. /// /// - Example: /// ```swift @@ -203,7 +205,8 @@ public struct Branch { /// - An error of type `Error` if any issues occur during the branch deletion process. /// /// - Returns: - /// A `Bool` value indicating whether the branch was successfully deleted. Returns `true` if the branch was deleted successfully; otherwise, returns `false`. + /// A `Bool` value indicating whether the branch was successfully deleted. \ + /// Returns `true` if the branch was deleted successfully; otherwise, returns `false`. /// /// - Example: /// ```swift @@ -229,12 +232,11 @@ public struct Branch { /// Prepare and execute the Git command to delete the local branch using a ShellClient. try ShellClient().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git branch -D \(branchName)") - + // Return true to indicate that the branch deletion was attempted. return true } - /// Deletes a remote Git branch in a specified directory. /// /// - Parameters: @@ -246,7 +248,9 @@ public struct Branch { /// - An error of type `Error` if any issues occur during the remote branch deletion process. /// /// - Note: - /// This function attempts to delete the remote branch on the specified remote repository. If the deletion fails due to the remote branch already being deleted or for any other reason, it may try to remove the corresponding local reference. + /// This function attempts to delete the remote branch on the specified remote repository. \ + /// If the deletion fails due to the remote branch already being deleted or for any other reason, \ + /// it may try to remove the corresponding local reference. /// /// - Example: /// ```swift @@ -255,7 +259,11 @@ public struct Branch { /// let remoteBranchName = "feature/old-feature" /// /// do { - /// try deleteRemoteBranch(directoryURL: directoryURL, remoteName: remoteName, remoteBranchName: remoteBranchName) + /// try deleteRemoteBranch( + /// directoryURL: directoryURL, + /// remoteName: remoteName, + /// remoteBranchName: remoteBranchName + /// ) /// print("Remote branch '\(remoteBranchName)' was successfully deleted on '\(remoteName)'.") /// } catch { /// print("Error deleting remote branch: \(error.localizedDescription)") @@ -330,17 +338,17 @@ public struct Branch { "--points-at=\(commitsh)", "--format=%(refname:short)" ] - + let result = try ShellClient.live().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git \(args)") - + let resultSplit = result.split(separator: "\n").map { String($0) } let resultRange = Array(resultSplit.reversed()) return resultRange.isEmpty ? nil : resultRange } - - /// Retrieves a dictionary of branch names and their corresponding commit SHAs that are merged into the specified branch. + /// Retrieves a dictionary of branch names and their corresponding commit SHAs \ + /// that are merged into the specified branch. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -350,7 +358,8 @@ public struct Branch { /// - An error of type `Error` if any issues occur during the branch retrieval process. /// /// - Returns: - /// A dictionary containing branch names as keys and their corresponding commit SHAs as values, representing branches that are merged into the specified branch. + /// A dictionary containing branch names as keys and their corresponding commit SHAs as values, \ + /// representing branches that are merged into the specified branch. /// /// - Example: /// ```swift @@ -377,19 +386,19 @@ public struct Branch { func getMergedBranches(directoryURL: URL, branchName: String) throws -> [String: String] { let canonicalBranchRef = Refs().formatAsLocalRef(name: branchName) - + let args = ["branch", "--format=%(refname):%(objectname)", "--merged", branchName] - + do { let result = try ShellClient().run("cd \(directoryURL.relativePath.escapedWhiteSpaces());git \(args)") - + var mergedBranches = [String: String]() for line in result.split(separator: "\n") { let components = line.split(separator: ":", maxSplits: 1) if components.count == 2 { let ref = String(components[0]) let sha = String(components[1]) - + // Don't include the branch we're using to compare against // in the list of branches merged into that branch. if ref != canonicalBranchRef { diff --git a/Sources/Version-Control/Services/Models/Client/Check.swift b/Sources/Version-Control/Services/Models/Client/Check.swift index d11b141d..33d2df9e 100644 --- a/Sources/Version-Control/Services/Models/Client/Check.swift +++ b/Sources/Version-Control/Services/Models/Client/Check.swift @@ -9,16 +9,18 @@ import Foundation public struct Check { - + public init() {} - + /// Checks if a given workspace directory is a Git repository or a Git worktree. /// /// - Parameter workspaceURL: The URL of the workspace directory to be checked. /// /// - Returns: `true` if the workspace is a Git repository or worktree, `false` otherwise. /// - /// - Note: This function checks the type of the workspace using `getRepositoryType`, and if it's marked as unsafe by Git, it falls back to a naive approximation by looking for the `.git` directory. + /// - Note: This function checks the type of the workspace using `getRepositoryType`, \ + /// and if it's marked as unsafe by Git, \ + /// it falls back to a naive approximation by looking for the `.git` directory. /// /// - Example: /// ```swift diff --git a/Sources/Version-Control/Services/Models/Client/Checkout.swift b/Sources/Version-Control/Services/Models/Client/Checkout.swift index ab97b1ae..b4088e22 100644 --- a/Sources/Version-Control/Services/Models/Client/Checkout.swift +++ b/Sources/Version-Control/Services/Models/Client/Checkout.swift @@ -10,9 +10,9 @@ import Foundation public struct Checkout { - + public init() {} - + /// Checks out a Git branch in a specified directory. /// /// - Parameters: @@ -93,7 +93,11 @@ public struct Checkout { /// let resolutionStrategy = ManualConflictResolution.ours // Replace with the desired resolution strategy /// /// do { - /// try checkoutConflictedFile(directoryURL: directoryURL, file: conflictedFile, resolution: resolutionStrategy) + /// try checkoutConflictedFile( + /// directoryURL: directoryURL, + /// file: conflictedFile, + /// resolution: resolutionStrategy + /// ) /// print("File '\(conflictedFile.url.relativePath)' checked out with \(resolutionStrategy) resolution.") /// } catch { /// print("Error checking out conflicted file: \(error.localizedDescription)") @@ -111,7 +115,7 @@ public struct Checkout { "--", file.url.relativePath ] - + try ShellClient().run("cd \(directoryURL.relativePath.escapedWhiteSpaces());git \(args)") } } diff --git a/Sources/Version-Control/Services/Models/Client/Cherry-Pick.swift b/Sources/Version-Control/Services/Models/Client/Cherry-Pick.swift index 676225c9..db02e6aa 100644 --- a/Sources/Version-Control/Services/Models/Client/Cherry-Pick.swift +++ b/Sources/Version-Control/Services/Models/Client/Cherry-Pick.swift @@ -10,9 +10,9 @@ import Foundation public struct CherryPick { - + public init() {} - + /// The app-specific results from attempting to cherry pick commits enum CherryPickResult: String { /// Git completed the cherry pick without reporting any errors, and the caller can @@ -133,10 +133,13 @@ public struct CherryPick { public func isCherryPickHeadFound(directoryURL: URL) -> Bool { do { let cherryPickHeadPath = try String(contentsOf: directoryURL) + ".git/CHERRY_PICK_HEAD" - + return FileManager.default.fileExists(atPath: cherryPickHeadPath) } catch { - print("[cherryPick] A problem was encountered reading .git/CHERRY_PICK_HEAD, so it is unsafe to continue cherry-picking.") + print( + "[cherryPick] A problem was encountered reading .git/CHERRY_PICK_HEAD," + + " so it is unsafe to continue cherry-picking." + ) return false } } diff --git a/Sources/Version-Control/Services/Models/Client/Clone.swift b/Sources/Version-Control/Services/Models/Client/Clone.swift index 2f5acb4f..074cce08 100644 --- a/Sources/Version-Control/Services/Models/Client/Clone.swift +++ b/Sources/Version-Control/Services/Models/Client/Clone.swift @@ -10,7 +10,7 @@ import Foundation public struct Clone { - + public init() {} /// Clones a repository from a given url into to the specified path. diff --git a/Sources/Version-Control/Services/Models/Client/Commit.swift b/Sources/Version-Control/Services/Models/Client/Commit.swift index a98c2524..506a5a11 100644 --- a/Sources/Version-Control/Services/Models/Client/Commit.swift +++ b/Sources/Version-Control/Services/Models/Client/Commit.swift @@ -10,7 +10,7 @@ import Foundation public struct Commit { - + public init() {} /// Creates a Git commit in a specified Git repository directory. diff --git a/Sources/Version-Control/Services/Models/Client/Config.swift b/Sources/Version-Control/Services/Models/Client/Config.swift index bd7049f5..b45ad2df 100644 --- a/Sources/Version-Control/Services/Models/Client/Config.swift +++ b/Sources/Version-Control/Services/Models/Client/Config.swift @@ -10,23 +10,27 @@ import Foundation public struct Config { - + public init() {} - + /// Look up a Git configuration value by name within a specific repository context. /// - /// This function retrieves a Git configuration value within the context of a specific Git repository by reading the repository's path and then using the `getConfigValueInPath` function to perform the configuration value lookup. + /// This function retrieves a Git configuration value within the context of a specific Git repository \ + /// by reading the repository's path and then using the `getConfigValueInPath` function to \ + /// perform the configuration value lookup. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. /// - name: The name of the Git configuration key to look up. - /// - onlyLocal: Whether or not the value should be retrieved from local repository settings only. Default is `false`, which means both local and global settings are considered. + /// - onlyLocal: Whether or not the value should be retrieved from local repository settings only. \ + /// Default is `false`, which means both local and global settings are considered. /// /// - Throws: /// - An error of type `Error` if any issues occur during the configuration value lookup process. /// /// - Returns: - /// The string value associated with the specified Git configuration key in the context of the repository, or `nil` if the configuration key is not found. + /// The string value associated with the specified Git configuration key in the context of the repository, \ + /// or `nil` if the configuration key is not found. /// /// - Example: /// ```swift @@ -57,7 +61,8 @@ public struct Config { /// Look up a global Git configuration value by name. /// - /// This function retrieves a Git configuration value from the global Git configuration file based on the provided `name`. + /// This function retrieves a Git configuration value from the global Git configuration file based + /// on the provided `name`. /// /// - Parameters: /// - name: The name of the Git configuration key to look up. @@ -84,7 +89,8 @@ public struct Config { /// ``` /// /// - Note: - /// This function retrieves a global Git configuration value using the `getConfigValueInPath` function with appropriate parameters. + /// This function retrieves a global Git configuration value using the `getConfigValueInPath` + /// function with appropriate parameters. public func getGlobalConfigValue(name: String) throws -> String? { return try getConfigValueInPath(name: name, path: nil, @@ -247,7 +253,9 @@ public struct Config { /// Sets a Git configuration value within a specific repository context. /// - /// This function sets a Git configuration value within the context of a specific Git repository by reading the repository's path and then using the `setConfigValueInPath` function to perform the configuration value setting. + /// This function sets a Git configuration value within the context of a specific + /// Git repository by reading the repository's path and then using the `setConfigValueInPath` + /// function to perform the configuration value setting. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -412,7 +420,9 @@ public struct Config { /// ``` /// /// - Note: - /// This function checks if the specified Git configuration value already exists in the global Git configuration file. If it does not exist, it adds the value using the `git config` command with the `--global -z --get-all` flags. + /// This function checks if the specified Git configuration value \ + /// already exists in the global Git configuration file. If it does not exist, \ + /// it adds the value using the `git config` command with the `--global -z --get-all` flags. public func addGlobalConfigValueIfMissing(name: String, value: String) throws { @@ -504,7 +514,8 @@ public struct Config { /// ``` /// /// - Note: - /// This function removes a Git configuration value within the context of a specific Git repository by reading the repository's path and then using the `removeConfigValueInPath` function to perform the removal. + /// This function removes a Git configuration value within the context of a specific Git repository + /// by reading the repository's path and then using the `removeConfigValueInPath` function to perform the removal. public func removeConfigValue(directoryURL: URL, name: String) throws { try removeConfigValueInPath(name: name, diff --git a/Sources/Version-Control/Services/Models/Client/Core.swift b/Sources/Version-Control/Services/Models/Client/Core.swift index f104f66e..74319412 100644 --- a/Sources/Version-Control/Services/Models/Client/Core.swift +++ b/Sources/Version-Control/Services/Models/Client/Core.swift @@ -34,7 +34,9 @@ public func gitRebaseArguments() -> [String] { /// Parse the commit SHA from a Git command result string. /// -/// This function extracts the commit SHA from a Git command result string. It assumes that the result string follows a specific format, typically used in Git commands that return commit information. +/// This function extracts the commit SHA from a Git command result string. \ +/// It assumes that the result string follows a specific format, \ +/// typically used in Git commands that return commit information. /// /// - Parameter result: The Git command result string containing commit information. /// @@ -48,10 +50,12 @@ public func gitRebaseArguments() -> [String] { /// ``` /// /// - Note: -/// This function is designed to work with Git command result strings that have a specific format, where the commit SHA is enclosed in square brackets (e.g., "[commit abcdef12345678901234567890]"). +/// This function is designed to work with Git command result strings that have a specific format, \ +/// where the commit SHA is enclosed in square brackets (e.g., "[commit abcdef12345678901234567890]"). /// /// - Warning: -/// Ensure that the provided result string conforms to the expected format; otherwise, this function may not extract the commit SHA correctly. +/// Ensure that the provided result string conforms to the expected format; otherwise, \ +/// this function may not extract the commit SHA correctly. public func parseCommitSHA(result: String) -> String { return String(result.split(separator: "]")[0].split(separator: " ")[1]) diff --git a/Sources/Version-Control/Services/Models/Client/Diff-Index.swift b/Sources/Version-Control/Services/Models/Client/Diff-Index.swift index c331a396..caf9c5af 100644 --- a/Sources/Version-Control/Services/Models/Client/Diff-Index.swift +++ b/Sources/Version-Control/Services/Models/Client/Diff-Index.swift @@ -96,9 +96,9 @@ public func getIndexChanges(directoryURL: URL) throws -> [String: IndexStatus] { let pieces = result.split(separator: "\0") - for i in stride(from: 0, to: pieces.count, by: 2) { - let status = try getNoRenameIndexStatus(status: String(pieces[i])) - let path = String(pieces[i + 1]) + for index in stride(from: 0, to: pieces.count, by: 2) { + let status = try getNoRenameIndexStatus(status: String(pieces[index])) + let path = String(pieces[index + 1]) map[path] = status } diff --git a/Sources/Version-Control/Services/Models/Client/Format-Patch.swift b/Sources/Version-Control/Services/Models/Client/Format-Patch.swift index 4cf72c14..006ade75 100644 --- a/Sources/Version-Control/Services/Models/Client/Format-Patch.swift +++ b/Sources/Version-Control/Services/Models/Client/Format-Patch.swift @@ -11,7 +11,8 @@ import Foundation /// Generate a patch representing the changes associated with a range of commits. /// -/// This function generates a patch representing the changes introduced by a range of commits between the `base` and `head` references. +/// This function generates a patch representing the changes introduced by \ +/// a range of commits between the `base` and `head` references. /// /// - Parameters: /// - directoryURL: The URL of the Git repository directory where the `git format-patch` command will be executed. @@ -20,7 +21,8 @@ import Foundation /// /// - Returns: A string containing the generated patch. /// -/// - Throws: An error if there is a problem executing the `git format-patch` command or if the Git repository is not in a valid state. +/// - Throws: An error if there is a problem executing the `git format-patch` command or \ +/// if the Git repository is not in a valid state. /// /// - Example: /// ```swift @@ -37,10 +39,12 @@ import Foundation /// } /// ``` /// -/// - Note: Ensure that you have the necessary permissions to execute Git commands in the specified directory, and that the Git repository is in a valid state. +/// - Note: Ensure that you have the necessary permissions to execute Git commands in the specified directory, \ +/// and that the Git repository is in a valid state. public func formatPatch(directoryURL: URL, base: String, head: String) throws -> String { let result = try ShellClient.live().run( - "cd \(directoryURL.relativePath.escapedWhiteSpaces());git format-patch --unified=1 --minimal --stdout \(base)..<\(head)" + "cd \(directoryURL.relativePath.escapedWhiteSpaces());" + + "git format-patch --unified=1 --minimal --stdout \(base)..<\(head)" ) return result diff --git a/Sources/Version-Control/Services/Models/Client/GitIgnore.swift b/Sources/Version-Control/Services/Models/Client/GitIgnore.swift index 83e3103f..bc7d464c 100644 --- a/Sources/Version-Control/Services/Models/Client/GitIgnore.swift +++ b/Sources/Version-Control/Services/Models/Client/GitIgnore.swift @@ -10,7 +10,7 @@ import Foundation public struct GitIgnore { - + public init() {} /// Read the contents of the repository's root `.gitignore` file. @@ -117,7 +117,9 @@ public struct GitIgnore { /// /// - Throws: An error if there is a problem reading or updating the `.gitignore` file. /// - /// - Note: This function is intended for appending file paths to an existing `.gitignore` file. If the `.gitignore` file does not exist, you should create it first and then use this function to add file paths. + /// - Note: This function is intended for appending file paths to an existing `.gitignore` file. \ + /// If the `.gitignore` file does not exist, you should create it first and then use this + /// function to add file paths. /// /// - Example: /// ```swift @@ -126,7 +128,8 @@ public struct GitIgnore { /// try appendIgnoreFile(directoryURL: directoryURL, filePath: filePaths) /// ``` /// - /// - Important: Ensure that you have write permissions for the `.gitignore` file and that the provided directory is part of a Git repository. + /// - Important: Ensure that you have write permissions for the `.gitignore` + /// file and that the provided directory is part of a Git repository. public func appendIgnoreFile(directoryURL: URL, filePath: [String]) throws { let escapedFilePaths = filePath.map { diff --git a/Sources/Version-Control/Services/Models/Client/GitLog.swift b/Sources/Version-Control/Services/Models/Client/GitLog.swift index 74a737cf..340d3067 100644 --- a/Sources/Version-Control/Services/Models/Client/GitLog.swift +++ b/Sources/Version-Control/Services/Models/Client/GitLog.swift @@ -16,7 +16,11 @@ public enum CommitDate: String { /// Retrieve a list of Git commits from the repository's history. /// -/// This function retrieves a list of Git commits from the repository's history based on the specified parameters. You can filter commits by revision range, limit the number of commits returned, skip a certain number of commits, and include additional Git log arguments. You can also filter commits by date and exclude merge commits if needed. +/// This function retrieves a list of Git commits from the repository's history based on +/// the specified parameters. \ +/// You can filter commits by revision range, limit the number of commits returned, +/// skip a certain number of commits, and include additional Git log arguments. \ +/// You can also filter commits by date and exclude merge commits if needed. /// /// - Parameters: /// - directoryURL: The URL of the Git repository directory. @@ -46,7 +50,8 @@ public enum CommitDate: String { /// } /// ``` /// -/// - Note: The `CommitHistory` structure represents a Git commit and includes fields such as the commit hash, author, commit message, date, and more. +/// - Note: The `CommitHistory` structure represents a Git commit and includes fields such as +/// the commit hash, author, commit message, date, and more. /// /// - Important: Ensure that you have a valid Git repository in the specified directory before calling this function. public func getCommits(directoryURL: URL, diff --git a/Sources/Version-Control/Services/Models/Client/Init.swift b/Sources/Version-Control/Services/Models/Client/Init.swift index 21299d9e..ba666c56 100644 --- a/Sources/Version-Control/Services/Models/Client/Init.swift +++ b/Sources/Version-Control/Services/Models/Client/Init.swift @@ -11,7 +11,9 @@ import Foundation /// Initialize a new Git repository in the specified directory. /// -/// This function creates a new Git repository in the provided directory and configures the default branch name based on system settings. If a Git repository already exists in the specified directory, this function has no effect. +/// This function creates a new Git repository in the provided directory and configures the +/// default branch name based on system settings. \ +/// If a Git repository already exists in the specified directory, this function has no effect. /// /// - Parameters: /// - directoryURL: The URL of the directory where the Git repository should be initialized. @@ -28,9 +30,11 @@ import Foundation /// } /// ``` /// -/// - Note: If a Git repository already exists in the specified directory, this function will not reinitialize it and will have no effect. +/// - Note: If a Git repository already exists in the specified directory, +/// this function will not reinitialize it and will have no effect. /// -/// - Important: Make sure to call this function to initialize a new Git repository in a directory before performing Git operations on that directory. +/// - Important: Make sure to call this function to initialize a new Git repository +/// in a directory before performing Git operations on that directory. public func initGitRepository(directoryURL: URL) throws { try ShellClient().run( // swiftlint:disable:next line_length diff --git a/Sources/Version-Control/Services/Models/Client/LFS.swift b/Sources/Version-Control/Services/Models/Client/LFS.swift index 1f961531..38c017ea 100644 --- a/Sources/Version-Control/Services/Models/Client/LFS.swift +++ b/Sources/Version-Control/Services/Models/Client/LFS.swift @@ -10,17 +10,20 @@ import Foundation public struct LFS { - + public init() {} - + /// Install Git LFS (Large File Storage) global filters. /// - /// Git LFS is an extension for handling large files in a Git repository. This function installs Git LFS global filters, which apply to all Git repositories on the system and are configured globally. + /// Git LFS is an extension for handling large files in a Git repository. + /// This function installs Git LFS global filters, + /// which apply to all Git repositories on the system and are configured globally. /// /// - Parameters: /// - force: A flag indicating whether to force the installation of global filters if they already exist. /// - /// - Throws: An error if there was an issue installing global LFS filters or if the installation is forced and fails. + /// - Throws: An error if there was an issue installing global LFS filters + /// or if the installation is forced and fails. /// /// - Example: /// ```swift diff --git a/Sources/Version-Control/Services/Models/Client/RM.swift b/Sources/Version-Control/Services/Models/Client/RM.swift index 29d13bfe..f7ffc182 100644 --- a/Sources/Version-Control/Services/Models/Client/RM.swift +++ b/Sources/Version-Control/Services/Models/Client/RM.swift @@ -11,7 +11,9 @@ import Foundation /// Remove all files from the Git index. /// -/// This function removes all files from the Git index (staging area) in a Git repository located at the specified `directoryURL`. The files are removed from the staging area while keeping them in the working directory. +/// This function removes all files from the Git index (staging area) in a Git repository \ +/// located at the specified `directoryURL`. \ +/// The files are removed from the staging area while keeping them in the working directory. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -32,10 +34,13 @@ import Foundation /// ``` /// /// - Note: -/// This function uses the `git rm --cached -r -f .` command to remove all files from the Git index while preserving them in the working directory. +/// This function uses the `git rm --cached -r -f .` command to remove all files from the Git \ +/// index while preserving them in the working directory. /// /// - Warning: -/// Exercise caution when using this function, as it can lead to the removal of all staged changes without committing them. Make sure you understand the implications of unstaging files from the index. +/// Exercise caution when using this function, \ +/// as it can lead to the removal of all staged changes without committing them. \ +/// Make sure you understand the implications of unstaging files from the index. public func unstageAllFiles(directoryURL: URL) throws { try ShellClient().run( // these flags are important: @@ -48,7 +53,9 @@ public func unstageAllFiles(directoryURL: URL) throws { /// Remove a conflicted file from both the working tree and the Git index (staging area). /// -/// This function removes a conflicted file specified by `file` from both the working tree and the Git index (staging area) in a Git repository located at the specified `directoryURL`. The file will be deleted from the working directory, and the removal will be staged for the next commit. +/// This function removes a conflicted file specified by `file` from both the working tree and the \ +/// Git index (staging area) in a Git repository located at the specified `directoryURL`. \ +/// The file will be deleted from the working directory, and the removal will be staged for the next commit. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -71,10 +78,12 @@ public func unstageAllFiles(directoryURL: URL) throws { /// ``` /// /// - Note: -/// This function uses the `git rm` command with the `--` flag to remove the specified conflicted file from both the working directory and the Git index. +/// This function uses the `git rm` command with the `--` flag to remove the specified conflicted file \ +/// from both the working directory and the Git index. /// /// - Warning: -/// Be cautious when using this function, as it permanently deletes the conflicted file from both the working directory and the Git index. +/// Be cautious when using this function, as it permanently deletes the conflicted file \ +/// from both the working directory and the Git index. public func removeConflictedFile(directoryURL: URL, file: GitFileItem) throws { try ShellClient().run( diff --git a/Sources/Version-Control/Services/Models/Client/Refs.swift b/Sources/Version-Control/Services/Models/Client/Refs.swift index d5866ed8..a0fe35b4 100644 --- a/Sources/Version-Control/Services/Models/Client/Refs.swift +++ b/Sources/Version-Control/Services/Models/Client/Refs.swift @@ -10,7 +10,7 @@ import Foundation public struct Refs { - + public init() {} /// Format a local branch name as a Git ref syntax. diff --git a/Sources/Version-Control/Services/Models/Client/Remote.swift b/Sources/Version-Control/Services/Models/Client/Remote.swift index c79f9a22..f65ad81c 100644 --- a/Sources/Version-Control/Services/Models/Client/Remote.swift +++ b/Sources/Version-Control/Services/Models/Client/Remote.swift @@ -36,9 +36,11 @@ import Foundation /// ``` /// /// - Note: -/// - The function executes the Git command `git remote -v` to retrieve the list of Git remotes configured for the local repository. +/// - The function executes the Git command `git remote -v`\ +/// to retrieve the list of Git remotes configured for the local repository. /// -/// - Warning: Ensure that the provided `directoryURL` points to a valid local Git repository directory. Failure to do so may result in errors or incorrect results. +/// - Warning: Ensure that the provided `directoryURL` points to a valid local Git repository directory.\ +/// Failure to do so may result in errors or incorrect results. /// /// - Returns: An array of `GitRemote` objects representing the configured Git remotes for the local repository. public func getRemotes(directoryURL: URL) throws -> [GitRemote] { @@ -105,7 +107,8 @@ public func addRemote(directoryURL: URL, name: String, url: String) throws -> Gi /// Remove an existing Git remote repository by its name or silently ignore if it doesn't exist. /// -/// Use this function to remove an existing Git remote repository specified by its remote name. If the remote with the given name does not exist, the function silently ignores the operation. +/// Use this function to remove an existing Git remote repository specified by its remote name.\ +/// If the remote with the given name does not exist, the function silently ignores the operation. /// /// - Parameters: /// - directoryURL: The URL of the local Git repository. @@ -251,7 +254,6 @@ public func updateRemoteHEAD(directoryURL: URL, remote: IRemote) throws { ) } - /// Get the name of the HEAD branch in a remote Git repository. /// /// Use this function to retrieve the name of the HEAD branch in a remote Git repository associated with a specific remote name. The function constructs the reference path for the remote's HEAD and retrieves it using the `Refs` utility. diff --git a/Sources/Version-Control/Services/Models/Client/Reset.swift b/Sources/Version-Control/Services/Models/Client/Reset.swift index c74a663f..6bb655ed 100644 --- a/Sources/Version-Control/Services/Models/Client/Reset.swift +++ b/Sources/Version-Control/Services/Models/Client/Reset.swift @@ -25,7 +25,7 @@ public enum GitResetMode: Int { } public struct Reset { - + public init() {} /// Convert a Git reset mode and a reference to an array of Git command arguments. diff --git a/Sources/Version-Control/Services/Models/Client/Rev-List.swift b/Sources/Version-Control/Services/Models/Client/Rev-List.swift index da1b434f..5b72c0eb 100644 --- a/Sources/Version-Control/Services/Models/Client/Rev-List.swift +++ b/Sources/Version-Control/Services/Models/Client/Rev-List.swift @@ -29,10 +29,13 @@ import Foundation /// ``` /// /// - Note: -/// The Git range syntax is used to represent the set of commits that are reachable from the `to` reference but excludes those that are reachable from the `from` reference. It does not include the commit specified by the `from` reference. +/// The Git range syntax is used to represent the set of commits that are reachable from the `to` +/// reference but excludes those that are reachable from the `from` reference. \ +/// It does not include the commit specified by the `from` reference. /// /// - Warning: -/// Ensure that the `from` and `to` parameters represent valid references or commit SHA values to avoid syntax errors when using the resulting string in Git commands. +/// Ensure that the `from` and `to` parameters represent valid references or commit SHA values +/// to avoid syntax errors when using the resulting string in Git commands. /// /// - SeeAlso: /// [Git Range](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefrangea) @@ -64,7 +67,8 @@ private func revRange(from: String, to: String) -> String { // swiftlint:disable /// The Git inclusive range syntax is used to represent the set of commits that are reachable from the `to` reference but excludes those that are reachable from the `from` reference. It includes the commit specified by the `from` reference. /// /// - Warning: -/// Ensure that the `from` and `to` parameters represent valid references or commit SHA values to avoid syntax errors when using the resulting string in Git commands. +/// Ensure that the `from` and `to` parameters represent valid references or commit SHA values +/// to avoid syntax errors when using the resulting string in Git commands. /// /// - SeeAlso: /// [Git Inclusive Range](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefinclusiverangea) @@ -96,7 +100,8 @@ private func revRangeInclusive(from: String, to: String) -> String { // swiftlin /// The Git symmetric difference syntax is used to represent the set of commits that are reachable from either the `from` reference or the `to` reference but not from both. It is commonly used in Git operations such as comparing branches or finding the differences between two references. /// /// - Warning: -/// Ensure that the `from` and `to` parameters represent valid references or commit SHA values to avoid syntax errors when using the resulting string in Git commands. +/// Ensure that the `from` and `to` parameters represent valid references or commit SHA values to +/// avoid syntax errors when using the resulting string in Git commands. /// /// - SeeAlso: /// [Git Symmetric Difference](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefsymmetricdiffa) @@ -114,7 +119,8 @@ private func revSymmetricDifference(from: String, to: String) -> String { // swi /// /// - Returns: /// - An `AheadBehind` object representing the number of commits ahead and behind in the specified commit range. -/// - `nil` if the commit range is invalid, one of the references does not exist, or an error occurs during the calculation. +/// - `nil` if the commit range is invalid, one of the references does not exist, \ +/// or an error occurs during the calculation. /// /// - Throws: /// - An error of type `Error` if any issues occur during the calculation process. @@ -137,10 +143,13 @@ private func revSymmetricDifference(from: String, to: String) -> String { // swi /// ``` /// /// - Note: -/// This function uses the `git rev-list` command with the `--left-right` and `--count` options to calculate the number of commits ahead of and behind a specified commit range. The result is returned as an `AheadBehind` object. +/// This function uses the `git rev-list` command with the `--left-right` and `--count` options +/// to calculate the number of commits ahead of and behind a specified commit range. \ +/// The result is returned as an `AheadBehind` object. /// /// - Warning: -/// Be cautious when using this function, as an invalid commit range or non-existent references may result in errors, and it assumes that the Git executable is available and accessible in the system's PATH. +/// Be cautious when using this function, as an invalid commit range or non-existent references +/// may result in errors, and it assumes that the Git executable is available and accessible in the system's PATH. public func getAheadBehind(directoryURL: URL, range: String) throws -> IAheadBehind? { // `--left-right` annotates the list of commits in the range with which side @@ -185,7 +194,8 @@ public func getAheadBehind(directoryURL: URL, /// - directoryURL: The URL of the Git repository directory. /// - branch: The local branch for which you want to determine the ahead and behind commits. /// -/// - Returns: An `IAheadBehind` object that encapsulates the number of commits ahead and behind the upstream branch. If the branch type is remote or no upstream branch is set, `nil` is returned. +/// - Returns: An `IAheadBehind` object that encapsulates the number of commits ahead and behind the upstream branch. \ +/// If the branch type is remote or no upstream branch is set, `nil` is returned. /// /// - Example: /// ```swift @@ -194,7 +204,8 @@ public func getAheadBehind(directoryURL: URL, /// /// do { /// if let aheadBehind = try getBranchAheadBehind(directoryURL: repositoryDirectory, branch: branch) { -/// print("Branch is \(aheadBehind.ahead) commits ahead and \(aheadBehind.behind) commits behind its upstream branch.") +/// print("Branch is \(aheadBehind.ahead) commits ahead and \(aheadBehind.behind) +/// commits behind its upstream branch.") /// } else { /// print("No upstream branch set or branch type is remote.") /// } @@ -204,12 +215,15 @@ public func getAheadBehind(directoryURL: URL, /// ``` /// /// - Note: -/// This function is useful for tracking the differences between a local branch and its upstream branch. It calculates the commits that have been added or removed from the local branch compared to its upstream branch. +/// This function is useful for tracking the differences between a local branch and its upstream branch. \ +/// It calculates the commits that have been added or removed from the local branch compared to its upstream branch. /// /// - Warning: -/// Ensure that the branch provided as a parameter is a valid local branch, and it has an upstream branch set. Otherwise, the function will return `nil`. +/// Ensure that the branch provided as a parameter is a valid local branch, and it has an upstream branch set. \ +/// Otherwise, the function will return `nil`. /// -/// - Returns: An `IAheadBehind` object representing the number of commits ahead and behind the upstream branch, or `nil` if the branch type is remote or no upstream branch is set. +/// - Returns: An `IAheadBehind` object representing the number of commits ahead and behind the upstream branch, \ +/// or `nil` if the branch type is remote or no upstream branch is set. func getBranchAheadBehind(directoryURL: URL, branch: GitBranch) async throws -> IAheadBehind? { if branch.type == .remote { @@ -229,7 +243,10 @@ func getBranchAheadBehind(directoryURL: URL, /// Retrieve a list of commits between two specified commit references in a Git repository. /// -/// This function retrieves a list of commits between the specified `baseBranchSha` and `targetBranchSha` in a Git repository located at the specified `directoryURL`. The commits are ordered in the sequence they will be applied to the `baseBranchSha`, emulating the behavior of `git rebase`. +/// This function retrieves a list of commits between the specified `baseBranchSha` and `targetBranchSha` \ +/// in a Git repository located at the specified `directoryURL`. +/// The commits are ordered in the sequence they will be applied to the `baseBranchSha`, \ +/// emulating the behavior of `git rebase`. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -237,8 +254,10 @@ func getBranchAheadBehind(directoryURL: URL, /// - targetBranchSha: The commit SHA of the target branch, representing the ending point (not included). /// /// - Returns: -/// - An array of `CommitOneLine` objects representing commits between the `baseBranchSha` (inclusive) and `targetBranchSha` (exclusive). Each `CommitOneLine` object contains a commit SHA and a commit summary. -/// - `nil` if the rebase is not possible to perform due to a missing commit ID or if an error occurs during the retrieval. +/// - An array of `CommitOneLine` objects representing commits between the `baseBranchSha` (inclusive) \ +/// and `targetBranchSha` (exclusive). Each `CommitOneLine` object contains a commit SHA and a commit summary. +/// - `nil` if the rebase is not possible to perform due to a missing commit ID or \ +/// if an error occurs during the retrieval. /// /// - Throws: /// - An error of type `Error` if any issues occur during the retrieval process. @@ -250,7 +269,11 @@ func getBranchAheadBehind(directoryURL: URL, /// let targetBranchCommitSHA = "7890abcd5678" // Replace with the SHA of the target branch commit /// /// do { -/// if let commits = try getCommitsBetweenCommits(directoryURL: repositoryPath, baseBranchSha: baseBranchCommitSHA, targetBranchSha: targetBranchCommitSHA) { +/// if let commits = try getCommitsBetweenCommits( +/// directoryURL: repositoryPath, +/// baseBranchSha: baseBranchCommitSHA, +/// targetBranchSha: targetBranchCommitSHA +/// ) { /// for commit in commits { /// print("Commit SHA: \(commit.sha)") /// print("Commit Summary: \(commit.summary)") @@ -277,7 +300,8 @@ public func getCommitsBetweenCommits(directoryURL: URL, /// Retrieve a list of commits within the specified commit range in a Git repository. /// -/// This function retrieves a list of commits within the specified `range` in a Git repository located at the specified `directoryURL`. +/// This function retrieves a list of commits within the specified `range` in a Git repository \ +/// located at the specified `directoryURL`. /// The `range` parameter should represent a commit range, such as a branch or commit range expression. /// /// - Parameters: @@ -285,7 +309,8 @@ public func getCommitsBetweenCommits(directoryURL: URL, /// - range: The commit range expression used to filter commits. /// /// - Returns: -/// - An array of `CommitOneLine` objects representing commits within the specified range. Each `CommitOneLine` object contains a commit SHA and a commit summary. +/// - An array of `CommitOneLine` objects representing commits within the specified range. \ +/// Each `CommitOneLine` object contains a commit SHA and a commit summary. /// - `nil` if the specified `range` is invalid or if an error occurs during the retrieval. /// /// - Throws: @@ -312,10 +337,12 @@ public func getCommitsBetweenCommits(directoryURL: URL, /// /// - Note: /// This function uses the `git rev-list` command to retrieve a list of commits within the specified range. -/// The commits are represented as `CommitOneLine` objects, where each object contains a commit SHA and a commit summary. +/// The commits are represented as `CommitOneLine` objects, \ +/// where each object contains a commit SHA and a commit summary. /// /// - Warning: -/// Be cautious when using this function, as invalid commit range expressions may result in errors, and it assumes that the Git executable +/// Be cautious when using this function, as invalid commit range expressions may result in errors, \ +/// and it assumes that the Git executable \ /// is available and accessible in the system's PATH. public func getCommitsInRange(directoryURL: URL, range: String) throws -> [CommitOneLine]? { diff --git a/Sources/Version-Control/Services/Models/Client/Rev-Parse.swift b/Sources/Version-Control/Services/Models/Client/Rev-Parse.swift index 88867c62..3890035c 100644 --- a/Sources/Version-Control/Services/Models/Client/Rev-Parse.swift +++ b/Sources/Version-Control/Services/Models/Client/Rev-Parse.swift @@ -17,7 +17,8 @@ public enum RepositoryType { /// Determine the type of a Git repository at the specified `path`. /// -/// This function attempts to identify the type of a Git repository located at the specified `path`. It can determine whether the repository is a bare repository, a regular repository, or if it couldn't be found. +/// This function attempts to identify the type of a Git repository located at the specified `path`. \ +/// It can determine whether the repository is a bare repository, a regular repository, or if it couldn't be found. /// /// - Parameters: /// - path: The path to the directory where the Git repository is located. @@ -44,7 +45,9 @@ public enum RepositoryType { /// ``` /// /// - Note: -/// This function uses the `git rev-parse --is-bare-repository` command to determine if the repository is bare or regular. It also checks for certain error messages to identify unsafe or missing repositories. +/// This function uses the `git rev-parse --is-bare-repository` command to determine \ +/// if the repository is bare or regular. \ +/// It also checks for certain error messages to identify unsafe or missing repositories. /// /// - Warning: /// This function assumes that the Git executable is available and accessible in the system's PATH. diff --git a/Sources/Version-Control/Services/Models/Client/Stash.swift b/Sources/Version-Control/Services/Models/Client/Stash.swift index 9e78315a..24e76285 100644 --- a/Sources/Version-Control/Services/Models/Client/Stash.swift +++ b/Sources/Version-Control/Services/Models/Client/Stash.swift @@ -10,7 +10,7 @@ import Foundation public struct Stash { - + public init() {} private let editorStashEntryMarker = "!!AuroraEditor" diff --git a/Sources/Version-Control/Services/Models/Client/Tag.swift b/Sources/Version-Control/Services/Models/Client/Tag.swift index 9c8d1a12..471dfc8c 100644 --- a/Sources/Version-Control/Services/Models/Client/Tag.swift +++ b/Sources/Version-Control/Services/Models/Client/Tag.swift @@ -10,12 +10,14 @@ import Foundation public struct Tag { - + public init() {} - + /// Create a Git tag in a repository. /// - /// This function creates a Git tag with the specified `name` in a Git repository located at the specified `directoryURL`. The tag is associated with a target commit identified by its SHA (`targetCommitSha`). + /// This function creates a Git tag with the specified `name` in a Git repository located \ + /// at the specified `directoryURL`. \ + /// The tag is associated with a target commit identified by its SHA (`targetCommitSha`). /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -40,10 +42,13 @@ public struct Tag { /// ``` /// /// - Note: - /// This function uses the `git tag -a` command to create an annotated Git tag with the specified `name` and associates it with the target commit identified by `targetCommitSha`. The tag message is intentionally left empty. + /// This function uses the `git tag -a` command to create an annotated Git tag with \ + /// the specified `name` and associates it with the target commit identified by \ + /// `targetCommitSha`. The tag message is intentionally left empty. /// /// - Warning: - /// Be cautious when creating tags, especially annotated tags, as they can affect the history and versioning of a Git repository. + /// Be cautious when creating tags, especially annotated tags, \ + /// as they can affect the history and versioning of a Git repository. public func createTag(directoryURL: URL, name: String, targetCommitSha: String) throws { @@ -55,16 +60,16 @@ public struct Tag { name, targetCommitSha ] - + try ShellClient().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git \(args.joined(separator: " "))" ) } - /// Delete a Git tag from a repository. /// - /// This function deletes a Git tag with the specified `name` from a Git repository located at the specified `directoryURL`. + /// This function deletes a Git tag with the specified `name` from a Git repository located at \ + /// the specified `directoryURL`. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -96,7 +101,9 @@ public struct Tag { /// Retrieve a dictionary of all Git tags in a repository. /// - /// This asynchronous function retrieves a dictionary containing all Git tags in a Git repository located at the specified `directoryURL`. The dictionary maps tag names (strings) to their corresponding commit SHAs (strings). + /// This asynchronous function retrieves a dictionary containing all Git tags in a Git repository \ + /// located at the specified `directoryURL`. \ + /// The dictionary maps tag names (strings) to their corresponding commit SHAs (strings). /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -127,13 +134,16 @@ public struct Tag { /// ``` /// /// - Note: - /// This function uses the `git show-ref` command to retrieve a list of all Git tags and their associated commit SHAs. It normalizes tag names by removing the leading "refs/tags/" and trailing "^{}" from annotated tags. + /// This function uses the `git show-ref` command to retrieve a list of all Git tags and \ + /// their associated commit SHAs. \ + /// It normalizes tag names by removing the leading "refs/tags/" and trailing "^{}" from annotated tags. /// /// - Important: - /// This function is asynchronous and must be called from within an asynchronous context (e.g., an `async` function). + /// This function is asynchronous and must be called from within an asynchronous context \ + /// (e.g., an `async` function). func getAllTags(directoryURL: URL) async throws -> [String: String]? { var tags = [String: String]() - + let result = try ShellClient.live().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git show-ref --tags -d" ) @@ -170,7 +180,9 @@ public struct Tag { /// Fetch tags to be pushed to a remote Git repository. /// - /// This function fetches the tags that are pending to be pushed to a remote Git repository specified by `remote`. It performs a dry run of the push operation to identify unpushed tags. The tags are then extracted from the Git command result. + /// This function fetches the tags that are pending to be pushed to a remote Git repository specified by `remote`. \ + /// It performs a dry run of the push operation to identify unpushed tags. \ + /// The tags are then extracted from the Git command result. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -186,7 +198,10 @@ public struct Tag { /// - Example: /// ```swift /// let directoryURL = URL(fileURLWithPath: "/path/to/repo") // Replace with the path to the Git repository - /// let remote = GitRemote(name: "origin", url: "https://github.com/user/repo.git") // Replace with your Git remote details + /// let remote = GitRemote( + /// name: "origin", + /// url: "https://github.com/user/repo.git" + /// ) // Replace with your Git remote details /// let branchName = "main" // Replace with the name of the branch associated with the push operation /// /// do { @@ -202,7 +217,8 @@ public struct Tag { /// ``` /// /// - Note: - /// This function performs a dry run of the push operation and parses the Git command result to identify unpushed tags. It removes the "refs/tags/" prefix from the tag names. + /// This function performs a dry run of the push operation and parses the Git command \ + /// result to identify unpushed tags. It removes the "refs/tags/" prefix from the tag names. public func fetchTagsToPush(directoryURL: URL, remote: GitRemote, branchName: String) throws -> [String] { diff --git a/Sources/Version-Control/Services/Models/Client/Update-Index.swift b/Sources/Version-Control/Services/Models/Client/Update-Index.swift index de8e462a..a7f97c19 100644 --- a/Sources/Version-Control/Services/Models/Client/Update-Index.swift +++ b/Sources/Version-Control/Services/Models/Client/Update-Index.swift @@ -70,7 +70,8 @@ public class UpdateIndexOptions: IUpdateIndexOptions { /// - Parameters: /// - directoryURL: The local directory URL of the Git repository. /// - paths: An array of file paths to update in the Git index. -/// - options: An optional `UpdateIndexOptions` object that allows you to specify additional options for the `update-index` Git command. +/// - options: An optional `UpdateIndexOptions` object that allows you to specify additional options\ +/// for the `update-index` Git command. /// /// - Throws: An error if there's an issue with executing the Git command or if the specified paths are invalid. /// diff --git a/Sources/Version-Control/Services/Models/Client/Update-Ref.swift b/Sources/Version-Control/Services/Models/Client/Update-Ref.swift index 94538085..c36f04cd 100644 --- a/Sources/Version-Control/Services/Models/Client/Update-Ref.swift +++ b/Sources/Version-Control/Services/Models/Client/Update-Ref.swift @@ -10,12 +10,14 @@ import Foundation public struct UpdateRef { - + public init() {} - + /// Update a Git reference (branch or tag) in a local Git repository. /// - /// This function updates the specified Git reference (branch or tag) in the local Git repository with a new value. You must provide the old and new values of the reference and a reason or commit message for the update. + /// This function updates the specified Git reference (branch or tag) \ + /// in the local Git repository with a new value. \ + /// You must provide the old and new values of the reference and a reason or commit message for the update. /// /// - Parameters: /// - directoryURL: The local directory URL of the Git repository. @@ -24,7 +26,8 @@ public struct UpdateRef { /// - newValue: The new value to set for the reference. /// - reason: A reason or commit message for the update. /// - /// - Throws: An error if there's an issue with executing the Git command or if the specified reference doesn't exist. + /// - Throws: An error if there's an issue with executing the Git command or \ + /// if the specified reference doesn't exist. /// /// - Example: /// ```swift @@ -34,7 +37,13 @@ public struct UpdateRef { /// let oldValue = "abc123" /// let newValue = "def456" /// let updateReason = "Updated feature branch" - /// try updateRef(directoryURL: directoryURL, ref: referenceToUpdate, oldValue: oldValue, newValue: newValue, reason: updateReason) + /// try updateRef( + /// directoryURL: directoryURL, + /// ref: referenceToUpdate, + /// oldValue: oldValue, + /// newValue: newValue, + /// reason: updateReason + /// ) /// } catch { /// print("Error: Unable to update the Git reference.") /// } @@ -50,14 +59,16 @@ public struct UpdateRef { /// Delete a Git reference (branch or tag) in a local Git repository. /// - /// This function deletes the specified Git reference (branch or tag) in the local Git repository. You can optionally provide a reason or commit message for the deletion. + /// This function deletes the specified Git reference (branch or tag) in the local Git repository. \ + /// You can optionally provide a reason or commit message for the deletion. /// /// - Parameters: /// - directoryURL: The local directory URL of the Git repository. /// - ref: The name of the reference (branch or tag) to be deleted. /// - reason: An optional reason or commit message for the deletion. /// - /// - Throws: An error if there's an issue with executing the Git command or if the specified reference doesn't exist. + /// - Throws: An error if there's an issue with executing the Git command or \ + /// if the specified reference doesn't exist. /// /// - Example: /// ```swift diff --git a/Sources/Version-Control/Services/Models/CommitIdentity.swift b/Sources/Version-Control/Services/Models/CommitIdentity.swift index d2da45f8..7801b8fd 100644 --- a/Sources/Version-Control/Services/Models/CommitIdentity.swift +++ b/Sources/Version-Control/Services/Models/CommitIdentity.swift @@ -42,9 +42,13 @@ struct CommitIdentity { // Note also that this expects a date formatted with the RAW option in git see: // https://github.com/git/git/blob/35f6318d4/date.c#L191 let pattern = #"^(.*?) <(.*?)> (\d+) (\+|-)?(\d{2})(\d{2})"# - + if let regex = try? NSRegularExpression(pattern: pattern, options: []) { - if let match = regex.firstMatch(in: identity, options: [], range: NSRange(location: 0, length: identity.utf16.count)) { + if let match = regex.firstMatch( + in: identity, + options: [], + range: NSRange(location: 0, length: identity.utf16.count) + ) { let name = (identity as NSString).substring(with: match.range(at: 1)) let email = (identity as NSString).substring(with: match.range(at: 2)) let timestamp = TimeInterval((identity as NSString).substring(with: match.range(at: 3))) ?? 0 @@ -59,7 +63,7 @@ struct CommitIdentity { if let tzHours = Int(tzHH), let tzMinutes = Int(tzmm) { let tzOffset = tzSign * (tzHours * 60 + tzMinutes) - + return CommitIdentity(name: name, email: email, date: date, tzOffset: tzOffset) } } diff --git a/Sources/Version-Control/Services/Models/GitBranch.swift b/Sources/Version-Control/Services/Models/GitBranch.swift index c7547477..9dd9b03c 100644 --- a/Sources/Version-Control/Services/Models/GitBranch.swift +++ b/Sources/Version-Control/Services/Models/GitBranch.swift @@ -12,7 +12,7 @@ import Foundation public struct IAheadBehind { /// The number of commits ahead of the revision range. let ahead: Int - + /// The number of commits behind the revision range. let behind: Int } @@ -21,10 +21,10 @@ public struct IAheadBehind { struct ICompareResult { /// The number of commits ahead of the reference being compared to. let ahead: Int - + /// The number of commits behind the reference being compared to. let behind: Int - + /// An array of `Commit` objects representing individual commits involved in the comparison. let commits: [Commit] } @@ -33,13 +33,13 @@ struct ICompareResult { struct ITrackingBranch { /// The reference (name) of the branch. let ref: String - + /// The SHA (hash) of the branch. let sha: String - + /// The reference (name) of the upstream branch it's tracking. let upstreamRef: String - + /// The SHA (hash) of the upstream branch. let upstreamSha: String } @@ -48,7 +48,7 @@ struct ITrackingBranch { struct IBranchTip { /// The SHA (hash) of the latest commit. let sha: String - + /// Information about the author of the latest commit. let author: CommitIdentity } @@ -57,23 +57,22 @@ struct IBranchTip { enum StartPoint: String { /// Create the branch from the current branch. case currentBranch = "CurrentBranch" - + /// Create the branch from the default branch. case defaultBranch = "DefaultBranch" - + /// Create the branch from the HEAD. case head = "Head" - + /// Create the branch from the upstream default branch. case upstreamDefaultBranch = "UpstreamDefaultBranch" } - /// Enum to represent the type of a Git branch. enum BranchType: Int { /// Represents a local branch. case local = 0 - + /// Represents a remote branch. case remote = 1 } @@ -84,7 +83,7 @@ public struct GitBranch { let tip: IBranchTip let type: BranchType let ref: String - + /** * A branch as loaded from Git. * @@ -105,27 +104,27 @@ public struct GitBranch { self.type = type self.ref = ref } - + /** The name of the upstream's remote. */ var upstreamRemoteName: String? { guard let upstream = self.upstream else { return nil } - + let pieces = upstream.split(separator: "/") if pieces.count >= 2 { return String(pieces[0]) } - + return nil } - + /** The name of remote for a remote branch. If local, will return null. */ var remoteName: String? { if self.type == .local { return nil } - + let pieces = self.ref.split(separator: "/") if pieces.count == 4 && pieces[0] == "refs" && pieces[1] == "remotes" { return String(pieces[2]) @@ -135,7 +134,7 @@ public struct GitBranch { fatalError("Remote branch ref has unexpected format: \(self.ref)") } } - + /** * The name of the branch's upstream without the remote prefix. */ @@ -143,10 +142,10 @@ public struct GitBranch { if let upstream = self.upstream { return removeRemotePrefix(name: upstream) } - + return nil } - + /** * The name of the branch without the remote prefix. If the branch is a local * branch, this is the same as its `name`. @@ -159,7 +158,7 @@ public struct GitBranch { return withoutRemote ?? self.name } } - + /** * Gets a value indicating whether the branch is a remote branch belonging to * one of Desktop's automatically created (and pruned) fork remotes. I.e. a @@ -174,4 +173,3 @@ public struct GitBranch { return self.type == .remote && self.name.hasPrefix("auroraeditor-") } } - diff --git a/Sources/Version-Control/Utils/Extensions/Date.swift b/Sources/Version-Control/Utils/Extensions/Date.swift index b14dd24b..409f8b79 100644 --- a/Sources/Version-Control/Utils/Extensions/Date.swift +++ b/Sources/Version-Control/Utils/Extensions/Date.swift @@ -21,7 +21,7 @@ public extension Date { dateFormatter.dateFormat = "E MMM dd HH:mm:ss yyyy Z" return dateFormatter.date(from: commitDate) } - + func toGitHubIsoDateString(_ date: Date) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" diff --git a/Sources/Version-Control/Utils/Extensions/String.swift b/Sources/Version-Control/Utils/Extensions/String.swift index ab220241..3ed8b371 100644 --- a/Sources/Version-Control/Utils/Extensions/String.swift +++ b/Sources/Version-Control/Utils/Extensions/String.swift @@ -48,7 +48,7 @@ extension String { return [] } } - + func urlEncode(_ parameters: [String: Any]) -> String? { var components = URLComponents() components.queryItems = parameters.map { key, value in @@ -56,22 +56,22 @@ extension String { } return components.percentEncodedQuery } - + func urlEncode() -> String? { return self.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) } - + func stdout() throws -> String { let process = Process() process.executableURL = URL(fileURLWithPath: "/bin/bash") process.arguments = ["-c", self] - + let stdoutPipe = Pipe() process.standardOutput = stdoutPipe - + try process.run() process.waitUntilExit() - + let stdoutData = stdoutPipe.fileHandleForReading.readDataToEndOfFile() if let stdoutString = String(data: stdoutData, encoding: .utf8) { return stdoutString diff --git a/Sources/Version-Control/Utils/Helpers/RemoveRemotePrefix.swift b/Sources/Version-Control/Utils/Helpers/RemoveRemotePrefix.swift index 323b0c5a..82852ddb 100644 --- a/Sources/Version-Control/Utils/Helpers/RemoveRemotePrefix.swift +++ b/Sources/Version-Control/Utils/Helpers/RemoveRemotePrefix.swift @@ -9,7 +9,9 @@ import Foundation /// Remove the remote prefix from a branch name. /// -/// If a branch name includes a remote prefix, this function extracts the branch name itself by removing the remote prefix. If no prefix is found, it returns `nil`. +/// If a branch name includes a remote prefix, \ +/// this function extracts the branch name itself by removing the remote prefix. \ +/// If no prefix is found, it returns `nil`. /// /// - Parameter name: The branch name that may include a remote prefix. /// @@ -27,7 +29,8 @@ import Foundation /// ``` /// /// - Note: -/// The remote prefix typically includes the name of the remote repository and a forward slash (`/`). This function is useful for extracting the local branch name from a branch name that includes the remote prefix. +/// The remote prefix typically includes the name of the remote repository and a forward slash (`/`). \ +/// This function is useful for extracting the local branch name from a branch name that includes the remote prefix. /// /// - Warning: /// Ensure that the input `name` is a valid branch name or includes a remote prefix to avoid unexpected results. @@ -35,7 +38,7 @@ import Foundation /// - Returns: The extracted branch name or `nil` if no remote prefix is present in the input name. func removeRemotePrefix(name: String) -> String? { let regexPattern = #".*?/(.*)"# - + if let regex = try? NSRegularExpression(pattern: regexPattern, options: []) { if let match = regex.firstMatch(in: name, options: [], range: NSRange(location: 0, length: name.utf16.count)) { let remoteBranch = (name as NSString).substring(with: match.range(at: 1)) diff --git a/Sources/Version-Control/Utils/ShellClient.swift b/Sources/Version-Control/Utils/ShellClient.swift index a313bd2d..c9c5cdeb 100644 --- a/Sources/Version-Control/Utils/ShellClient.swift +++ b/Sources/Version-Control/Utils/ShellClient.swift @@ -12,15 +12,15 @@ public class ShellClient { func generateProcessAndPipe(_ args: [String]) -> (Process, Pipe) { let task = Process() let pipe = Pipe() - + task.standardOutput = pipe task.standardError = pipe task.arguments = ["-c"] + args task.executableURL = URL(fileURLWithPath: "/bin/zsh") - + return (task, pipe) } - + /// Generate a process and pipe to run commands /// - Parameters: /// - commandPath: The path to the command to run (e.g., "/usr/bin/git") @@ -31,16 +31,16 @@ public class ShellClient { workingDirectory: String?) -> (Process, Pipe) { let task = Process() let pipe = Pipe() - + task.standardOutput = pipe task.standardError = pipe task.arguments = ["-c"] + arguments task.executableURL = URL(fileURLWithPath: "/bin/zsh") - + if let workingDirectory = workingDirectory { task.currentDirectoryPath = workingDirectory } - + return (task, pipe) } @@ -105,7 +105,6 @@ public class ShellClient { } } - /// Run a command with Publisher /// - Parameter args: command to run /// - Returns: command output @@ -114,9 +113,9 @@ public class ShellClient { let subject = PassthroughSubject() let (task, pipe) = generateProcessAndPipe(args) let outputHandler = pipe.fileHandleForReading - + outputHandler.waitForDataInBackgroundAndNotify() - + let id = UUID() self.cancellables[id] = NotificationCenter .default @@ -137,12 +136,12 @@ public class ShellClient { } outputHandler.waitForDataInBackgroundAndNotify() // Wait for more data } - + task.launch() // Start the task - + return subject.eraseToAnyPublisher() } - + func run(arguments: [String], workingDirectory: String) throws -> (stdout: String, stderr: String) { let process = Process() From 8576b11509ac50af676df260c9fba24943075a7f Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Sun, 8 Oct 2023 12:09:53 +0100 Subject: [PATCH 2/4] Swiftlint fixes --- .../Services/Models/Client/Config.swift | 66 +++++++++++++------ .../Services/Models/Client/Description.swift | 16 +++-- .../Services/Models/Client/Diff-Index.swift | 6 +- .../Services/Models/Client/Rev-List.swift | 35 +++++++--- .../Services/Models/Diff/Diff-Data.swift | 2 - .../Services/Models/Diff/Diff-Selection.swift | 1 - 6 files changed, 86 insertions(+), 40 deletions(-) diff --git a/Sources/Version-Control/Services/Models/Client/Config.swift b/Sources/Version-Control/Services/Models/Client/Config.swift index b45ad2df..7e4b92c4 100644 --- a/Sources/Version-Control/Services/Models/Client/Config.swift +++ b/Sources/Version-Control/Services/Models/Client/Config.swift @@ -49,7 +49,8 @@ public struct Config { /// ``` /// /// - Note: - /// This function retrieves a Git configuration value within a specific repository context by reading the repository's path and then using the `getConfigValueInPath` function with the provided path. + /// This function retrieves a Git configuration value within a specific repository context + /// by reading the repository's path and then using the `getConfigValueInPath` function with the provided path. public func getConfigValue(directoryURL: URL, name: String, onlyLocal: Bool = false) throws -> String? { @@ -71,7 +72,8 @@ public struct Config { /// - An error of type `Error` if any issues occur during the configuration value lookup process. /// /// - Returns: - /// The string value associated with the specified Git configuration key, or `nil` if the configuration key is not found. + /// The string value associated with the specified Git configuration key, + /// or `nil` if the configuration key is not found. /// /// - Example: /// ```swift @@ -100,7 +102,9 @@ public struct Config { /// Look up a global Git configuration value by name and interpret it as a boolean. /// - /// This function retrieves a Git configuration value from the global Git configuration file based on the provided `name` and interprets it as a boolean value according to Git's definition of boolean configuration values (e.g., "0" -> `false`, "off" -> `false`, "yes" -> `true`, etc.). + /// This function retrieves a Git configuration value from the global Git configuration file + /// based on the provided `name` and interprets it as a boolean value according to Git's definition of + /// boolean configuration values (e.g., "0" -> `false`, "off" -> `false`, "yes" -> `true`, etc.). /// /// - Parameters: /// - name: The name of the Git configuration key to look up. @@ -109,7 +113,8 @@ public struct Config { /// - An error of type `Error` if any issues occur during the configuration value lookup process. /// /// - Returns: - /// A `Bool` representing the interpreted boolean value of the Git configuration, or `nil` if the configuration key is not found or its value cannot be interpreted as a boolean. + /// A `Bool` representing the interpreted boolean value of the Git configuration, + /// or `nil` if the configuration key is not found or its value cannot be interpreted as a boolean. /// /// - Example: /// ```swift @@ -127,7 +132,8 @@ public struct Config { /// ``` /// /// - Note: - /// This function retrieves and interprets a global Git configuration value as a boolean by using the `getConfigValueInPath` function with appropriate parameters. + /// This function retrieves and interprets a global Git configuration value as a boolean by + /// using the `getConfigValueInPath` function with appropriate parameters. public func getGlobalBooleanConfigValue(name: String) throws -> Bool? { let value = try getConfigValueInPath(name: name, path: nil, @@ -140,9 +146,13 @@ public struct Config { /// /// - Parameters: /// - name: The name of the Git configuration value to retrieve. - /// - path: The optional path specifying the context (local repository directory) in which to retrieve the configuration value. If `nil`, the configuration value is retrieved globally. - /// - onlyLocal: A Boolean flag indicating whether to retrieve the configuration value only from the local repository configuration (default is `false`). If `true`, the global configuration is not considered. - /// - type: An optional type to specify the expected type of the configuration value (e.g., "string", "int", "bool"). If `nil`, no type filtering is applied. + /// - path: The optional path specifying the context (local repository directory) in which to \ + /// retrieve the configuration value. If `nil`, the configuration value is retrieved globally. + /// - onlyLocal: A Boolean flag indicating whether to retrieve the configuration value only from \ + /// the local repository configuration (default is `false`). If `true`, \ + /// the global configuration is not considered. + /// - type: An optional type to specify the expected type of the configuration value \ + /// (e.g., "string", "int", "bool"). If `nil`, no type filtering is applied. /// /// - Throws: /// - An error of type `Error` if any issues occur during the configuration value retrieval process. @@ -227,7 +237,8 @@ public struct Config { /// ``` /// /// - Note: - /// This function retrieves the path to the global Git configuration file by parsing the output of the `git config` command. + /// This function retrieves the path to the global Git configuration file by parsing the + /// output of the `git config` command. public func getGlobalConfig() throws -> String? { let result = try ShellClient.live().run( "git config --global --list --show-origin --name-only -z" @@ -280,7 +291,8 @@ public struct Config { /// ``` /// /// - Note: - /// This function sets a Git configuration value within a specific repository context by reading the repository's path and then using the `setConfigValueInPath` function with the provided path. + /// This function sets a Git configuration value within a specific repository context by + /// reading the repository's path and then using the `setConfigValueInPath` function with the provided path. public func setConfigValue(directoryURL: URL, name: String, value: String) throws { @@ -291,7 +303,8 @@ public struct Config { /// Sets a global Git configuration value by name. /// - /// This function sets a Git configuration value in the global context. It updates the global Git configuration file with the specified key-value pair. + /// This function sets a Git configuration value in the global context. \ + /// It updates the global Git configuration file with the specified key-value pair. /// /// - Parameters: /// - name: The name of the Git configuration key to set. @@ -317,13 +330,15 @@ public struct Config { /// ``` /// /// - Note: - /// This function sets a Git configuration value in the global context using the `setConfigValueInPath` function with `path` set to `nil`. + /// This function sets a Git configuration value in the global context using the + /// `setConfigValueInPath` function with `path` set to `nil`. /// /// - SeeAlso: /// - `setConfigValueInPath(name:value:path:)` /// /// - Warning: - /// Changing global Git configuration values can affect the behavior of Git commands and may impact all repositories on the system. + /// Changing global Git configuration values can affect the behavior of Git commands and may + /// impact all repositories on the system. public func setGlobalConfigValue(name: String, value: String) throws -> String { return try setConfigValueInPath(name: name, @@ -354,7 +369,8 @@ public struct Config { /// ``` /// /// - Note: - /// This function adds a Git configuration value to the global Git configuration file using the `git config` command with the `--global --add` flags. + /// This function adds a Git configuration value to the global Git configuration file using the + /// `git config` command with the `--global --add` flags. public func addGlobalConfigValue(name: String, value: String) throws { try ShellClient().run( @@ -373,7 +389,8 @@ public struct Config { /// - An error of type `Error` if any issues occur during the configuration addition process. /// /// - Note: - /// If the specified `path` is not already present in the `safe.directories` configuration, it is added using the `addGlobalConfigValueIfMissing` function. + /// If the specified `path` is not already present in the `safe.directories` configuration, + /// it is added using the `addGlobalConfigValueIfMissing` function. /// /// - SeeAlso: /// - `addGlobalConfigValueIfMissing(name:value:)` @@ -391,7 +408,8 @@ public struct Config { /// ``` /// /// - Warning: - /// Adding a path to `safe.directories` may affect Git's behavior with regard to ownership differences within the specified directory. + /// Adding a path to `safe.directories` may affect Git's behavior with regard to ownership + /// differences within the specified directory. public func addSafeDirectory(path: String) throws { try addGlobalConfigValueIfMissing(name: "safe.directory", value: path) @@ -440,7 +458,8 @@ public struct Config { /// - Parameters: /// - name: The name of the Git configuration value to set. /// - value: The value to set for the Git configuration. - /// - path: The optional path specifying the context (local repository directory) in which to set the configuration value. If `nil`, the configuration value is set globally. + /// - path: The optional path specifying the context (local repository directory) \ + /// in which to set the configuration value. If `nil`, the configuration value is set globally. /// /// - Throws: /// - An error of type `Error` if any issues occur during the configuration value setting process. @@ -543,16 +562,20 @@ public struct Config { /// ``` /// /// - Note: - /// This function removes a Git configuration value from the global Git configuration file using the `removeConfigValueInPath` function with `path` set to `nil`. + /// This function removes a Git configuration value from the global Git configuration file + /// using the `removeConfigValueInPath` function with `path` set to `nil`. public func removeGlobalConfigValue(name: String) throws { try removeConfigValueInPath(name: name, path: nil) } - /// Removes all occurrences of a Git configuration value with a specified name within a given context (global or local). + /// Removes all occurrences of a Git configuration value with a specified name within a given context + /// (global or local). /// /// - Parameters: /// - name: The name of the Git configuration value to remove. - /// - path: The optional path specifying the context (local repository directory) in which to remove the configuration value. If `nil`, the configuration value is removed globally. + /// - path: The optional path specifying the context (local repository directory) \ + /// in which to remove the configuration value. \ + /// If `nil`, the configuration value is removed globally. /// /// - Throws: /// - An error of type `Error` if any issues occur during the configuration value removal process. @@ -574,7 +597,8 @@ public struct Config { /// ``` /// /// - Note: - /// If `path` is `nil`, the configuration value is removed globally; otherwise, it's removed within the specified local repository context. + /// If `path` is `nil`, the configuration value is removed globally; otherwise, + /// it's removed within the specified local repository context. public func removeConfigValueInPath(name: String, path: String?) throws { var gitCommand: String diff --git a/Sources/Version-Control/Services/Models/Client/Description.swift b/Sources/Version-Control/Services/Models/Client/Description.swift index 354ed826..57b42137 100644 --- a/Sources/Version-Control/Services/Models/Client/Description.swift +++ b/Sources/Version-Control/Services/Models/Client/Description.swift @@ -15,7 +15,9 @@ private let defaultGitDescription = "Unnamed repository; edit this file 'descrip /// Get the project's description from the `.git/description` file. /// -/// This function retrieves the project's description from the `.git/description` file within a Git repository located at the specified `directoryURL`. The description typically provides a brief overview of the project. +/// This function retrieves the project's description from the `.git/description` +/// file within a Git repository located at the specified `directoryURL`. \ +/// The description typically provides a brief overview of the project. /// /// - Parameter directoryURL: The URL of the directory containing the Git repository. /// @@ -42,7 +44,9 @@ private let defaultGitDescription = "Unnamed repository; edit this file 'descrip /// ``` /// /// - Note: -/// This function reads the content of the `.git/description` file in the Git repository specified by `directoryURL` and returns it as a string. If the description is not found or cannot be retrieved, an empty string is returned. +/// This function reads the content of the `.git/description` file in the Git repository specified by +/// `directoryURL` and returns it as a string. \ +/// If the description is not found or cannot be retrieved, an empty string is returned. public func getGitDescription(directoryURL: URL) throws -> String { let path = try String(contentsOf: directoryURL) + gitDescriptionPath @@ -59,7 +63,9 @@ public func getGitDescription(directoryURL: URL) throws -> String { /// Write a project's description to the `.git/description` file within a Git repository. /// -/// This function writes the provided `description` to the `.git/description` file within a Git repository located at the specified `directoryURL`. The description typically provides a brief overview of the project. +/// This function writes the provided `description` to the `.git/description` file within +/// a Git repository located at the specified `directoryURL`. \ +/// The description typically provides a brief overview of the project. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -82,7 +88,9 @@ public func getGitDescription(directoryURL: URL) throws -> String { /// ``` /// /// - Note: -/// This function writes the provided `description` to the `.git/description` file in the Git repository specified by `directoryURL`. It does so by overwriting the existing content of the file, if any. +/// This function writes the provided `description` to the `.git/description` file +/// in the Git repository specified by `directoryURL`. \ +/// It does so by overwriting the existing content of the file, if any. public func writeGitDescription(directoryURL: URL, description: String) throws { let fullPath = try String(contentsOf: directoryURL) + gitDescriptionPath diff --git a/Sources/Version-Control/Services/Models/Client/Diff-Index.swift b/Sources/Version-Control/Services/Models/Client/Diff-Index.swift index caf9c5af..ab38d88f 100644 --- a/Sources/Version-Control/Services/Models/Client/Diff-Index.swift +++ b/Sources/Version-Control/Services/Models/Client/Diff-Index.swift @@ -74,9 +74,11 @@ public let nilTreeSHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" /// - Parameters: /// - directoryURL: The URL of the Git repository directory where the `git diff-index` command will be executed. /// -/// - Returns: A dictionary where the keys are file paths and the values are `IndexStatus` representing the status of each file in the index. +/// - Returns: A dictionary where the keys are file paths and the values are `IndexStatus` \ +/// representing the status of each file in the index. /// -/// - Throws: An error if there is a problem executing the `git diff-index` command or if the Git repository is not in a valid state. +/// - Throws: An error if there is a problem executing the `git diff-index` command or \ +/// if the Git repository is not in a valid state. /// /// - SeeAlso: `git diff-index` documentation for additional options and details. public func getIndexChanges(directoryURL: URL) throws -> [String: IndexStatus] { diff --git a/Sources/Version-Control/Services/Models/Client/Rev-List.swift b/Sources/Version-Control/Services/Models/Client/Rev-List.swift index 5b72c0eb..b163deca 100644 --- a/Sources/Version-Control/Services/Models/Client/Rev-List.swift +++ b/Sources/Version-Control/Services/Models/Client/Rev-List.swift @@ -39,7 +39,7 @@ import Foundation /// /// - SeeAlso: /// [Git Range](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefrangea) -private func revRange(from: String, to: String) -> String { // swiftlint:disable:this identifier_name +private func revRange(from: String, to: String) -> String { return "\(from)..\(to)" } @@ -72,13 +72,16 @@ private func revRange(from: String, to: String) -> String { // swiftlint:disable /// /// - SeeAlso: /// [Git Inclusive Range](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefinclusiverangea) -private func revRangeInclusive(from: String, to: String) -> String { // swiftlint:disable:this identifier_name +private func revRangeInclusive(from: String, to: String) -> String { return "\(from)^...\(to)" } /// Convert two references into Git's symmetric difference syntax. /// -/// Git's symmetric difference syntax represents the set of commits that are reachable from either the `from` reference or the `to` reference but not from both. This function takes two parameters, `from` and `to`, which can be specified as commit SHA values, reference names, or an empty string to represent the HEAD reference. +/// Git's symmetric difference syntax represents the set of commits that are reachable from either +/// the `from` reference or the `to` reference but not from both. This function takes two parameters, +/// `from` and `to`, which can be specified as commit SHA values, reference names, +/// or an empty string to represent the HEAD reference. /// /// - Parameters: /// - from: The source reference or commit SHA. @@ -97,21 +100,27 @@ private func revRangeInclusive(from: String, to: String) -> String { // swiftlin /// ``` /// /// - Note: -/// The Git symmetric difference syntax is used to represent the set of commits that are reachable from either the `from` reference or the `to` reference but not from both. It is commonly used in Git operations such as comparing branches or finding the differences between two references. +/// The Git symmetric difference syntax is used to represent the set of commits that are +/// reachable from either the `from` reference or the `to` reference but not from both. \ +/// It is commonly used in Git operations such as comparing branches or +/// finding the differences between two references. /// /// - Warning: /// Ensure that the `from` and `to` parameters represent valid references or commit SHA values to /// avoid syntax errors when using the resulting string in Git commands. /// /// - SeeAlso: -/// [Git Symmetric Difference](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefsymmetricdiffa) -private func revSymmetricDifference(from: String, to: String) -> String { // swiftlint:disable:this identifier_name +/// https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefsymmetricdiffa +private func revSymmetricDifference(from: String, to: String) -> String { return "\(from)...\(to)" } /// Calculate the number of commits that a given commit range is ahead of and behind. /// -/// This function calculates the number of commits that a specified commit range is ahead of and behind in a Git repository located at the specified `directoryURL`. The commit range is represented by the `range` parameter, and the result is returned as an `AheadBehind` object containing the counts of commits ahead and behind. +/// This function calculates the number of commits that a specified commit range is ahead of and behind in +/// a Git repository located at the specified `directoryURL`. \ +/// The commit range is represented by the `range` parameter, and the result is returned as +/// an `AheadBehind` object containing the counts of commits ahead and behind. /// /// - Parameters: /// - directoryURL: The URL of the directory containing the Git repository. @@ -188,7 +197,10 @@ public func getAheadBehind(directoryURL: URL, /// Retrieve the number of commits ahead and behind between a local branch and its upstream branch. /// -/// This function calculates the number of commits that a local branch is ahead and behind its corresponding upstream branch. It provides information about how the local branch differs from its upstream branch, taking into account merge bases and merge commits. +/// This function calculates the number of commits that a local branch is ahead and behind its +/// corresponding upstream branch. \ +/// It provides information about how the local branch differs from its upstream branch, +/// taking into account merge bases and merge commits. /// /// - Parameters: /// - directoryURL: The URL of the Git repository directory. @@ -287,10 +299,13 @@ func getBranchAheadBehind(directoryURL: URL, /// ``` /// /// - Note: -/// This function uses the `git rev-range` command to retrieve a list of commits between two commit references. The commits are represented as `CommitOneLine` objects, where each object contains a commit SHA and a commit summary. +/// This function uses the `git rev-range` command to retrieve a list of commits between two commit references. \ +/// The commits are represented as `CommitOneLine` objects, +/// where each object contains a commit SHA and a commit summary. /// /// - Warning: -/// Be cautious when using this function, as missing commit IDs or invalid commit references may result in errors, and it assumes that the Git executable is available and accessible in the system's PATH. +/// Be cautious when using this function, as missing commit IDs or invalid commit references may result in errors, +/// and it assumes that the Git executable is available and accessible in the system's PATH. public func getCommitsBetweenCommits(directoryURL: URL, baseBranchSha: String, targetBranchSha: String) throws -> [CommitOneLine]? { diff --git a/Sources/Version-Control/Services/Models/Diff/Diff-Data.swift b/Sources/Version-Control/Services/Models/Diff/Diff-Data.swift index f94a0d5d..e86d7495 100644 --- a/Sources/Version-Control/Services/Models/Diff/Diff-Data.swift +++ b/Sources/Version-Control/Services/Models/Diff/Diff-Data.swift @@ -35,11 +35,9 @@ public enum LineEndingType: String { public class LineEndingsChange { var from: LineEndingType - // swiftlint:disable:next identifier_name var to: LineEndingType init(from: LineEndingType, - // swiftlint:disable:next identifier_name to: LineEndingType) { self.from = from self.to = to diff --git a/Sources/Version-Control/Services/Models/Diff/Diff-Selection.swift b/Sources/Version-Control/Services/Models/Diff/Diff-Selection.swift index f7cb16d0..f1094737 100644 --- a/Sources/Version-Control/Services/Models/Diff/Diff-Selection.swift +++ b/Sources/Version-Control/Services/Models/Diff/Diff-Selection.swift @@ -171,7 +171,6 @@ class DiffSelection { length: Int, selected: Bool) throws -> DiffSelection { let computedSelectionType = self.getSelectionType() - // swiftlint:disable:next identifier_name let to = from + length if try typeMatchesSelection(selectionType: computedSelectionType, From 5ea8b319289fee545733c04cda131d1182bd62f6 Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Sun, 8 Oct 2023 12:27:20 +0100 Subject: [PATCH 3/4] Some more Swiftlint fixes --- .../Services/Models/Client/GitIgnore.swift | 69 ++++++++++++++----- .../Services/Models/Client/LFS.swift | 14 ++-- .../Services/Models/Client/Merge.swift | 43 ++++++++---- .../Services/Models/Client/Reflog.swift | 29 ++++++-- .../Services/Models/Client/Remote.swift | 18 +++-- .../Services/Models/Client/Reset.swift | 66 ++++++++++++------ .../Services/Models/Client/Rev-List.swift | 12 +++- 7 files changed, 181 insertions(+), 70 deletions(-) diff --git a/Sources/Version-Control/Services/Models/Client/GitIgnore.swift b/Sources/Version-Control/Services/Models/Client/GitIgnore.swift index bc7d464c..6bb11ffa 100644 --- a/Sources/Version-Control/Services/Models/Client/GitIgnore.swift +++ b/Sources/Version-Control/Services/Models/Client/GitIgnore.swift @@ -15,9 +15,12 @@ public struct GitIgnore { /// Read the contents of the repository's root `.gitignore` file. /// - /// This function reads the contents of the `.gitignore` file located in the root directory of the Git repository. If the `.gitignore` file exists and has content, it will be returned as a string. If there is no `.gitignore` file in the repository root, the function will return `nil`. + /// This function reads the contents of the `.gitignore` file located in the root directory of the Git repository. \ + /// If the `.gitignore` file exists and has content, it will be returned as a string. \ + /// If there is no `.gitignore` file in the repository root, the function will return `nil`. /// - /// - Parameter directoryURL: The URL of the Git repository directory where the `.gitignore` file is expected to be located. + /// - Parameter directoryURL: The URL of the Git repository directory where the `.gitignore` \ + /// file is expected to be located. /// /// - Returns: The contents of the `.gitignore` file as a string if it exists, or `nil` if the file is not present. /// @@ -34,7 +37,8 @@ public struct GitIgnore { /// } /// ``` /// - /// - Important: Ensure that you have read permissions for the repository directory and that the provided directory is part of a Git repository. + /// - Important: Ensure that you have read permissions for the repository directory + /// and that the provided directory is part of a Git repository. public func readGitIgnoreAtRoot(directoryURL: URL) throws -> String? { let ignorePath = try String(contentsOf: directoryURL) + ".gitignore" let content = try String(contentsOf: URL(string: ignorePath)!) @@ -43,11 +47,15 @@ public struct GitIgnore { /// Persist the given content to the root `.gitignore` file of the repository. /// - /// This function saves the provided text content to the root `.gitignore` file of the Git repository. If the repository root doesn't contain a `.gitignore` file, one will be created with the specified content. If a `.gitignore` file already exists, its contents will be overwritten with the new content. + /// This function saves the provided text content to the root `.gitignore` file of the Git repository. \ + /// If the repository root doesn't contain a `.gitignore` file, one will be created with the specified content. \ + /// If a `.gitignore` file already exists, its contents will be overwritten with the new content. /// /// - Parameters: - /// - directoryURL: The URL of the Git repository directory where the root `.gitignore` file should be located or created. - /// - text: The content to be saved to the `.gitignore` file. This content should follow `.gitignore` file format rules. + /// - directoryURL: The URL of the Git repository directory where the root `.gitignore` file \ + /// should be located or created. + /// - text: The content to be saved to the `.gitignore` file. This content should follow `.gitignore` \ + /// file format rules. /// /// - Throws: An error if there is a problem creating, writing, or saving the `.gitignore` file. /// @@ -60,7 +68,8 @@ public struct GitIgnore { /// try saveGitIgnore(directoryURL: directoryURL, text: gitIgnoreContents) /// ``` /// - /// - Important: Ensure that you have write permissions for the repository directory and that the provided directory is part of a Git repository. + /// - Important: Ensure that you have write permissions for the repository directory and \ + /// that the provided directory is part of a Git repository. public func saveGitIgnore(directoryURL: URL, text: String) throws { let ignorePath = try String(contentsOf: directoryURL) + ".gitignore" @@ -76,15 +85,19 @@ public struct GitIgnore { /// Add the given pattern or patterns to the root `.gitignore` file of the repository. /// - /// This function appends one or more patterns to the root `.gitignore` file of the specified Git repository. The provided patterns will be added to the end of the existing `.gitignore` file, and they will be escaped as necessary to ensure proper matching. + /// This function appends one or more patterns to the root `.gitignore` file of the specified Git repository. \ + /// The provided patterns will be added to the end of the existing `.gitignore` file, + /// and they will be escaped as necessary to ensure proper matching. /// /// - Parameters: /// - directoryURL: The URL of the Git repository directory where the root `.gitignore` file is located. - /// - patterns: An array of patterns to append to the `.gitignore` file. Each pattern should be on a separate line. + /// - patterns: An array of patterns to append to the `.gitignore` file. \ + /// Each pattern should be on a separate line. /// /// - Throws: An error if there is a problem reading, updating, or saving the `.gitignore` file. /// - /// - Note: If the `.gitignore` file does not exist in the repository, it will be created with the specified patterns. + /// - Note: If the `.gitignore` file does not exist in the repository, \ + /// it will be created with the specified patterns. /// /// - Example: /// ```swift @@ -93,7 +106,8 @@ public struct GitIgnore { /// try appendIgnoreRule(directoryURL: directoryURL, patterns: patterns) /// ``` /// - /// - Important: Ensure that you have write permissions for the `.gitignore` file and that the provided directory is part of a Git repository. + /// - Important: Ensure that you have write permissions for the `.gitignore` file \ + /// and that the provided directory is part of a Git repository. public func appendIgnoreRule(directoryURL: URL, patterns: [String]) throws { let text = try readGitIgnoreAtRoot(directoryURL: directoryURL) @@ -109,7 +123,10 @@ public struct GitIgnore { /// Convenience method to add the given file path(s) to the repository's `.gitignore` file. /// - /// This function allows you to append one or more file paths to the `.gitignore` file in the specified repository directory. The provided file paths will be escaped before being added to the `.gitignore` file to ensure they are properly matched. + /// This function allows you to append one or more file paths to the `.gitignore` file + /// in the specified repository directory. \ + /// The provided file paths will be escaped before being added to the `.gitignore` file + /// to ensure they are properly matched. /// /// - Parameters: /// - directoryURL: The URL of the directory where the `.gitignore` file is located. @@ -141,13 +158,16 @@ public struct GitIgnore { /// Escapes special characters in a string for use in a `.gitignore` file pattern. /// - /// This function takes a string pattern and escapes any special characters that are used in `.gitignore` file patterns. The escaped pattern can then be safely used in a `.gitignore` file to match files and directories. + /// This function takes a string pattern and escapes any special characters that + /// are used in `.gitignore` file patterns. \ + /// The escaped pattern can then be safely used in a `.gitignore` file to match files and directories. /// /// - Parameter pattern: The string pattern to be escaped. /// /// - Returns: The escaped string pattern suitable for use in a `.gitignore` file. /// - /// - Note: The special characters that are escaped include `/`, `[`, `]`, `!`, `*`, `#`, and `?`, as they have special meanings in `.gitignore` patterns. + /// - Note: The special characters that are escaped include `/`, `[`, `]`, `!`, `*`, `#`, and `?`, \ + /// as they have special meanings in `.gitignore` patterns. /// /// - Example: /// ```swift @@ -156,7 +176,8 @@ public struct GitIgnore { /// // Use the escapedPattern in a .gitignore file. /// ``` /// - /// - Important: The escaped pattern is intended for use in `.gitignore` files. Ensure that you understand how `.gitignore` patterns work in Git repositories. + /// - Important: The escaped pattern is intended for use in `.gitignore` files. \ + /// Ensure that you understand how `.gitignore` patterns work in Git repositories. public func escapeGitSpecialCharacters(pattern: String) -> String { // Define the characters that need to be escaped within a regular expression pattern let specialCharacters = "/[\\[\\]!\\*\\#\\?]/" @@ -173,7 +194,10 @@ public struct GitIgnore { /// Format the contents of a `.gitignore` file based on the current Git configuration settings. /// - /// This function takes the text contents of a `.gitignore` file and formats it based on the current Git configuration settings, specifically `core.autocrlf` and `core.safecrlf`. Depending on these settings, it may normalize line endings to CRLF (`\r\n`) or LF (`\n`), and it ensures that the file ends with the appropriate line ending based on Git's behavior. + /// This function takes the text contents of a `.gitignore` file and formats it based on + /// the current Git configuration settings, specifically `core.autocrlf` and `core.safecrlf`. \ + /// Depending on these settings, it may normalize line endings to CRLF (`\r\n`) or LF (`\n`), + /// and it ensures that the file ends with the appropriate line ending based on Git's behavior. /// /// - Parameters: /// - text: The text contents of the `.gitignore` file to format. @@ -183,19 +207,26 @@ public struct GitIgnore { /// /// - Returns: The formatted text contents of the `.gitignore` file. /// - /// - Note: The `core.autocrlf` setting controls how line endings are handled in the working directory, while `core.safecrlf` affects Git's behavior when adding files to the index. This function ensures that the `.gitignore` file adheres to these settings to prevent conflicts and confusion. + /// - Note: The `core.autocrlf` setting controls how line endings are handled in the working directory, \ + /// while `core.safecrlf` affects Git's behavior when adding files to the index. \ + /// This function ensures that the `.gitignore` file adheres to these settings to \ + /// prevent conflicts and confusion. /// /// - Example: /// ```swift /// do { - /// let gitIgnoreText = try formatGitIgnoreContents(text: myGitIgnoreText, directoryURL: myProjectDirectoryURL) + /// let gitIgnoreText = try formatGitIgnoreContents( + //// text: myGitIgnoreText, + //// directoryURL: myProjectDirectoryURL + /// ) /// // Use the formatted gitIgnoreText as needed. /// } catch { /// print("Error: \(error)") /// } /// ``` /// - /// - Important: Ensure that you have a valid Git repository and a `.gitignore` file in the specified directory before calling this function. + /// - Important: Ensure that you have a valid Git repository and a `.gitignore` file \ + /// in the specified directory before calling this function. func formatGitIgnoreContents(text: String, directoryURL: URL) throws -> String { let autocrlf = try Config().getConfigValue(directoryURL: directoryURL, name: "core.autocrlf") let safecrlf = try Config().getConfigValue(directoryURL: directoryURL, name: "core.safecrlf") diff --git a/Sources/Version-Control/Services/Models/Client/LFS.swift b/Sources/Version-Control/Services/Models/Client/LFS.swift index 38c017ea..5397d8a1 100644 --- a/Sources/Version-Control/Services/Models/Client/LFS.swift +++ b/Sources/Version-Control/Services/Models/Client/LFS.swift @@ -35,9 +35,12 @@ public struct LFS { /// } /// ``` /// - /// - Note: If `force` is set to `true`, the function will forcibly install global LFS filters even if they already exist. + /// - Note: If `force` is set to `true`, the function will forcibly install global LFS filters \ + /// even if they already exist. /// - /// - Important: Installing global Git LFS filters is typically required to properly manage large files in all Git repositories on the system. Make sure to call this function if you want to apply Git LFS globally. + /// - Important: Installing global Git LFS filters is typically required to \ + /// properly manage large files in all Git repositories on the system. \ + /// Make sure to call this function if you want to apply Git LFS globally. public func installGlobalLFSFilters(force: Bool) throws { var args = ["lfs", "install", "--skip-repo"] @@ -177,9 +180,12 @@ public struct LFS { return match } - /// Query a Git repository to filter a set of provided relative paths and identify which files are not covered by the current Git LFS (Large File Storage) configuration. + /// Query a Git repository to filter a set of provided relative paths \ + /// and identify which files are not covered by the current Git LFS (Large File Storage) configuration. /// - /// Git LFS is an extension for handling large files in a Git repository, and this function helps you determine which files are not tracked by Git LFS within the specified relative paths. + /// Git LFS is an extension for handling large files in a Git repository, + /// and this function helps you determine which files are not tracked by + /// Git LFS within the specified relative paths. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. diff --git a/Sources/Version-Control/Services/Models/Client/Merge.swift b/Sources/Version-Control/Services/Models/Client/Merge.swift index 978e4d9a..a9118860 100644 --- a/Sources/Version-Control/Services/Models/Client/Merge.swift +++ b/Sources/Version-Control/Services/Models/Client/Merge.swift @@ -21,7 +21,9 @@ public enum MergeResult { /// Merge the named branch into the current branch in the Git repository. /// -/// This function performs a merge operation, incorporating changes from a named branch into the current branch of the Git repository. You can specify whether to perform a regular merge or a squash merge. +/// This function performs a merge operation, +/// incorporating changes from a named branch into the current branch of the Git repository. \ +/// You can specify whether to perform a regular merge or a squash merge. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. @@ -50,7 +52,9 @@ public enum MergeResult { /// } /// ``` /// -/// - Important: This function performs a merge operation in the Git repository. Ensure that the provided branch name is valid and that the repository is in a clean state before calling this function. +/// - Important: This function performs a merge operation in the Git repository. \ +/// Ensure that the provided branch name is valid and that the repository is in a \ +/// clean state before calling this function. public func merge(directoryURL: URL, branch: String, isSquash: Bool = false) throws -> MergeResult { @@ -80,7 +84,8 @@ private let noopMergeMessage = "Already up to date.\n" /// Find the base commit between two commit-ish identifiers in the Git repository. /// -/// This function calculates the merge base commit between two commit-ish identifiers (e.g., branch names, commit hashes) in the Git repository. +/// This function calculates the merge base commit between two commit-ish identifiers +/// (e.g., branch names, commit hashes) in the Git repository. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. @@ -96,14 +101,19 @@ private let noopMergeMessage = "Already up to date.\n" /// let repositoryURL = URL(fileURLWithPath: "/path/to/git/repo") /// let firstBranch = "feature/branch-a" /// let secondBranch = "feature/branch-b" -/// if let mergeBase = try getMergeBase(directoryURL: repositoryURL, firstCommitish: firstBranch, secondCommitish: secondBranch) { +/// if let mergeBase = try getMergeBase( +/// directoryURL: repositoryURL, +/// firstCommitish: firstBranch, +/// secondCommitish: secondBranch +/// ) { /// print("Merge base commit: \(mergeBase)") /// } else { /// print("No common merge base found.") /// } /// ``` /// -/// - Important: This function requires valid commit-ish identifiers as input, and it may return `nil` if there is no common merge base between the provided commit-ish identifiers. +/// - Important: This function requires valid commit-ish identifiers as input, \ +/// and it may return `nil` if there is no common merge base between the provided commit-ish identifiers. public func getMergeBase(directoryURL: URL, firstCommitish: String, secondCommitish: String) throws -> String? { @@ -116,12 +126,14 @@ public func getMergeBase(directoryURL: URL, /// Abort a conflicted merge in the Git repository. /// -/// This function aborts a mid-flight merge operation that is in a conflicted state. It is equivalent to running the `git merge --abort` command in the repository. +/// This function aborts a mid-flight merge operation that is in a conflicted state. \ +/// It is equivalent to running the `git merge --abort` command in the repository. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. /// -/// - Throws: An error if there was an issue aborting the merge operation or if the repository is not in a merge-conflicted state. +/// - Throws: An error if there was an issue aborting the merge operation or \ +/// if the repository is not in a merge-conflicted state. /// /// - Example: /// ```swift @@ -130,7 +142,8 @@ public func getMergeBase(directoryURL: URL, /// print("Merge aborted successfully.") /// ``` /// -/// - Important: This function should only be called when the repository is in a conflicted state due to a mid-flight merge operation. +/// - Important: This function should only be called when the repository is in a conflicted state \ +/// due to a mid-flight merge operation. public func abortMerge(directoryURL: URL) throws { // Execute the `git merge --abort` command to abort the conflicted merge. _ = try ShellClient.live().run( @@ -140,7 +153,9 @@ public func abortMerge(directoryURL: URL) throws { /// Check if the `.git/MERGE_HEAD` file exists in the Git repository. /// -/// This function checks for the presence of the `.git/MERGE_HEAD` file in the repository's Git directory. The existence of this file typically indicates that the repository is in a conflicted state due to an ongoing merge operation. +/// This function checks for the presence of the `.git/MERGE_HEAD` file in the repository's Git directory. \ +/// The existence of this file typically indicates that the repository is in a conflicted state due to +/// an ongoing merge operation. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. @@ -168,16 +183,20 @@ public func isMergeHeadSet(directoryURL: URL) throws -> Bool { /// Check if the `.git/SQUASH_MSG` file exists in the Git repository. /// -/// This function checks for the presence of the `.git/SQUASH_MSG` file in the repository's Git directory. The existence of this file typically indicates that a merge with the `--squash` option has been initiated, and the merge has not yet been committed. It can be an indicator of a detected conflict. +/// This function checks for the presence of the `.git/SQUASH_MSG` file in the repository's Git directory. \ +/// The existence of this file typically indicates that a merge with the `--squash` option has been initiated, +/// and the merge has not yet been committed. It can be an indicator of a detected conflict. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. /// -/// - Returns: `true` if the `.git/SQUASH_MSG` file exists, indicating a potential merge --squash scenario; otherwise, `false`. +/// - Returns: `true` if the `.git/SQUASH_MSG` file exists, \ +/// indicating a potential merge --squash scenario; otherwise, `false`. /// /// - Throws: An error if there was an issue accessing or reading the repository's Git directory. /// -/// - Note: If a merge --squash is aborted, the `.git/SQUASH_MSG` file may not be cleared automatically, leading to its presence in non-merge --squashing scenarios. +/// - Note: If a merge --squash is aborted, the `.git/SQUASH_MSG` file may not be cleared automatically, \ +/// leading to its presence in non-merge --squashing scenarios. /// /// - Example: /// ```swift diff --git a/Sources/Version-Control/Services/Models/Client/Reflog.swift b/Sources/Version-Control/Services/Models/Client/Reflog.swift index 098f511f..f5720a2a 100644 --- a/Sources/Version-Control/Services/Models/Client/Reflog.swift +++ b/Sources/Version-Control/Services/Models/Client/Reflog.swift @@ -11,7 +11,10 @@ import Foundation /// Get a list of the `limit` most recently checked out branches in the Git repository. /// -/// This function retrieves information from the Git logs to identify branches that were recently checked out. It is useful for tracking branch history and provides the names of branches that were either checked out or renamed. +/// This function retrieves information from the Git logs to identify branches +/// that were recently checked out. \ +/// It is useful for tracking branch history and provides the names of branches +/// that were either checked out or renamed. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. @@ -22,8 +25,10 @@ import Foundation /// - Throws: An error if there was an issue executing the Git log command or if the output couldn't be parsed. /// /// - Note: -/// - This function uses regular expressions to parse the Git log output, looking for branch checkout and rename events. -/// - Renamed branches are considered as part of the history, and their original names are excluded from the result to avoid duplicates. +/// - This function uses regular expressions to parse the Git log output, \ +/// looking for branch checkout and rename events. +/// - Renamed branches are considered as part of the history, \ +/// and their original names are excluded from the result to avoid duplicates. /// /// - Example: /// ```swift @@ -98,7 +103,10 @@ private let noCommitsOnBranchRe = "fatal: your current branch '.*' does not have /// Get a distinct list of branches that have been checked out after a specific date in the Git repository. /// -/// This function retrieves information from the Git reflog to identify branches that were checked out after a given date. It returns a dictionary where the keys are branch names, and the values are the timestamps when the branches were checked out. +/// This function retrieves information from the Git reflog to identify branches +/// that were checked out after a given date. \ +/// It returns a dictionary where the keys are branch names, +/// and the values are the timestamps when the branches were checked out. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. @@ -110,7 +118,8 @@ private let noCommitsOnBranchRe = "fatal: your current branch '.*' does not have /// /// - Note: /// - This function uses regular expressions to parse the Git reflog output, looking for checkout events. -/// - The reflog records information about various operations, and this function specifically filters for "checkout" events after the specified date. +/// - The reflog records information about various operations, \ +/// and this function specifically filters for "checkout" events after the specified date. /// /// - Example: /// ```swift @@ -129,7 +138,15 @@ public func getBranchCheckouts(directoryURL: URL, afterDate: Date) throws -> [St // Create a process to execute the Git reflog command. let process = Process() process.executableURL = URL(fileURLWithPath: "/usr/bin/env") - process.arguments = ["git", "reflog", "--date=iso", "--after=\(afterDate.ISO8601Format())", "--pretty=%H %gd %gs", "--grep-reflog=checkout: moving from .* to .*$", "--"] + process.arguments = [ + "git", + "reflog", + "--date=iso", + "--after=\(afterDate.ISO8601Format())", + "--pretty=%H %gd %gs", + "--grep-reflog=checkout: moving from .* to .*$", + "--" + ] process.currentDirectoryURL = URL(fileURLWithPath: directoryURL.relativePath.escapedWhiteSpaces()) // Create pipes for capturing the stdout and stderr of the Git reflog command. diff --git a/Sources/Version-Control/Services/Models/Client/Remote.swift b/Sources/Version-Control/Services/Models/Client/Remote.swift index f65ad81c..c2025fd0 100644 --- a/Sources/Version-Control/Services/Models/Client/Remote.swift +++ b/Sources/Version-Control/Services/Models/Client/Remote.swift @@ -225,16 +225,22 @@ public func getRemoteURL(directoryURL: URL, name: String) throws -> String? { /// Update the HEAD reference for a remote Git repository. /// -/// Use this function to update the HEAD reference of a remote Git repository associated with a specific remote name. The function executes a Git command to set the HEAD reference of the remote repository to its default branch (usually the main branch). +/// Use this function to update the HEAD reference of a remote Git repository associated +/// with a specific remote name. \ +/// The function executes a Git command to set the HEAD reference of the remote repository +/// to its default branch (usually the main branch). /// /// - Parameters: /// - directoryURL: The URL of the local Git repository. /// - remote: An instance of `IRemote` representing the remote repository to update. /// -/// - Throws: An error if there is a problem accessing the Git repository or executing the Git command to update the remote's HEAD reference. +/// - Throws: An error if there is a problem accessing the Git repository or executing \ +/// the Git command to update the remote's HEAD reference. /// /// - Note: -/// - The function executes the Git command `git remote set-head -a ` to update the remote's HEAD reference to its default branch. This operation is typically used to synchronize the remote's HEAD reference with its default branch. +/// - The function executes the Git command `git remote set-head -a ` \ +/// to update the remote's HEAD reference to its default branch. \ +/// This operation is typically used to synchronize the remote's HEAD reference with its default branch. /// /// - Example: /// ```swift @@ -283,7 +289,8 @@ public func updateRemoteHEAD(directoryURL: URL, remote: IRemote) throws { /// ``` /// /// - Note: -/// - This function constructs the reference path for the remote's HEAD using the provided `remote` name and then fetches the reference using the `Refs` utility. +/// - This function constructs the reference path for the remote's HEAD using the provided \ +/// `remote` name and then fetches the reference using the `Refs` utility. /// - The function returns `nil` if the remote's HEAD reference is not found or if there is an error in the process. public func getRemoteHEAD(directoryURL: URL, remote: String) throws -> String? { let remoteNamespace = "refs/remotes/\(remote)/" @@ -322,7 +329,8 @@ public func getRemoteHEAD(directoryURL: URL, remote: String) throws -> String? { /// /// - Note: /// - This function fetches the HEAD reference information from a remote Git repository at the specified URL. -/// - It extracts the name of the HEAD branch from the Git command output, removing any empty or unnecessary characters. +/// - It extracts the name of the HEAD branch from the Git command output, \ +/// removing any empty or unnecessary characters. public func getRemoteHEAD(url: String) throws -> String { return try ShellClient.live().run( "git ls-remote -q --symref \(url) | head -1 | cut -f1 | sed 's!^ref: refs/heads/!!'" diff --git a/Sources/Version-Control/Services/Models/Client/Reset.swift b/Sources/Version-Control/Services/Models/Client/Reset.swift index 6bb655ed..15022221 100644 --- a/Sources/Version-Control/Services/Models/Client/Reset.swift +++ b/Sources/Version-Control/Services/Models/Client/Reset.swift @@ -30,11 +30,13 @@ public struct Reset { /// Convert a Git reset mode and a reference to an array of Git command arguments. /// - /// Use this function to convert a specified reset mode (e.g., hard, mixed, soft) and a reference to an array of Git command arguments that can be used for performing a reset operation. + /// Use this function to convert a specified reset mode (e.g., hard, mixed, soft) + /// and a reference to an array of Git command arguments that can be used for performing a reset operation. /// /// - Parameters: /// - mode: The reset mode, represented by the `GitResetMode` enum. - /// - ref: A string that resolves to a reference, such as 'HEAD' or a commit SHA, to which the reset operation should be applied. + /// - ref: A string that resolves to a reference, such as 'HEAD' or a commit SHA, \ + /// to which the reset operation should be applied. /// /// - Returns: An array of Git command arguments that correspond to the specified reset mode and reference. /// @@ -48,7 +50,8 @@ public struct Reset { /// ``` /// /// - Note: - /// - This function is used to generate the Git command arguments for a reset operation based on the specified reset mode and reference. + /// - This function is used to generate the Git command arguments for \ + /// a reset operation based on the specified reset mode and reference. /// - The resulting arguments can be passed to Git commands for resetting the repository's HEAD and index. public func resetModeToArgs(mode: GitResetMode, ref: String) -> [String] { switch mode { @@ -63,20 +66,24 @@ public struct Reset { /// Reset the Git repository's HEAD and index to a specified reference with the given mode. /// - /// Use this function to reset the repository's HEAD and index to match a specific reference (e.g., commit or branch) using the specified reset mode. + /// Use this function to reset the repository's HEAD and index to match a specific reference + /// (e.g., commit or branch) using the specified reset mode. /// /// - Parameters: /// - directoryURL: The URL of the directory where the Git repository is located. /// - mode: The mode to use when resetting the repository. See the `GitResetMode` enum for more information. - /// - ref: A string that resolves to a reference, such as 'HEAD' or a commit SHA, to which the repository's HEAD and index should be reset. + /// - ref: A string that resolves to a reference, such as 'HEAD' or a commit SHA, \ + /// to which the repository's HEAD and index should be reset. /// - /// - Throws: An error if the operation fails. Possible errors include Git-related errors or issues with the provided repository path. + /// - Throws: An error if the operation fails. \ + /// Possible errors include Git-related errors or issues with the provided repository path. /// /// - Returns: `true` if the reset operation was successful; otherwise, `false`. /// /// - Example: /// ```swift - /// let repositoryURL = URL(fileURLWithPath: "/path/to/your/repository") // Replace with the repository's directory URL + /// // Replace with the repository's directory URL + /// let repositoryURL = URL(fileURLWithPath: "/path/to/your/repository") /// /// do { /// let success = try reset(directoryURL: repositoryURL, mode: .mixed, ref: "HEAD~2") @@ -91,11 +98,13 @@ public struct Reset { /// ``` /// /// - Note: - /// - The `mode` parameter determines how the reset operation will behave (e.g., soft, mixed, hard). Refer to the `GitResetMode` enum for more details. + /// - The `mode` parameter determines how the reset operation will behave (e.g., soft, mixed, hard). \ + /// Refer to the `GitResetMode` enum for more details. /// - This function alters the state of the Git repository, so use it with caution. /// /// - Warning: - /// Ensure that the provided `directoryURL` points to a valid Git repository directory. If the operation fails, check for potential issues with the repository or file permissions. + /// Ensure that the provided `directoryURL` points to a valid Git repository directory. \ + /// If the operation fails, check for potential issues with the repository or file permissions. public func reset(directoryURL: URL, mode: GitResetMode, ref: String) throws -> Bool { @@ -109,20 +118,25 @@ public struct Reset { /// Updates the index with information from a particular tree for a given set of paths. /// - /// Use this function to reset the index (staging area) to match a specific tree or commit for a set of specified paths in the Git repository. + /// Use this function to reset the index (staging area) to match a specific tree or commit + /// for a set of specified paths in the Git repository. /// /// - Parameters: /// - directoryURL: The URL of the directory where the Git repository is located. /// - mode: The mode to use when resetting the index. See the `GitResetMode` enum for more information. /// - ref: A string that resolves to a tree, such as 'HEAD' or a commit SHA, from which to update the index. - /// - paths: An array of strings representing the paths that should be updated in the index with information from the specified tree or commit. + /// - paths: An array of strings representing the paths that should be updated in the index \ + /// with information from the specified tree or commit. /// - /// - Throws: An error if the operation fails. Possible errors include Git-related errors or issues with the provided repository path. + /// - Throws: An error if the operation fails. + /// Possible errors include Git-related errors or issues with the provided repository path. /// /// - Example: /// ```swift - /// let repositoryURL = URL(fileURLWithPath: "/path/to/your/repository") // Replace with the repository's directory URL - /// let pathsToUpdate = ["file1.txt", "folder/file2.txt"] // Replace with the paths you want to update + /// // Replace with the repository's directory URL + /// let repositoryURL = URL(fileURLWithPath: "/path/to/your/repository") + /// // Replace with the paths you want to update + /// let pathsToUpdate = ["file1.txt", "folder/file2.txt"] /// /// do { /// try resetPaths(directoryURL: repositoryURL, mode: .soft, ref: "HEAD", paths: pathsToUpdate) @@ -133,11 +147,14 @@ public struct Reset { /// ``` /// /// - Note: - /// - The `mode` parameter determines how the index will be reset (e.g., soft, mixed, hard). Refer to the `GitResetMode` enum for more details. - /// - This function updates the index to match the specified tree or commit, effectively altering the staging area's content. + /// - The `mode` parameter determines how the index will be reset (e.g., soft, mixed, hard).\ + /// Refer to the `GitResetMode` enum for more details. + /// - This function updates the index to match the specified tree or commit, \ + /// effectively altering the staging area's content. /// /// - Warning: - /// Ensure that the provided `directoryURL` points to a valid Git repository directory. If the operation fails, check for potential issues with the repository or file permissions. + /// Ensure that the provided `directoryURL` points to a valid Git repository directory. \ + /// If the operation fails, check for potential issues with the repository or file permissions. /// /// - SeeAlso: `GitResetMode`, `reset`, `resetPaths(directoryURL:mode:ref:)` public func resetPaths(directoryURL: URL, @@ -157,7 +174,8 @@ public struct Reset { /// Unstages all changes in the Git repository. /// - /// This function removes all changes from the staging area (index) of the Git repository, effectively "unstaging" them. Any changes that were previously staged but not committed will be reset. + /// This function removes all changes from the staging area (index) of the Git repository, + /// effectively "unstaging" them. Any changes that were previously staged but not committed will be reset. /// /// - Parameter directoryURL: The URL of the directory where the Git repository is located. /// @@ -165,7 +183,9 @@ public struct Reset { /// /// - Example: /// ```swift - /// let repositoryURL = URL(fileURLWithPath: "/path/to/your/repository") // Replace with the repository's directory URL + /// let repositoryURL = URL( + /// fileURLWithPath: "/path/to/your/repository" + /// ) // Replace with the repository's directory URL /// let success = try? unstageAll(directoryURL: repositoryURL) /// if success == true { /// print("All changes have been unstaged.") @@ -175,10 +195,14 @@ public struct Reset { /// ``` /// /// - Note: - /// This function is useful for undoing the staging of changes that were previously marked for commit but not yet committed. After calling this function, the changes will remain in the working directory but will no longer be part of the next commit. + /// This function is useful for undoing the staging of changes that were previously marked for commit + /// but not yet committed. \ + /// After calling this function, + /// the changes will remain in the working directory but will no longer be part of the next commit. /// /// - Warning: - /// Ensure that the provided `directoryURL` points to a valid Git repository directory. If the operation fails, check for potential issues with the repository or file permissions. + /// Ensure that the provided `directoryURL` points to a valid Git repository directory. \ + /// If the operation fails, check for potential issues with the repository or file permissions. /// /// - Returns: `true` if all changes were successfully unstaged, `false` if there was an error during the operation. @discardableResult diff --git a/Sources/Version-Control/Services/Models/Client/Rev-List.swift b/Sources/Version-Control/Services/Models/Client/Rev-List.swift index b163deca..210f2b1f 100644 --- a/Sources/Version-Control/Services/Models/Client/Rev-List.swift +++ b/Sources/Version-Control/Services/Models/Client/Rev-List.swift @@ -10,7 +10,9 @@ import Foundation /// Convert two references into Git's range syntax. /// -/// Git's range syntax represents the set of commits that are reachable from the `to` reference but excludes those that are reachable from the `from` reference. This syntax is not inclusive of the `from` reference itself; it only includes commits up to the `to` reference. +/// Git's range syntax represents the set of commits that are reachable from the `to` reference +/// but excludes those that are reachable from the `from` reference. \ +/// This syntax is not inclusive of the `from` reference itself; it only includes commits up to the `to` reference. /// /// - Parameters: /// - from: The source reference or commit SHA. @@ -45,7 +47,9 @@ private func revRange(from: String, to: String) -> String { /// Convert two references into Git's inclusive range syntax. /// -/// Git's inclusive range syntax represents the set of commits that are reachable from the `to` reference but excludes those that are reachable from the `from` reference. Unlike `revRange`, this syntax includes the `from` reference itself. +/// Git's inclusive range syntax represents the set of commits that are reachable from the `to` +/// reference but excludes those that are reachable from the `from` reference. \ +/// Unlike `revRange`, this syntax includes the `from` reference itself. /// /// - Parameters: /// - from: The source reference or commit SHA. @@ -64,7 +68,9 @@ private func revRange(from: String, to: String) -> String { /// ``` /// /// - Note: -/// The Git inclusive range syntax is used to represent the set of commits that are reachable from the `to` reference but excludes those that are reachable from the `from` reference. It includes the commit specified by the `from` reference. +/// The Git inclusive range syntax is used to represent the set of commits that are reachable +/// from the `to` reference but excludes those that are reachable from the `from` reference. \ +/// It includes the commit specified by the `from` reference. /// /// - Warning: /// Ensure that the `from` and `to` parameters represent valid references or commit SHA values From 88bccdbdb616875a1dbd6a11961a71d7681b720b Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Sun, 8 Oct 2023 12:37:20 +0100 Subject: [PATCH 4/4] Last Swiftlint fixes --- .../Services/Models/Client/Branch.swift | 2 +- .../Services/Models/Client/Config.swift | 2 +- .../Services/Models/Client/LFS.swift | 38 +++++++--- .../Services/Models/Client/Reflog.swift | 2 +- .../Services/Models/Client/Refs.swift | 27 +++++-- .../Services/Models/Client/Remote.swift | 76 +++++++++++++------ .../Models/ManualConflictResolution.swift | 4 +- 7 files changed, 106 insertions(+), 45 deletions(-) diff --git a/Sources/Version-Control/Services/Models/Client/Branch.swift b/Sources/Version-Control/Services/Models/Client/Branch.swift index e625bccd..4e6608f6 100644 --- a/Sources/Version-Control/Services/Models/Client/Branch.swift +++ b/Sources/Version-Control/Services/Models/Client/Branch.swift @@ -411,4 +411,4 @@ public struct Branch { throw error } } -} +} // swiftlint:disable:this file_length diff --git a/Sources/Version-Control/Services/Models/Client/Config.swift b/Sources/Version-Control/Services/Models/Client/Config.swift index 7e4b92c4..9006535b 100644 --- a/Sources/Version-Control/Services/Models/Client/Config.swift +++ b/Sources/Version-Control/Services/Models/Client/Config.swift @@ -620,4 +620,4 @@ public struct Config { try ShellClient().run(gitCommand) } -} +} // swiftlint:disable:this file_length diff --git a/Sources/Version-Control/Services/Models/Client/LFS.swift b/Sources/Version-Control/Services/Models/Client/LFS.swift index 5397d8a1..e0d8bdba 100644 --- a/Sources/Version-Control/Services/Models/Client/LFS.swift +++ b/Sources/Version-Control/Services/Models/Client/LFS.swift @@ -53,13 +53,16 @@ public struct LFS { /// Install Git LFS (Large File Storage) hooks in a Git repository. /// - /// Git LFS is an extension for handling large files in a Git repository. This function installs Git LFS hooks in the repository, which are scripts that run at various points in the Git workflow to manage large files. + /// Git LFS is an extension for handling large files in a Git repository. \ + /// This function installs Git LFS hooks in the repository, + /// which are scripts that run at various points in the Git workflow to manage large files. /// /// - Parameters: /// - directoryURL: The URL of the Git repository where LFS hooks should be installed. /// - force: A flag indicating whether to force the installation of hooks if they already exist. /// - /// - Throws: An error if there was an issue installing LFS hooks, if the provided repository URL is invalid, or if the hooks installation is forced and fails. + /// - Throws: An error if there was an issue installing LFS hooks, \ + /// if the provided repository URL is invalid, or if the hooks installation is forced and fails. /// /// - Example: /// ```swift @@ -73,9 +76,12 @@ public struct LFS { /// } /// ``` /// - /// - Note: If `force` is set to `true`, the function will forcibly install LFS hooks even if they already exist in the repository. + /// - Note: If `force` is set to `true`, \ + /// the function will forcibly install LFS hooks even if they already exist in the repository. /// - /// - Important: Installing Git LFS hooks is typically required to properly manage large files in a Git repository. Make sure to call this function if your repository uses Git LFS for large file storage. + /// - Important: Installing Git LFS hooks is typically required to properly manage \ + /// large files in a Git repository. \ + /// Make sure to call this function if your repository uses Git LFS for large file storage. public func installLFSHooks(directoryURL: URL, force: Bool) throws { var args = ["lfs", "install"] @@ -90,13 +96,16 @@ public struct LFS { /// Check whether the Git repository is configured to track any paths with Git LFS (Large File Storage). /// - /// Git LFS is an extension for handling large files in a Git repository, and this function helps you determine if the repository is configured to track any paths using Git LFS within its configuration. + /// Git LFS is an extension for handling large files in a Git repository, + /// and this function helps you determine if the repository is configured to track + /// any paths using Git LFS within its configuration. /// /// - Parameter directoryURL: The URL of the Git repository. /// /// - Returns: `true` if the repository is configured to track paths with Git LFS; otherwise, `false`. /// - /// - Throws: An error if there was an issue querying the Git repository or if the provided repository URL is invalid. + /// - Throws: An error if there was an issue querying the Git repository or \ + /// if the provided repository URL is invalid. /// /// - Example: /// ```swift @@ -114,7 +123,10 @@ public struct LFS { /// } /// ``` /// - /// - Important: This function checks whether the Git repository is configured to track any paths with Git LFS in its configuration. It does not specify which paths are tracked; use `isTrackedByLFS` to check if specific files are tracked. + /// - Important: This function checks whether the Git repository is configured to track \ + /// any paths with Git LFS in its configuration. \ + /// It does not specify which paths are tracked; use `isTrackedByLFS` \ + /// to check if specific files are tracked. public func isUsingLFS(directoryURL: URL) throws -> Bool { let result = try ShellClient.live().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git lfs track" @@ -127,7 +139,9 @@ public struct LFS { /// Check whether the Git repository is configured to track a specific file with Git LFS (Large File Storage). /// - /// Git LFS is an extension for handling large files in a Git repository, and this function helps you determine if a particular file is tracked by Git LFS within the repository's configuration. + /// Git LFS is an extension for handling large files in a Git repository, + /// and this function helps you determine if a particular file is tracked by + /// Git LFS within the repository's configuration. /// /// - Parameters: /// - directoryURL: The URL of the Git repository. @@ -154,7 +168,9 @@ public struct LFS { /// } /// ``` /// - /// - Important: This function checks whether a specific file within the Git repository is tracked by Git LFS in the repository's configuration. Ensure that the provided path is valid and that the repository is configured to use Git LFS. + /// - Important: This function checks whether a specific file within the Git repository \ + /// is tracked by Git LFS in the repository's configuration. \ + /// Ensure that the provided path is valid and that the repository is configured to use Git LFS. public func isTrackedByLFS(directoryURL: URL, path: String) throws -> Bool { let result = try ShellClient.live().run( @@ -215,7 +231,9 @@ public struct LFS { /// } /// ``` /// - /// - Important: This function checks which files within the specified relative paths are not tracked by Git LFS in the Git repository. Ensure that the provided paths are valid and that the repository is configured to use Git LFS. + /// - Important: This function checks which files within the specified relative \ + /// paths are not tracked by Git LFS in the Git repository. \ + /// Ensure that the provided paths are valid and that the repository is configured to use Git LFS. public func filesNotTrackedByLFS(directoryURL: URL, filePaths: [String]) throws -> [String] { var filesNotTrackedByGitLFS: [String] = [] diff --git a/Sources/Version-Control/Services/Models/Client/Reflog.swift b/Sources/Version-Control/Services/Models/Client/Reflog.swift index f5720a2a..5c9389a8 100644 --- a/Sources/Version-Control/Services/Models/Client/Reflog.swift +++ b/Sources/Version-Control/Services/Models/Client/Reflog.swift @@ -40,7 +40,7 @@ import Foundation /// - Returns: An array of branch names that were recently checked out or renamed, with a maximum count of `limit`. public func getRecentBranches(directoryURL: URL, limit: Int) throws -> [String] { // Regular expression to match branch checkout and rename events in Git log. - let regexPattern = ".*? (renamed|checkout)(?:: moving from|\\s*) (?:refs/heads/|\\s*)(.*?) to (?:refs/heads/|\\s*)(.*?)$" + let regexPattern = ".*? (renamed|checkout)(?:: moving from|\\s*) (?:refs/heads/|\\s*)(.*?) to (?:refs/heads/|\\s*)(.*?)$" // swiftlint:disable:this line_length let regex = try NSRegularExpression(pattern: regexPattern, options: []) diff --git a/Sources/Version-Control/Services/Models/Client/Refs.swift b/Sources/Version-Control/Services/Models/Client/Refs.swift index a0fe35b4..25eac47b 100644 --- a/Sources/Version-Control/Services/Models/Client/Refs.swift +++ b/Sources/Version-Control/Services/Models/Client/Refs.swift @@ -15,7 +15,9 @@ public struct Refs { /// Format a local branch name as a Git ref syntax. /// - /// In Git, branch names are often represented as refs, and this function converts a local branch name into the corresponding ref syntax. It ensures that situations where the branch name is ambiguous are handled correctly. + /// In Git, branch names are often represented as refs, + /// and this function converts a local branch name into the corresponding ref syntax. \ + /// It ensures that situations where the branch name is ambiguous are handled correctly. /// /// - Parameter name: The local branch name to format. /// @@ -40,7 +42,8 @@ public struct Refs { // This ensures we format it correctly. return "refs/\(name)" } else if !name.starts(with: "refs/heads/") { - // By default, Git drops the `heads` prefix unless necessary. Include it to ensure the ref is fully qualified. + // By default, Git drops the `heads` prefix unless necessary. + // Include it to ensure the ref is fully qualified. return "refs/heads/\(name)" } else { return name @@ -49,15 +52,20 @@ public struct Refs { /// Read the canonical ref pointed to by a symbolic ref in the Git repository. /// - /// Symbolic refs in Git are references that point to other references, similar to symbolic links in a filesystem. They provide an additional layer of indirection. This function allows you to resolve a symbolic ref to its canonical ref, providing you with the actual reference it points to. + /// Symbolic refs in Git are references that point to other references, similar to symbolic links in a filesystem. \ + /// They provide an additional layer of indirection. \ + /// This function allows you to resolve a symbolic ref to its canonical ref, + /// providing you with the actual reference it points to. /// /// - Parameters: /// - directoryURL: The URL of the Git repository where the symbolic ref should be resolved. /// - ref: The symbolic ref to resolve. /// - /// - Throws: An error if there is a problem accessing the Git repository or executing the Git command to read the symbolic ref. + /// - Throws: An error if there is a problem accessing the Git repository or \ + /// executing the Git command to read the symbolic ref. /// - /// - Returns: The canonical ref pointed to by the symbolic ref, or `nil` if the symbolic ref cannot be found or is not a symbolic ref. + /// - Returns: The canonical ref pointed to by the symbolic ref, or \ + /// `nil` if the symbolic ref cannot be found or is not a symbolic ref. /// /// - Example: /// ```swift @@ -76,11 +84,14 @@ public struct Refs { /// ``` /// /// - Note: - /// - The function executes the Git command `git symbolic-ref -q ` to read the canonical ref pointed to by the symbolic ref. + /// - The function executes the Git command `git symbolic-ref -q ` to \ + /// read the canonical ref pointed to by the symbolic ref. /// - /// - Warning: Ensure that the provided `directoryURL` points to a valid Git repository directory. Failure to do so may result in errors or incorrect results. + /// - Warning: Ensure that the provided `directoryURL` points to a valid Git repository directory. \ + /// Failure to do so may result in errors or incorrect results. /// - /// - Returns: The canonical ref pointed to by the symbolic ref, or `nil` if the symbolic ref cannot be found or is not a symbolic ref. + /// - Returns: The canonical ref pointed to by the symbolic ref, or \ + /// `nil` if the symbolic ref cannot be found or is not a symbolic ref. public func getSymbolicRef(directoryURL: URL, ref: String) throws -> String? { let result = try ShellClient.live().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git symbolic-ref -q \(ref)" diff --git a/Sources/Version-Control/Services/Models/Client/Remote.swift b/Sources/Version-Control/Services/Models/Client/Remote.swift index c2025fd0..fcf79686 100644 --- a/Sources/Version-Control/Services/Models/Client/Remote.swift +++ b/Sources/Version-Control/Services/Models/Client/Remote.swift @@ -11,12 +11,14 @@ import Foundation /// Retrieve a list of Git remotes associated with a local repository. /// -/// This function lists the Git remotes configured for a given local Git repository. It returns an array of `GitRemote` objects, each representing a remote repository with a name and URL. +/// This function lists the Git remotes configured for a given local Git repository. \ +/// It returns an array of `GitRemote` objects, each representing a remote repository with a name and URL. /// /// - Parameters: /// - directoryURL: The URL of the local Git repository for which to retrieve the remotes. /// -/// - Throws: An error if there is a problem accessing the Git repository or executing the Git command to retrieve remotes. +/// - Throws: An error if there is a problem accessing the Git repository or \ +/// executing the Git command to retrieve remotes. /// /// - Returns: An array of `GitRemote` objects representing the Git remotes configured for the local repository. /// @@ -66,14 +68,18 @@ public func getRemotes(directoryURL: URL) throws -> [GitRemote] { /// Add a new Git remote repository with the specified name and URL. /// -/// Use this function to add a new Git remote repository to the local repository, providing a name for the remote and its URL. If the remote repository with the given name already exists, the function updates the URL of the existing remote to the new URL. +/// Use this function to add a new Git remote repository to the local repository, +/// providing a name for the remote and its URL. \ +/// If the remote repository with the given name already exists, +/// the function updates the URL of the existing remote to the new URL. /// /// - Parameters: /// - directoryURL: The URL of the local Git repository where the remote will be added. /// - name: The name for the new remote repository. /// - url: The URL of the remote Git repository. /// -/// - Throws: An error if there is a problem accessing the Git repository or executing the Git command to add the remote repository. +/// - Throws: An error if there is a problem accessing the Git repository or \ +/// executing the Git command to add the remote repository. /// /// - Returns: A `GitRemote` object representing the added remote repository with its name and URL. /// @@ -92,9 +98,13 @@ public func getRemotes(directoryURL: URL) throws -> [GitRemote] { /// ``` /// /// - Note: -/// - The function executes the Git command `git remote add ` to add or update a remote repository. If a remote with the specified name already exists, it updates the URL to the new URL. +/// - The function executes the Git command `git remote add ` \ +/// to add or update a remote repository. \ +/// If a remote with the specified name already exists, it updates the URL to the new URL. /// -/// - Warning: Be cautious when passing user-provided remote names and URLs to this function, as it may execute arbitrary Git commands. Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. +/// - Warning: Be cautious when passing user-provided remote names and URLs to this function, \ +/// as it may execute arbitrary Git commands. \ +/// Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. /// /// - Returns: A `GitRemote` object representing the added or updated remote repository with its name and URL. public func addRemote(directoryURL: URL, name: String, url: String) throws -> GitRemote? { @@ -114,7 +124,8 @@ public func addRemote(directoryURL: URL, name: String, url: String) throws -> Gi /// - directoryURL: The URL of the local Git repository. /// - name: The name of the remote repository to remove. /// -/// - Throws: An error if there is a problem accessing the Git repository or executing the Git command to remove the remote repository. +/// - Throws: An error if there is a problem accessing the Git repository or \ +/// executing the Git command to remove the remote repository. /// /// - Example: /// ```swift @@ -130,9 +141,13 @@ public func addRemote(directoryURL: URL, name: String, url: String) throws -> Gi /// ``` /// /// - Note: -/// - The function executes the Git command `git remote remove ` to remove the remote repository. If the remote with the specified name does not exist, it does not raise an error. +/// - The function executes the Git command `git remote remove ` to \ +/// remove the remote repository. \ +/// If the remote with the specified name does not exist, it does not raise an error. /// -/// - Warning: Be cautious when passing user-provided remote names to this function, as it may execute arbitrary Git commands. Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. +/// - Warning: Be cautious when passing user-provided remote names to this function, \ +/// as it may execute arbitrary Git commands. \ +/// Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. public func removeRemote(directoryURL: URL, name: String) throws { try ShellClient().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git remote remove \(name)" @@ -141,14 +156,16 @@ public func removeRemote(directoryURL: URL, name: String) throws { /// Change the URL of a Git remote repository by its name. /// -/// Use this function to update the URL of a Git remote repository specified by its remote name. The function executes a Git command to change the URL of the specified remote repository. +/// Use this function to update the URL of a Git remote repository specified by its remote name. \ +/// The function executes a Git command to change the URL of the specified remote repository. /// /// - Parameters: /// - directoryURL: The URL of the local Git repository. /// - name: The name of the remote repository for which to change the URL. /// - url: The new URL to set for the remote Git repository. /// -/// - Throws: An error if there is a problem accessing the Git repository or executing the Git command to change the remote's URL. +/// - Throws: An error if there is a problem accessing the Git repository or \ +/// executing the Git command to change the remote's URL. /// /// - Returns: `true` if the URL was successfully updated; otherwise, `false`. /// @@ -170,10 +187,13 @@ public func removeRemote(directoryURL: URL, name: String) throws { /// ``` /// /// - Note: -/// - The function executes the Git command `git remote set-url ` to change the URL of the specified remote repository. +/// - The function executes the Git command `git remote set-url ` to\ +/// change the URL of the specified remote repository. /// - It returns `true` if the URL was successfully updated, and `false` otherwise. /// -/// - Warning: Be cautious when passing user-provided remote names and URLs to this function, as it may execute arbitrary Git commands. Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. +/// - Warning: Be cautious when passing user-provided remote names and URLs to this function, \ +/// as it may execute arbitrary Git commands. \ +/// Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. public func setRemoteURL(directoryURL: URL, name: String, url: String) throws -> Bool { try ShellClient().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git remote set-url \(name) \(url)" @@ -184,15 +204,18 @@ public func setRemoteURL(directoryURL: URL, name: String, url: String) throws -> /// Get the URL associated with a Git remote repository by its name. /// -/// Use this function to retrieve the URL of a Git remote repository specified by its remote name. The function executes a Git command to obtain the URL of the specified remote repository. +/// Use this function to retrieve the URL of a Git remote repository specified by its remote name. \ +/// The function executes a Git command to obtain the URL of the specified remote repository. /// /// - Parameters: /// - directoryURL: The URL of the local Git repository. /// - name: The name of the remote repository for which to fetch the URL. /// -/// - Throws: An error if there is a problem accessing the Git repository or executing the Git command to retrieve the remote's URL. +/// - Throws: An error if there is a problem accessing the Git repository or \ +/// executing the Git command to retrieve the remote's URL. /// -/// - Returns: A string representing the URL of the remote Git repository, or `nil` if the specified remote repository could not be found. +/// - Returns: A string representing the URL of the remote Git repository, \ +/// or `nil` if the specified remote repository could not be found. /// /// - Example: /// ```swift @@ -211,10 +234,13 @@ public func setRemoteURL(directoryURL: URL, name: String, url: String) throws -> /// ``` /// /// - Note: -/// - The function executes the Git command `git remote get-url ` to retrieve the URL of the specified remote repository. +/// - The function executes the Git command `git remote get-url ` to \ +/// retrieve the URL of the specified remote repository. /// - If the specified remote repository does not exist, the function returns `nil`. /// -/// - Warning: Be cautious when passing user-provided remote names to this function, as it may execute arbitrary Git commands. Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. +/// - Warning: Be cautious when passing user-provided remote names to this function, \ +/// as it may execute arbitrary Git commands. \ +/// Ensure that input is properly validated and sanitized to prevent command injection vulnerabilities. public func getRemoteURL(directoryURL: URL, name: String) throws -> String? { let result = try ShellClient.live().run( "cd \(directoryURL.relativePath.escapedWhiteSpaces());git remote get-url \(name)" @@ -262,7 +288,9 @@ public func updateRemoteHEAD(directoryURL: URL, remote: IRemote) throws { /// Get the name of the HEAD branch in a remote Git repository. /// -/// Use this function to retrieve the name of the HEAD branch in a remote Git repository associated with a specific remote name. The function constructs the reference path for the remote's HEAD and retrieves it using the `Refs` utility. +/// Use this function to retrieve the name of the HEAD branch in a remote Git repository +/// associated with a specific remote name. \ +/// The function constructs the reference path for the remote's HEAD and retrieves it using the `Refs` utility. /// /// - Parameters: /// - directoryURL: The URL of the local Git repository. @@ -306,7 +334,10 @@ public func getRemoteHEAD(directoryURL: URL, remote: String) throws -> String? { /// Get the HEAD branch reference from a remote Git repository hosted at the specified URL. /// -/// Use this function to retrieve the reference of the HEAD branch from a remote Git repository hosted at the given URL. The function runs a Git command to fetch the HEAD reference information and processes the output to extract the branch name. +/// Use this function to retrieve the reference of the HEAD branch from a remote Git repository +/// hosted at the given URL. \ +/// The function runs a Git command to fetch the HEAD reference information and processes +/// the output to extract the branch name. /// /// - Parameters: /// - url: The URL of the remote Git repository from which to fetch the HEAD reference. @@ -339,7 +370,8 @@ public func getRemoteHEAD(url: String) throws -> String { /// Get a list of remote branches from a Git repository hosted at the specified URL. /// -/// Use this function to retrieve a list of remote branch names from a Git repository hosted at the given URL. The function runs a Git command to fetch remote branch information and processes the output to extract branch names. +/// Use this function to retrieve a list of remote branch names from a Git repository hosted at the given URL. \ +/// The function runs a Git command to fetch remote branch information and processes the output to extract branch names. /// /// - Parameters: /// - url: The URL of the remote Git repository from which to fetch branch information. @@ -367,4 +399,4 @@ public func getRemoteBranch(url: String) throws -> [String] { return try ShellClient.live().run( "git ls-remote \(url) --h --sort origin \"refs/heads/*\" | cut -f2 | sed 's!^refs/heads/!!'" ).components(separatedBy: "\n").filter { !$0.isEmpty } -} +} // swiftlint:disable:this file_length diff --git a/Sources/Version-Control/Services/Models/ManualConflictResolution.swift b/Sources/Version-Control/Services/Models/ManualConflictResolution.swift index c39e050c..ad920a5b 100644 --- a/Sources/Version-Control/Services/Models/ManualConflictResolution.swift +++ b/Sources/Version-Control/Services/Models/ManualConflictResolution.swift @@ -13,6 +13,6 @@ import Foundation // as `--ours` and `--theirs` to git checkout. Please be careful // when modifying this type. public enum ManualConflictResolution: String { - case theirs = "theirs" - case ours = "ours" + case theirs = "theirs" // swiftlint:disable:this redundant_string_enum_value + case ours = "ours" // swiftlint:disable:this redundant_string_enum_value }