From ff840f012d94ff6d328cbd952bfc399cd5c8177f Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Sun, 8 Oct 2023 12:00:47 +0100 Subject: [PATCH] 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()