diff --git a/Package.swift b/Package.swift index 0da9a08f..34e6d0c9 100644 --- a/Package.swift +++ b/Package.swift @@ -27,6 +27,6 @@ let package = Package( dependencies: [ "Version-Control" ] - ), + ) ] ) diff --git a/Sources/Version-Control/Base/Actions/GitHub/GitHubActions.swift b/Sources/Version-Control/Base/Actions/GitHub/GitHubActions.swift index 37b77a89..91918946 100644 --- a/Sources/Version-Control/Base/Actions/GitHub/GitHubActions.swift +++ b/Sources/Version-Control/Base/Actions/GitHub/GitHubActions.swift @@ -14,14 +14,14 @@ public enum GitHubViewType: String { } public struct GitHubActions { - + internal func getBranchName(directoryURL: URL) throws -> String { return try Branch().getCurrentBranch(directoryURL: directoryURL) } - + internal func getCurrentRepositoryGitHubURL(directoryURL: URL) throws -> String { let remoteUrls: [GitRemote] = try Remote().getRemotes(directoryURL: directoryURL) - + for remote in remoteUrls { if remote.url.contains("github.com") { return remote.url @@ -29,7 +29,7 @@ public struct GitHubActions { } return "" } - + /// Open a specific branch of a GitHub repository in a web browser. /// /// This function constructs the URL for a specific branch of a GitHub repository based on the provided parameters and opens it in the default web browser. @@ -61,10 +61,10 @@ public struct GitHubActions { } let url = URL(string: "\(htmlURL)/\(viewType)/\(encodedBranchName)") - + NSWorkspace.shared.open(url!) } - + /// Open the GitHub issue creation page for the current repository in a web browser. /// /// This function constructs the URL for creating a new issue in the current repository on GitHub and opens it in the default web browser. @@ -83,9 +83,9 @@ public struct GitHubActions { /// } public func openIssueCreationOnGitHub(directoryURL: URL) throws { let repositoryURL = try getCurrentRepositoryGitHubURL(directoryURL: directoryURL) - + let url = URL(string: "\(repositoryURL)/issues/new/choose") - + NSWorkspace.shared.open(url!) } } diff --git a/Sources/Version-Control/Base/Commands/Apply.swift b/Sources/Version-Control/Base/Commands/Apply.swift index e918e4c6..cb2bd38c 100644 --- a/Sources/Version-Control/Base/Commands/Apply.swift +++ b/Sources/Version-Control/Base/Commands/Apply.swift @@ -47,7 +47,7 @@ public struct Apply { let info = oldFile.stdout.split(separator: "\t", maxSplits: 1, omittingEmptySubsequences: true)[0] - let components = info.split(separator: " ", + let components = info.split(separator: " ", maxSplits: 3, omittingEmptySubsequences: true) let mode = components[0] diff --git a/Sources/Version-Control/Base/Commands/Branch.swift b/Sources/Version-Control/Base/Commands/Branch.swift index bb874b0e..6fa058e5 100644 --- a/Sources/Version-Control/Base/Commands/Branch.swift +++ b/Sources/Version-Control/Base/Commands/Branch.swift @@ -198,7 +198,7 @@ public struct Branch { "HEAD", "-n", "2500", - "--", + "--" ] let result = try GitShell().git(args: args, @@ -262,7 +262,7 @@ public struct Branch { "--after=\(afterDate.timeIntervalSince1970)", "--pretty=%H %gd %gs", "--grep-reflog=checkout: moving from .* to .*$", - "--", + "--" ] let result = try GitShell().git(args: args, @@ -307,20 +307,20 @@ public struct Branch { startPoint: String?, noTrack: Bool = false) throws { var args: [String] - + if let startPoint = startPoint { args = ["branch", name, startPoint] } else { args = ["branch", name] } - + // If we're branching directly from a remote branch, we don't want to track it // Tracking it will make the rest of the desktop think we want to push to that // remote branch's upstream (which would likely be the upstream of the fork) if noTrack { args.append("--no-track") } - + try GitShell().git(args: args, path: directoryURL, name: "createBranch") @@ -362,12 +362,12 @@ public struct Branch { "branch", "-D", branchName] - + /// Prepare and execute the Git command to delete the local branch using a ShellClient. try GitShell().git(args: args, path: directoryURL, name: "deleteLocalBranch") - + // Return true to indicate that the branch deletion was attempted. return true } diff --git a/Sources/Version-Control/Base/Commands/Checkout-Index.swift b/Sources/Version-Control/Base/Commands/Checkout-Index.swift index e4f4d18e..bc3ac568 100644 --- a/Sources/Version-Control/Base/Commands/Checkout-Index.swift +++ b/Sources/Version-Control/Base/Commands/Checkout-Index.swift @@ -9,7 +9,7 @@ import Foundation public struct CheckoutIndex { - public init(){} + public init() {} public func checkoutIndex(directoryURL: URL, paths: [String]) async throws { diff --git a/Sources/Version-Control/Base/Commands/Checkout.swift b/Sources/Version-Control/Base/Commands/Checkout.swift index e997aa12..0c3488ac 100644 --- a/Sources/Version-Control/Base/Commands/Checkout.swift +++ b/Sources/Version-Control/Base/Commands/Checkout.swift @@ -34,7 +34,7 @@ public struct GitCheckout { if enableRecurseSubmodulesFlag { if branch.type == BranchType.remote { return baseArgs + [ - branch.name, + branch.name, "-b", branch.nameWithoutRemote, "--recurse-submodules", @@ -50,7 +50,7 @@ public struct GitCheckout { } else { if branch.type == BranchType.remote { return baseArgs + [ - branch.name, + branch.name, "-b", branch.nameWithoutRemote, "--" diff --git a/Sources/Version-Control/Base/Commands/Cherry-Pick.swift b/Sources/Version-Control/Base/Commands/Cherry-Pick.swift index d1c81baa..2ac080db 100644 --- a/Sources/Version-Control/Base/Commands/Cherry-Pick.swift +++ b/Sources/Version-Control/Base/Commands/Cherry-Pick.swift @@ -161,11 +161,11 @@ public struct CherryPick { let headPath = directoryURL.appendingPathComponent(".git/sequencer/head").path let todoPath = directoryURL.appendingPathComponent(".git/sequencer/todo").path - guard let abortSafetySha = try? String(contentsOfFile: abortSafetyPath, + guard let abortSafetySha = try? String(contentsOfFile: abortSafetyPath, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines), - let headSha = try? String(contentsOfFile: headPath, + let headSha = try? String(contentsOfFile: headPath, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines), - let remainingPicks = try? String(contentsOfFile: todoPath, + let remainingPicks = try? String(contentsOfFile: todoPath, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines) else { print("Could not read file") return nil diff --git a/Sources/Version-Control/Base/Commands/Clone.swift b/Sources/Version-Control/Base/Commands/Clone.swift index f834d538..d651a0bd 100644 --- a/Sources/Version-Control/Base/Commands/Clone.swift +++ b/Sources/Version-Control/Base/Commands/Clone.swift @@ -41,7 +41,7 @@ public struct Clone { func clone(directoryURL: URL, path: String, - options: CloneOptions, + options: CloneOptions, progressCallback: ((ICloneProgress) -> Void)? = nil) async throws { // let env = try await envForRemoteOperation(options.account, url) let defaultBranch = options.defaultBranch ?? (DefaultBranch().getDefaultBranch()) diff --git a/Sources/Version-Control/Base/Commands/Diff-Check.swift b/Sources/Version-Control/Base/Commands/Diff-Check.swift index 77284f01..db852f2f 100644 --- a/Sources/Version-Control/Base/Commands/Diff-Check.swift +++ b/Sources/Version-Control/Base/Commands/Diff-Check.swift @@ -10,7 +10,7 @@ import Foundation public struct DiffCheck { - public init(){} + public init() {} /// Matches a line reporting a leftover conflict marker /// and captures the name of the file @@ -24,7 +24,6 @@ public struct DiffCheck { path: directoryURL, name: #function, options: IGitExecutionOptions(successExitCodes: Set([0, 2]))) - let captures = Regex().getCaptures(text: output.stdout, expression: try NSRegularExpression(pattern: pattern, diff --git a/Sources/Version-Control/Base/Commands/Diff.swift b/Sources/Version-Control/Base/Commands/Diff.swift index a67f86dc..f6ef4a22 100644 --- a/Sources/Version-Control/Base/Commands/Diff.swift +++ b/Sources/Version-Control/Base/Commands/Diff.swift @@ -628,8 +628,8 @@ public struct GitDiff { let fullPath = directoryURL.appendingPathComponent(path).path let url = try Config().getConfigValue(directoryURL: directoryURL, name: "submodule.\(path).url") - var oldSHA: String? = nil - var newSHA: String? = nil + var oldSHA: String? + var newSHA: String? if status.commitChanged || file.status.kind == .new || diff --git a/Sources/Version-Control/Base/Commands/GitLog.swift b/Sources/Version-Control/Base/Commands/GitLog.swift index d7eeba76..547f99ac 100644 --- a/Sources/Version-Control/Base/Commands/GitLog.swift +++ b/Sources/Version-Control/Base/Commands/GitLog.swift @@ -34,7 +34,7 @@ public struct GitLog { return nil } - func mapStatus(rawStatus: String, + func mapStatus(rawStatus: String, oldPath: String?, srcMode: String, dstMode: String) -> AppFileStatus { @@ -63,12 +63,12 @@ public struct GitLog { oldPath: oldPath ?? "", submoduleStatus: submoduleStatus) default: - if status.range(of: #"R[0-9]+"#, options: .regularExpression) != nil, + if status.range(of: #"R[0-9]+"#, options: .regularExpression) != nil, let oldPath = oldPath { return CopiedOrRenamedFileStatus(kind: .renamed, oldPath: oldPath, submoduleStatus: submoduleStatus) - } else if status.range(of: #"C[0-9]+"#, options: .regularExpression) != nil, + } else if status.range(of: #"C[0-9]+"#, options: .regularExpression) != nil, let oldPath = oldPath { return CopiedOrRenamedFileStatus(kind: .copied, oldPath: oldPath, @@ -126,7 +126,7 @@ public struct GitLog { args += additionalArgs args.append("--") - let result = try GitShell().git(args: args, + let result = try GitShell().git(args: args, path: directoryURL, name: #function) @@ -178,7 +178,7 @@ public struct GitLog { "--format=format:", "--numstat", "-z", - "--", + "--" ] let result = try GitShell().git(args: args, @@ -214,7 +214,7 @@ public struct GitLog { the total number of lines added and deleted. It returns the parsed information in a tuple. */ - func parseRawLogWithNumstat(stdout: String, + func parseRawLogWithNumstat(stdout: String, sha: String, parentCommitish: String) throws -> IChangesetData { var files = [CommittedFileChange]() diff --git a/Sources/Version-Control/Base/Commands/LFS.swift b/Sources/Version-Control/Base/Commands/LFS.swift index f5808e0a..37e53b69 100644 --- a/Sources/Version-Control/Base/Commands/LFS.swift +++ b/Sources/Version-Control/Base/Commands/LFS.swift @@ -195,7 +195,7 @@ public struct LFS { // // README.md: filter: unspecified let lfsFilterRegex = try! NSRegularExpression(pattern: ": filter: lfs", options: []) - let range = NSRange(result.stdout.startIndex.. Void)? = nil) throws -> [String] { let divergentPathArgs = getDefaultPullDivergentBranchArguments(directoryURL: directoryURL) - var args = gitNetworkArguments + gitRebaseArguments + ["pull"] + divergentPathArgs args.append("--recurse-submodules") diff --git a/Sources/Version-Control/Base/Commands/Push.swift b/Sources/Version-Control/Base/Commands/Push.swift index 0600f1a4..bbea51ca 100644 --- a/Sources/Version-Control/Base/Commands/Push.swift +++ b/Sources/Version-Control/Base/Commands/Push.swift @@ -21,7 +21,6 @@ public struct Push { public init() {} - public func push(directoryURL: URL, remote: IRemote, localBranch: String, diff --git a/Sources/Version-Control/Base/Commands/Rebase.swift b/Sources/Version-Control/Base/Commands/Rebase.swift index 9d7e5676..fe138b69 100644 --- a/Sources/Version-Control/Base/Commands/Rebase.swift +++ b/Sources/Version-Control/Base/Commands/Rebase.swift @@ -9,7 +9,7 @@ import Foundation public struct Rebase { - public init(){} + public init() {} func getRebaseInternalState(directoryURL: URL) throws -> RebaseInternalState? { let rebaseMergePath = directoryURL.appendingPathComponent(".git/rebase-merge") @@ -83,7 +83,7 @@ public struct Rebase { if let commits = try RevList().getCommitsBetweenCommits(directoryURL: directoryURL, baseBranchSha: baseBranch.tip!.sha, targetBranchSha: targetBranch.tip!.sha) { - options = configureOptionsForRebase(options: baseOptions, + options = configureOptionsForRebase(options: baseOptions, progress: RebaseProgressOptions(commits: commits, progressCallback: progressCallback)) } else { @@ -135,7 +135,7 @@ public struct Rebase { func parseRebaseResult(result: IGitResult) -> RebaseResult { if result.exitCode == 0 { - if result.stdout.trimmingCharacters(in: .whitespacesAndNewlines).range(of: #"^Current branch [^ ]+ is up to date.$"#, + if result.stdout.trimmingCharacters(in: .whitespacesAndNewlines).range(of: #"^Current branch [^ ]+ is up to date.$"#, options: .regularExpression) != nil { return .alreadyUpToDate } @@ -153,7 +153,7 @@ public struct Rebase { return .error } - func configureOptionsForRebase(options: IGitExecutionOptions, + func configureOptionsForRebase(options: IGitExecutionOptions, progress: RebaseProgressOptions?) -> IGitExecutionOptions { guard let progress = progress else { return options @@ -165,7 +165,7 @@ public struct Rebase { newOptions.processCallback = { output in // Assuming output is a string containing the content of stderr var stdout = "" - + let stdoutPipe = Pipe() output.standardOutput = stdoutPipe @@ -227,7 +227,7 @@ public struct Rebase { return .aborted } - options = configureOptionsForRebase(options: options, + options = configureOptionsForRebase(options: options, progress: RebaseProgressOptions(commits: snapshot.commits, progressCallback: progressCallback)) } @@ -249,7 +249,6 @@ public struct Rebase { return parseRebaseResult(result: result) } - func rebaseInteractive(directoryURL: URL, pathOfGeneratedTodo: String, lastRetainedCommitRef: String?, @@ -262,7 +261,7 @@ public struct Rebase { expectedErrors: [.RebaseConflicts]) if let progressCallback = progressCallback, let commits = commits { - let context = RebaseProgressOptions(commits: commits, + let context = RebaseProgressOptions(commits: commits, progressCallback: progressCallback) baseOptions = configureOptionsForRebase(options: baseOptions, progress: context) } else { @@ -273,9 +272,9 @@ public struct Rebase { let ref = lastRetainedCommitRef ?? "--root" let sequenceEditorCommand = "cat \"\(pathOfGeneratedTodo)\" >" - let result = try GitShell().git(args: ["-c", + let result = try GitShell().git(args: ["-c", "sequence.editor=\(sequenceEditorCommand)", - "rebase", + "rebase", "-i", ref], path: directoryURL, diff --git a/Sources/Version-Control/Base/Commands/Reflog.swift b/Sources/Version-Control/Base/Commands/Reflog.swift index 3ffd31fc..2e4f607d 100644 --- a/Sources/Version-Control/Base/Commands/Reflog.swift +++ b/Sources/Version-Control/Base/Commands/Reflog.swift @@ -102,7 +102,6 @@ public struct Reflog { return Array(branchNames) } - private let noCommitsOnBranchRe = "fatal: your current branch '.*' does not have any commits yet" /// Get a distinct list of branches that have been checked out after a specific date in the Git repository. @@ -187,5 +186,4 @@ public struct Reflog { return checkouts } - } diff --git a/Sources/Version-Control/Base/Commands/Refs.swift b/Sources/Version-Control/Base/Commands/Refs.swift index e7c4b9d4..621c2ef3 100644 --- a/Sources/Version-Control/Base/Commands/Refs.swift +++ b/Sources/Version-Control/Base/Commands/Refs.swift @@ -92,7 +92,7 @@ public struct Refs { /// /// - 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, + public func getSymbolicRef(directoryURL: URL, ref: String) throws -> String? { let result = try GitShell().git(args: ["symbolic-ref", "-q", ref], diff --git a/Sources/Version-Control/Base/Commands/Revert.swift b/Sources/Version-Control/Base/Commands/Revert.swift index d8ac6b23..34a4b141 100644 --- a/Sources/Version-Control/Base/Commands/Revert.swift +++ b/Sources/Version-Control/Base/Commands/Revert.swift @@ -24,7 +24,7 @@ public struct GitRevert { args.append(commit.sha) - var opts: IGitExecutionOptions? = nil + var opts: IGitExecutionOptions? if let progressCallback = progressCallback { opts = try FromProcess().executionOptionsWithProgress( options: IGitExecutionOptions(trackLFSProgress: true), diff --git a/Sources/Version-Control/Base/Commands/Squash.swift b/Sources/Version-Control/Base/Commands/Squash.swift index 409b0800..007917ca 100644 --- a/Sources/Version-Control/Base/Commands/Squash.swift +++ b/Sources/Version-Control/Base/Commands/Squash.swift @@ -37,7 +37,7 @@ public struct GitSquash { do { guard toSquash.count > 0 else { - throw NSError(domain: "Squash Error", + throw NSError(domain: "Squash Error", code: 1, userInfo: [NSLocalizedDescriptionKey: "No commits provided to squash."]) } @@ -55,7 +55,7 @@ public struct GitSquash { skip: nil) guard !commits.isEmpty else { - throw NSError(domain: "Squash Error", + throw NSError(domain: "Squash Error", code: 3, userInfo: [NSLocalizedDescriptionKey: "Could not find commits in log for last retained commit ref."]) } diff --git a/Sources/Version-Control/Base/Commands/Stash.swift b/Sources/Version-Control/Base/Commands/Stash.swift index bed43075..be8b6557 100644 --- a/Sources/Version-Control/Base/Commands/Stash.swift +++ b/Sources/Version-Control/Base/Commands/Stash.swift @@ -138,7 +138,7 @@ public struct Stash { branch: Any, untrackedFilesToStage: [WorkingDirectoryFileChange]) throws -> Bool { let fullySelectedUntrackedFiles = untrackedFilesToStage.map { $0.withIncludeAll(include: true) } - + try UpdateIndex().stageFiles(directoryURL: directoryURL, files: untrackedFilesToStage) diff --git a/Sources/Version-Control/Base/Commands/Status.swift b/Sources/Version-Control/Base/Commands/Status.swift index 71a346db..54c90d2f 100644 --- a/Sources/Version-Control/Base/Commands/Status.swift +++ b/Sources/Version-Control/Base/Commands/Status.swift @@ -31,12 +31,11 @@ public struct GitStatus { } let manualConflictEntry = entry as? ManualConflictEntry - return ManualConflict(kind: .conflicted, + return ManualConflict(kind: .conflicted, entry: manualConflictEntry!, submoduleStatus: nil) } - func convertToAppStatus( path: String, entry: FileEntry, @@ -64,7 +63,6 @@ public struct GitStatus { } } - func getStatus(directoryURL: URL) async throws -> StatusResult? { let args = [ "--no-optional-locks", @@ -168,7 +166,7 @@ public struct GitStatus { return files } - func parseStatusHeader(results: StatusHeadersData, + func parseStatusHeader(results: StatusHeadersData, header: IStatusHeader) -> StatusHeadersData { var currentBranch = results.currentBranch var currentUpstreamBranch = results.currentUpstreamBranch @@ -239,7 +237,6 @@ public struct GitStatus { return ConflictFilesDetails(conflictCountsByPath: conflictCountsByPath, binaryFilePaths: binaryFilePaths) } - func getConflictDetails(directoryURL: URL, mergeHeadFound: Bool, lookForStashConflicts: Bool, diff --git a/Sources/Version-Control/Base/Commands/Submodule.swift b/Sources/Version-Control/Base/Commands/Submodule.swift index 6dccdac3..9601e858 100644 --- a/Sources/Version-Control/Base/Commands/Submodule.swift +++ b/Sources/Version-Control/Base/Commands/Submodule.swift @@ -11,7 +11,7 @@ import Foundation public struct Submodule { - public init(){} + public init() {} func listSubmodules(directoryURL: URL) throws -> [SubmoduleEntry] { let submodulesFile = FileManager.default.fileExists(atPath: directoryURL.appendingPathComponent(".gitmodules").path) diff --git a/Sources/Version-Control/Base/Commands/Update-Index.swift b/Sources/Version-Control/Base/Commands/Update-Index.swift index e7ef12f1..a2ce795c 100644 --- a/Sources/Version-Control/Base/Commands/Update-Index.swift +++ b/Sources/Version-Control/Base/Commands/Update-Index.swift @@ -196,5 +196,4 @@ public struct UpdateIndex { } } - } diff --git a/Sources/Version-Control/Base/Core/Blob/Blob.swift b/Sources/Version-Control/Base/Core/Blob/Blob.swift index 31eed770..e1900b7a 100644 --- a/Sources/Version-Control/Base/Core/Blob/Blob.swift +++ b/Sources/Version-Control/Base/Core/Blob/Blob.swift @@ -117,7 +117,7 @@ public struct Blob { let errorPipe = Pipe() process.executableURL = URL(fileURLWithPath: "/usr/bin/env") - process.arguments = ["git", + process.arguments = ["git", "-C", directoryURL.relativePath.escapedWhiteSpaces(), "show", diff --git a/Sources/Version-Control/Base/Core/GitShell.swift b/Sources/Version-Control/Base/Core/GitShell.swift index 01a9b8f5..f90a35cf 100644 --- a/Sources/Version-Control/Base/Core/GitShell.swift +++ b/Sources/Version-Control/Base/Core/GitShell.swift @@ -87,12 +87,12 @@ public struct GitShell { path: path.relativePath.escapedWhiteSpaces()) let exitCode = result.exitCode - var gitError: GitError? = nil + var gitError: GitError? var acceptableExitCode = options?.successExitCodes != nil ? options?.successExitCodes?.contains(exitCode) : false if !acceptableExitCode! { gitError = parseError(stderr: result.stderr) - if (gitError == nil) { + if gitError == nil { gitError = parseError(stderr: result.stdout) } } @@ -113,7 +113,7 @@ public struct GitShell { acceptableError = ((options?.expectedErrors?.contains(gitError!)) != nil) } - if ((gitError != nil && acceptableError) || acceptableError) { + if (gitError != nil && acceptableError) || acceptableError { return gitResult } diff --git a/Sources/Version-Control/Base/Core/IGitExecutionOptions.swift b/Sources/Version-Control/Base/Core/IGitExecutionOptions.swift index 5b524744..1dab6f61 100644 --- a/Sources/Version-Control/Base/Core/IGitExecutionOptions.swift +++ b/Sources/Version-Control/Base/Core/IGitExecutionOptions.swift @@ -8,7 +8,7 @@ import Foundation public struct IGitExecutionOptions: IExecutionOptions { - var env: [String : String]? + var env: [String: String]? var stdin: String? var stdinEncoding: String? var maxBuffer: Int? diff --git a/Sources/Version-Control/Base/Core/Parsers/GitCherryPickParser.swift b/Sources/Version-Control/Base/Core/Parsers/GitCherryPickParser.swift index 5eba10d5..197a623f 100644 --- a/Sources/Version-Control/Base/Core/Parsers/GitCherryPickParser.swift +++ b/Sources/Version-Control/Base/Core/Parsers/GitCherryPickParser.swift @@ -11,7 +11,7 @@ class GitCherryPickParser { private let commits: [Commit] private var count: Int = 0 - init(commits: [Commit], + init(commits: [Commit], count: Int = 0) { self.commits = commits self.count = count diff --git a/Sources/Version-Control/Base/Core/Parsers/GitDelimiterParser.swift b/Sources/Version-Control/Base/Core/Parsers/GitDelimiterParser.swift index 48363781..90308148 100644 --- a/Sources/Version-Control/Base/Core/Parsers/GitDelimiterParser.swift +++ b/Sources/Version-Control/Base/Core/Parsers/GitDelimiterParser.swift @@ -74,7 +74,7 @@ struct GitDelimiterParser { let records = value.components(separatedBy: "\0") var entries = [[T: String]]() - var entry: [T: String]? = nil + var entry: [T: String]? var consumed = 0 // start at 1 to avoid 0 modulo X problem. The first record is guaranteed diff --git a/Sources/Version-Control/Base/Core/Parsers/GitErrorParser.swift b/Sources/Version-Control/Base/Core/Parsers/GitErrorParser.swift index 2aece8e9..efd5fc7e 100644 --- a/Sources/Version-Control/Base/Core/Parsers/GitErrorParser.swift +++ b/Sources/Version-Control/Base/Core/Parsers/GitErrorParser.swift @@ -40,4 +40,3 @@ class GitErrorParser: Error { self.isRawMessage = rawMessage } } - diff --git a/Sources/Version-Control/Base/Core/Parsers/GitStatusParser.swift b/Sources/Version-Control/Base/Core/Parsers/GitStatusParser.swift index 71eaf405..a477d4b6 100644 --- a/Sources/Version-Control/Base/Core/Parsers/GitStatusParser.swift +++ b/Sources/Version-Control/Base/Core/Parsers/GitStatusParser.swift @@ -22,9 +22,9 @@ struct GitStatusParser { let changedEntryRegex = try! NSRegularExpression(pattern: "^1 ([MADRCUTX?!.]{2}) (N\\\\.\\.\\.|S[C.][M.][U.]) (\\d+) (\\d+) (\\d+) ([a-f0-9]+) ([a-f0-9]+) ([\\s\\S]*?)$", options: []) - let renamedOrCopiedEntryRegex = try! NSRegularExpression(pattern: "^2 ([MADRCUTX?!.]{2}) (N\\\\.\\.\\.|S[C.][M.][U.]) (\\d+) (\\d+) (\\d+) ([a-f0-9]+) ([a-f0-9]+) ([RC]\\d+) ([\\s\\S]*?)$", + let renamedOrCopiedEntryRegex = try! NSRegularExpression(pattern: "^2 ([MADRCUTX?!.]{2}) (N\\\\.\\.\\.|S[C.][M.][U.]) (\\d+) (\\d+) (\\d+) ([a-f0-9]+) ([a-f0-9]+) ([RC]\\d+) ([\\s\\S]*?)$", options: []) - let unmergedEntryRegex = try! NSRegularExpression(pattern: "^u ([DAU]{2}) (N\\\\.\\.\\.|S[C.][M.][U.]) (\\d+) (\\d+) (\\d+) (\\d+) ([a-f0-9]+) ([a-f0-9]+) ([a-f0-9]+) ([\\s\\S]*?)$", + let unmergedEntryRegex = try! NSRegularExpression(pattern: "^u ([DAU]{2}) (N\\\\.\\.\\.|S[C.][M.][U.]) (\\d+) (\\d+) (\\d+) (\\d+) ([a-f0-9]+) ([a-f0-9]+) ([a-f0-9]+) ([\\s\\S]*?)$", options: []) func parsePorcelainStatus(output: String) -> [StatusItem] { @@ -92,7 +92,7 @@ struct GitStatusParser { oldPath: nil) } - func parseRenamedOrCopiedEntry(field: String, + func parseRenamedOrCopiedEntry(field: String, oldPath: String?) -> IStatusEntry? { let nsRange = NSRange(field.startIndex.. Void) throws -> IGitExecutionOptions { - var lfsProgressPath: String? = nil + var lfsProgressPath: String? var env = [String: String]() if options.trackLFSProgress! { do { diff --git a/Sources/Version-Control/Base/Core/Progress/GitProgress.swift b/Sources/Version-Control/Base/Core/Progress/GitProgress.swift index 9a240d4e..a5b7ab3b 100644 --- a/Sources/Version-Control/Base/Core/Progress/GitProgress.swift +++ b/Sources/Version-Control/Base/Core/Progress/GitProgress.swift @@ -174,7 +174,6 @@ struct IGitProgressInfo { let percentRePattern = "^(\\d{1,3})% \\((\\d+)/(\\d+)\\)$" let valueOnlyRePattern = "^\\d+$" - /** * A utility class for interpreting progress output from `git` * and turning that into a percentage value estimating the overall progress @@ -209,7 +208,7 @@ struct GitProgressParser { */ init(steps: [ProgressStep]) throws { if steps.isEmpty { - throw NSError(domain: "com.auroraeditor.editor", + throw NSError(domain: "com.auroraeditor.editor", code: 1, userInfo: [NSLocalizedDescriptionKey: "Must specify at least one step"]) } @@ -300,4 +299,3 @@ struct GitProgressParser { return IGitProgressInfo(title: title, value: value, total: total, percent: percent, done: done, text: line) } } - diff --git a/Sources/Version-Control/Base/Core/Progress/LFSProgress.swift b/Sources/Version-Control/Base/Core/Progress/LFSProgress.swift index 54257240..6aff8958 100644 --- a/Sources/Version-Control/Base/Core/Progress/LFSProgress.swift +++ b/Sources/Version-Control/Base/Core/Progress/LFSProgress.swift @@ -29,12 +29,12 @@ struct LFSProgress { let lfsProgressURL = tempDirectoryURL.appendingPathComponent("AuroraEditor-lfs-progress-\(UUID().uuidString)") // Ensure the directory exists - try FileManager.default.createDirectory(at: lfsProgressURL.deletingLastPathComponent(), + try FileManager.default.createDirectory(at: lfsProgressURL.deletingLastPathComponent(), withIntermediateDirectories: true) // Create the file if it does not exist if !FileManager.default.fileExists(atPath: lfsProgressURL.path) { - FileManager.default.createFile(atPath: lfsProgressURL.path, + FileManager.default.createFile(atPath: lfsProgressURL.path, contents: nil) } else { // If file exists, throw an error diff --git a/Sources/Version-Control/Base/Models/CloneOptions.swift b/Sources/Version-Control/Base/Models/CloneOptions.swift index 1f4d79d8..48869598 100644 --- a/Sources/Version-Control/Base/Models/CloneOptions.swift +++ b/Sources/Version-Control/Base/Models/CloneOptions.swift @@ -11,4 +11,3 @@ struct CloneOptions { let branch: String? let defaultBranch: String? } - diff --git "a/Sources/Version-Control/Base/Models/Commands/Diff/Diff Types/ISubmoduleDiff\342\200\216.swift" "b/Sources/Version-Control/Base/Models/Commands/Diff/Diff Types/ISubmoduleDiff\342\200\216.swift" index d9ce0c25..200fdc4f 100644 --- "a/Sources/Version-Control/Base/Models/Commands/Diff/Diff Types/ISubmoduleDiff\342\200\216.swift" +++ "b/Sources/Version-Control/Base/Models/Commands/Diff/Diff Types/ISubmoduleDiff\342\200\216.swift" @@ -7,7 +7,7 @@ import Foundation -public struct ISubmoduleDiff : IDiff { +public struct ISubmoduleDiff: IDiff { public var kind: DiffType = .submodule /** Full path of the submodule */ @@ -17,14 +17,14 @@ public struct ISubmoduleDiff : IDiff { var path: String /** URL of the submodule */ - var url: String? = nil + var url: String? /** Status of the submodule */ var status: SubmoduleStatus /** Previous SHA of the submodule, or null if it hasn't changed */ - var oldSHA: String? = nil + var oldSHA: String? /** New SHA of the submodule, or null if it hasn't changed */ - var newSHA: String? = nil + var newSHA: String? } diff --git a/Sources/Version-Control/Base/Models/Commands/Diff/ITextDiffData.swift b/Sources/Version-Control/Base/Models/Commands/Diff/ITextDiffData.swift index 9183869f..42c3d5f7 100644 --- a/Sources/Version-Control/Base/Models/Commands/Diff/ITextDiffData.swift +++ b/Sources/Version-Control/Base/Models/Commands/Diff/ITextDiffData.swift @@ -35,5 +35,3 @@ public class ITextDiffData { public protocol TextDiff: ITextDiffData { var kind: DiffType { get set } } - - diff --git a/Sources/Version-Control/Base/Models/Commands/Status/StatusHeadersData.swift b/Sources/Version-Control/Base/Models/Commands/Status/StatusHeadersData.swift index 7245ba02..30658936 100644 --- a/Sources/Version-Control/Base/Models/Commands/Status/StatusHeadersData.swift +++ b/Sources/Version-Control/Base/Models/Commands/Status/StatusHeadersData.swift @@ -22,7 +22,7 @@ struct StatusHeadersData { self.match = nil } - public init(currentBranch: String?, + public init(currentBranch: String?, currentUpstreamBranch: String?, currentTip: String?, branchAheadBehind: IAheadBehind?, diff --git a/Sources/Version-Control/Base/Models/Commands/Status/WorkingDirectoryStatus.swift b/Sources/Version-Control/Base/Models/Commands/Status/WorkingDirectoryStatus.swift index 00149d2b..0bfb7aa6 100644 --- a/Sources/Version-Control/Base/Models/Commands/Status/WorkingDirectoryStatus.swift +++ b/Sources/Version-Control/Base/Models/Commands/Status/WorkingDirectoryStatus.swift @@ -11,7 +11,7 @@ struct WorkingDirectoryStatus { let files: [WorkingDirectoryFileChange] let includeAll: Bool? - init(files: [WorkingDirectoryFileChange], + init(files: [WorkingDirectoryFileChange], includeAll: Bool? = true) { self.files = files self.includeAll = includeAll diff --git a/Sources/Version-Control/Base/Models/Files/AppFileStatus.swift b/Sources/Version-Control/Base/Models/Files/AppFileStatus.swift index 5d4f3041..67e72899 100644 --- a/Sources/Version-Control/Base/Models/Files/AppFileStatus.swift +++ b/Sources/Version-Control/Base/Models/Files/AppFileStatus.swift @@ -74,7 +74,6 @@ public func isManualConflict(_ conflictedFileStatus: ConflictedFileStatus) -> Bo return conflictedFileStatus is ManualConflict } - public struct UntrackedFileStatus: AppFileStatus { public var kind: AppFileStatusKind public var submoduleStatus: SubmoduleStatus? @@ -171,4 +170,3 @@ struct OrdinaryEntry: FileEntry { let workingTree: GitStatusEntry? let submoduleStatus: SubmoduleStatus? } - diff --git a/Sources/Version-Control/Base/Models/Files/CommittedFileChange.swift b/Sources/Version-Control/Base/Models/Files/CommittedFileChange.swift index dff9cc20..0a4711f3 100644 --- a/Sources/Version-Control/Base/Models/Files/CommittedFileChange.swift +++ b/Sources/Version-Control/Base/Models/Files/CommittedFileChange.swift @@ -11,9 +11,9 @@ class CommittedFileChange: FileChange { let commitish: String let parentCommitish: String - init(path: String, + init(path: String, status: AppFileStatus, - commitish: String, + commitish: String, parentCommitish: String) { self.commitish = commitish self.parentCommitish = parentCommitish diff --git a/Sources/Version-Control/Base/Models/Files/FileChange.swift b/Sources/Version-Control/Base/Models/Files/FileChange.swift index 69a68172..ee5c8de8 100644 --- a/Sources/Version-Control/Base/Models/Files/FileChange.swift +++ b/Sources/Version-Control/Base/Models/Files/FileChange.swift @@ -12,7 +12,7 @@ public class FileChange { let path: String let status: AppFileStatus - public init(path: String, + public init(path: String, status: AppFileStatus) { self.path = path self.status = status diff --git a/Sources/Version-Control/Base/Models/GitCommit.swift b/Sources/Version-Control/Base/Models/GitCommit.swift index 18020696..55f4ed54 100644 --- a/Sources/Version-Control/Base/Models/GitCommit.swift +++ b/Sources/Version-Control/Base/Models/GitCommit.swift @@ -108,7 +108,7 @@ public struct Commit: Codable, Equatable, Identifiable { self.isMergeCommit = parentShas.count > 1 } - public init(sha: String, + public init(sha: String, summary: String) { self.sha = sha self.summary = summary diff --git a/Sources/Version-Control/Base/Models/IProgress.swift b/Sources/Version-Control/Base/Models/IProgress.swift index 9464bb59..f2a474df 100644 --- a/Sources/Version-Control/Base/Models/IProgress.swift +++ b/Sources/Version-Control/Base/Models/IProgress.swift @@ -195,7 +195,7 @@ public class MultiCommitOperationProgress: IMultiCommitOperationProgress { currentCommitSummary: String, position: Int, totalCommitCount: Int, - value: Int, + value: Int, title: String? = nil, description: String? = nil) { self.kind = kind diff --git a/Sources/Version-Control/Services/API/BitBucket/BitBucketAPI.swift b/Sources/Version-Control/Services/API/BitBucket/BitBucketAPI.swift index 7ba8d1f6..dce7d8e2 100644 --- a/Sources/Version-Control/Services/API/BitBucket/BitBucketAPI.swift +++ b/Sources/Version-Control/Services/API/BitBucket/BitBucketAPI.swift @@ -8,8 +8,8 @@ import Foundation struct BitBucketAPI { - - public init(){} + + public init() {} var bitbucketURL: String = "https://api.bitbucket.org/2.0/" diff --git a/Sources/Version-Control/Services/API/GitHub/AuthorizationResponse.swift b/Sources/Version-Control/Services/API/GitHub/AuthorizationResponse.swift index bb4de17f..8eff28d9 100644 --- a/Sources/Version-Control/Services/API/GitHub/AuthorizationResponse.swift +++ b/Sources/Version-Control/Services/API/GitHub/AuthorizationResponse.swift @@ -11,13 +11,13 @@ import Foundation struct AuthorizationResponse { /// The kind of authorization response. let kind: AuthorizationResponseKind - + /// The token associated with successful authorization. let token: String? - + /// The HTTP response associated with failed authorization. let response: String? - + /// The type of authentication mode required for two-factor authentication. let type: AuthenticationMode? } diff --git a/Sources/Version-Control/Services/API/GitHub/AuthorizationResponseKind.swift b/Sources/Version-Control/Services/API/GitHub/AuthorizationResponseKind.swift index 79b8587d..69a68393 100644 --- a/Sources/Version-Control/Services/API/GitHub/AuthorizationResponseKind.swift +++ b/Sources/Version-Control/Services/API/GitHub/AuthorizationResponseKind.swift @@ -9,25 +9,25 @@ enum AuthorizationResponseKind { /// The authorization was successful. case authorized - + /// The authorization failed. case failed - + /// Two-factor authentication is required. case twoFactorAuthenticationRequired - + /// User verification is required. case userRequiresVerification - + /// Personal access token is blocked. case personalAccessTokenBlocked - + /// An error occurred during authorization. case error - + /// The enterprise is too old for the authorization. case enterpriseTooOld - + /// Web authentication flow is required. /// /// The API has indicated that the user is required to go through diff --git a/Sources/Version-Control/Services/API/GitHub/GitHubAPI.swift b/Sources/Version-Control/Services/API/GitHub/GitHubAPI.swift index 1062220e..2587bc0c 100644 --- a/Sources/Version-Control/Services/API/GitHub/GitHubAPI.swift +++ b/Sources/Version-Control/Services/API/GitHub/GitHubAPI.swift @@ -8,9 +8,9 @@ import Foundation public struct GitHubAPI { - + public init() {} - + /// Creates a new GitHub repository. /// /// This function allows the user to create a new GitHub repository either under their own account or within an organization. It provides parameters for specifying the repository's name, description, and whether it should be private or public. @@ -59,7 +59,7 @@ public struct GitHubAPI { "description": description, "private": isPrivate ] - + AuroraNetworking() .request(baseURL: "", path: path, @@ -80,7 +80,7 @@ public struct GitHubAPI { } }) } - + /// Fetches branch protection information to determine if a user can push to a given branch. /// /// - Parameters: @@ -125,13 +125,13 @@ public struct GitHubAPI { guard let branchName = branch.urlEncode() else { return } - + let path = "repos/\(owner)/\(name)/branches/\(branchName)/push_control" - + let headers: [String: String] = [ "Accept": "application/vnd.github.phandalin-preview" ] - + AuroraNetworking() .request(baseURL: "", path: path, @@ -154,7 +154,7 @@ public struct GitHubAPI { } }) } - + /// Fetches protected branches for the given repository. /// /// - Parameters: @@ -186,7 +186,7 @@ public struct GitHubAPI { completion: @escaping ([IAPIBranch]?) -> Void ) { let path = "repos/\(owner)/\(name)/branches?protected=true" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -208,9 +208,9 @@ public struct GitHubAPI { } }) } - + // MARK: - Repository Issues - + /** * Fetch the issues with the given state that have been created or updated * since the given date. @@ -223,13 +223,13 @@ public struct GitHubAPI { completion: @escaping ([IAPIIssue]?) -> Void ) { var params: [String: String] = ["state": state.rawValue] - + if let sinceDate = since { params["since"] = Date().toGitHubIsoDateString(sinceDate) } - + let path = "repos/\(owner)/\(name)/issues".urlEncode(params) - + AuroraNetworking() .request(baseURL: "", path: path!, @@ -251,7 +251,7 @@ public struct GitHubAPI { } }) } - + /** Fetches all comments from a given issue. @@ -269,7 +269,7 @@ public struct GitHubAPI { completion: @escaping ([IAPIComment]?) -> Void ) { let path = "/repos/\(owner)/\(name)/issues/\(issueNumber)/comments" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -291,9 +291,9 @@ public struct GitHubAPI { } }) } - + // MARK: - Repository Pull Requests - + /** Fetches all open pull requests in the given repository. @@ -308,7 +308,7 @@ public struct GitHubAPI { name: String, completion: @escaping ([IAPIPullRequest]?) -> Void) { let path = "repos/\(owner)/\(name)/pulls".urlEncode(["state": "open"]) - + AuroraNetworking() .request(baseURL: "", path: path!, @@ -330,7 +330,7 @@ public struct GitHubAPI { } }) } - + /** Fetch a single pull request in the given repository. @@ -349,7 +349,7 @@ public struct GitHubAPI { completion: @escaping (IAPIPullRequest?) -> Void ) { let path = "/repos/\(owner)/\(name)/pulls/\(prNumber)" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -371,7 +371,7 @@ public struct GitHubAPI { } }) } - + /** Fetch a single pull request review in the given repository. @@ -391,7 +391,7 @@ public struct GitHubAPI { completion: @escaping (IAPIPullRequestReview?) -> Void ) { let path = "/repos/\(owner)/\(name)/pulls/\(prNumber)/reviews/\(reviewId)" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -413,7 +413,7 @@ public struct GitHubAPI { } }) } - + /** Fetches all reviews from a given pull request. @@ -431,7 +431,7 @@ public struct GitHubAPI { completion: @escaping ([IAPIPullRequestReview]?) -> Void ) { let path = "/repos/\(owner)/\(name)/pulls/\(prNumber)/reviews" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -453,7 +453,7 @@ public struct GitHubAPI { } }) } - + /** Fetches all review comments from a given pull request review. @@ -473,7 +473,7 @@ public struct GitHubAPI { completion: @escaping ([IAPIComment]?) -> Void ) { let path = "/repos/\(owner)/\(name)/pulls/\(prNumber)/reviews/\(reviewId)/comments" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -495,7 +495,7 @@ public struct GitHubAPI { } }) } - + /** Fetches all review comments from a given pull request. @@ -513,7 +513,7 @@ public struct GitHubAPI { completion: @escaping ([IAPIComment]?) -> Void ) { let path = "/repos/\(owner)/\(name)/pulls/\(prNumber)/comments" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -535,9 +535,9 @@ public struct GitHubAPI { } }) } - + // MARK: - Repository Rules - + /// Fetches repository rules for a specific branch in a GitHub repository. /// /// This function retrieves repository rules associated with a specific branch in a GitHub repository. Repository rules are used to define code analysis and linting rules that apply to the repository's codebase on a per-branch basis. It allows you to fetch a list of rules applicable to a particular branch. @@ -582,7 +582,7 @@ public struct GitHubAPI { completion: @escaping ([IAPIRepoRule]?) -> Void ) { let path = "repos/\(owner)/\(name)/rules/branches/\(branch)" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -604,7 +604,7 @@ public struct GitHubAPI { } }) } - + /// Fetches all repository rulesets from a GitHub repository. /// /// This function retrieves all repository rulesets associated with a GitHub repository. Repository rulesets are used to define code analysis and linting rules that apply to the repository. It allows you to fetch a list of all rulesets available in the repository. @@ -646,7 +646,7 @@ public struct GitHubAPI { completion: @escaping ([IAPISlimRepoRuleset]?) -> Void ) { let path = "repos/\(owner)/\(name)/rulesets" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -668,7 +668,7 @@ public struct GitHubAPI { } }) } - + /// Fetches a repository ruleset by its ID from a GitHub repository. /// /// This function retrieves a repository ruleset by its unique identifier (`id`) from a GitHub repository. Repository rulesets are used to define code analysis and linting rules that apply to the repository. This function allows you to fetch the details of a specific ruleset based on its ID. @@ -710,7 +710,7 @@ public struct GitHubAPI { completion: @escaping (IAPIRepoRuleset?) -> Void ) { let path = "repos/\(owner)/\(name)/rulesets/\(id)" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -732,9 +732,9 @@ public struct GitHubAPI { } }) } - + // MARK: - Workflows - + /// Fetches GitHub Actions check runs associated with a specific Git reference (e.g., branch or commit) in a repository. /// /// This function retrieves information about the GitHub Actions check runs that are associated with a specific Git reference in a GitHub repository. It is typically used to obtain check run details for a particular branch or commit. @@ -777,13 +777,13 @@ public struct GitHubAPI { completion: @escaping (IAPIRefCheckRuns?) -> Void ) { let safeRef = ref.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "" - + let path = "repos/\(owner)/\(name)/commits/\(safeRef)/check-runs?per_page=100" - + let headers = [ "Accept": "application/vnd.github.antiope-preview+json" ] - + AuroraNetworking() .request(baseURL: "", path: path, @@ -806,7 +806,7 @@ public struct GitHubAPI { } }) } - + /// Fetches GitHub Actions workflow runs associated with a specific branch name in a repository's pull requests. /// /// This function retrieves information about the GitHub Actions workflow runs that correspond to a particular branch name in pull requests of a GitHub repository. It is typically used to obtain workflow run details triggered by pull request events. @@ -848,9 +848,9 @@ public struct GitHubAPI { completion: @escaping (IAPIWorkflowRuns?) -> Void ) { let path = "repos/\(owner)/\(name)/actions/runs?event=pull_request&branch=\(branchName.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? "")" - + let headers = ["Accept": "application/vnd.github.antiope-preview+json"] - + AuroraNetworking() .request(baseURL: "", path: path, @@ -873,7 +873,7 @@ public struct GitHubAPI { } }) } - + /// Fetches the GitHub Actions workflow run associated with a specific check suite ID in a repository. /// /// This function retrieves information about the GitHub Actions workflow run that corresponds to a particular check suite ID in a GitHub repository. It is typically used to obtain workflow run details triggered by a pull request or a push event. @@ -915,9 +915,9 @@ public struct GitHubAPI { completion: @escaping (IAPIWorkflowRun?) -> Void ) { let path = "repos/\(owner)/\(name)/actions/runs?event=pull_request&check_suite_id=\(checkSuiteId)" - + let headers = ["Accept": "application/vnd.github.antiope-preview+json"] - + AuroraNetworking() .request(baseURL: "", path: path, @@ -940,7 +940,7 @@ public struct GitHubAPI { } }) } - + /// Fetches the jobs associated with a specific GitHub Actions workflow run for a repository. /// /// This function retrieves information about the jobs that were part of a particular workflow run in a GitHub Actions workflow for a specific repository. @@ -982,9 +982,9 @@ public struct GitHubAPI { completion: @escaping (IAPIWorkflowJobs?) -> Void ) { let path = "repos/\(owner)/\(name)/actions/runs/\(workflowRunId)/jobs" - + let headers = ["Accept": "application/vnd.github.antiope-preview+json"] - + AuroraNetworking() .request(baseURL: "", path: path, @@ -1007,7 +1007,7 @@ public struct GitHubAPI { } }) } - + /// Rerequests a GitHub check suite for a repository. /// /// This function triggers the rerequest of a specific GitHub check suite for a repository. It uses the GitHub API to make the request. @@ -1049,7 +1049,7 @@ public struct GitHubAPI { completion: @escaping (Bool) -> Void ) { let path = "/repos/\(owner)/\(name)/check-suites/\(checkSuiteId)/rerequest" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -1065,7 +1065,7 @@ public struct GitHubAPI { } }) } - + /// Reruns all failed jobs in a GitHub Actions workflow run for a repository. /// /// This function triggers the rerun of all failed jobs in a specific GitHub Actions workflow run for a repository. It uses the GitHub API to make the request. @@ -1107,7 +1107,7 @@ public struct GitHubAPI { completion: @escaping (Bool) -> Void ) { let path = "/repos/\(owner)/\(name)/actions/runs/\(workflowRunId)/rerun-failed-jobs" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -1123,7 +1123,7 @@ public struct GitHubAPI { } }) } - + /// Reruns a specific GitHub Actions job for a repository. /// /// This function triggers the rerun of a GitHub Actions job for a specific repository. It uses the GitHub API to make the request. @@ -1165,7 +1165,7 @@ public struct GitHubAPI { completion: @escaping (Bool) -> Void ) { let path = "/repos/\(owner)/\(name)/actions/jobs/\(jobId)/rerun" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -1181,7 +1181,7 @@ public struct GitHubAPI { } }) } - + /// Fetches information about a specific GitHub check suite by its identifier. /// /// This function retrieves details about a GitHub check suite, including its status, associated pull request, and other relevant information. It uses the GitHub API to make the request. @@ -1221,7 +1221,7 @@ public struct GitHubAPI { completion: @escaping (IAPICheckSuite?) -> Void ) { let path = "/repos/\(owner)/\(name)/check-suites/\(checkSuiteId)" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -1243,11 +1243,9 @@ public struct GitHubAPI { } }) } - - - + // MARK: - Account Information - + /// Fetches the account information for the authenticated user. /// /// This function retrieves the account information for the currently authenticated user. The account information typically includes details such as the user's username, avatar URL, email, and other profile-related information. @@ -1299,7 +1297,7 @@ public struct GitHubAPI { } }) } - + /// Fetches the email addresses associated with the authenticated user's GitHub account. /// /// This function retrieves the email addresses associated with the authenticated user's GitHub account. Users can have one or more email addresses associated with their account, and this function provides access to that information. @@ -1329,9 +1327,9 @@ public struct GitHubAPI { /// - SeeAlso: [GitHub API Documentation](https://docs.github.com/en/free-pro-team@latest/rest/users/emails?apiVersion=2022-11-28#list-email-addresses-for-the-authenticated-user) /// /// - SeeAlso: [GitHub Email Settings](https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/setting-up-and-managing-your-github-profile/managing-email-preferences) - func fetchEmails(completion: @escaping (IAPIEmail?) -> Void) -> Void { + func fetchEmails(completion: @escaping (IAPIEmail?) -> Void) { let path = "user/emails" - + AuroraNetworking() .request(baseURL: "", path: path, @@ -1352,7 +1350,7 @@ public struct GitHubAPI { } }) } - + /// Fetches a list of organizations that the authenticated user belongs to. /// /// This function retrieves a list of organizations that the authenticated user is a member of on GitHub. It can be used to obtain information about the organizations, such as their names and URLs. @@ -1382,9 +1380,9 @@ public struct GitHubAPI { /// - SeeAlso: [GitHub API Documentation](https://docs.github.com/en/free-pro-team@latest/rest/orgs/orgs?apiVersion=2022-11-28#list-organizations-for-the-authenticated-user) /// /// - SeeAlso: [GitHub Organizations](https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/listing-the-organizations-a-user-belongs-to) - func fetchOrgs(completion: @escaping (IAPIOrganization?) -> Void) -> Void { + func fetchOrgs(completion: @escaping (IAPIOrganization?) -> Void) { let path = "user/orgs" - + AuroraNetworking() .request(baseURL: "", path: path, diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIEmail.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIEmail.swift index 84e8bb15..1d948bf1 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIEmail.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIEmail.swift @@ -7,8 +7,6 @@ import Foundation -import Foundation - /// `null` can be returned by the API for legacy reasons. A non-null value is /// set for the primary email address currently, but in the future visibility /// may be defined for each email address. @@ -24,8 +22,8 @@ public struct IAPIEmail: Codable { let verified: Bool let primary: Bool let visibility: EmailVisibility - - public init(email: String, + + public init(email: String, verified: Bool, primary: Bool, visibility: EmailVisibility) { diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIFullIdentity.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIFullIdentity.swift index fc93dc45..9358cc94 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIFullIdentity.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Account/IAPIFullIdentity.swift @@ -20,13 +20,13 @@ struct IAPIFullIdentity: Codable { let htmlUrl: String let login: String let avatarUrl: String - + /** * The user's real name or null if the user hasn't provided * a real name for their public profile. */ let name: String? - + /** * The email address for this user or null if the user has not * specified a public email address in their profile. @@ -34,7 +34,7 @@ struct IAPIFullIdentity: Codable { let email: String? let type: GitHubAccountType let plan: Plan? - + struct Plan: Codable { let name: String } diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Branch/IAPIBranch.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Branch/IAPIBranch.swift index 6d1b79ea..755a05af 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Branch/IAPIBranch.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Branch/IAPIBranch.swift @@ -15,7 +15,7 @@ public struct IAPIBranch: Codable { NOTE: This is NOT a fully-qualified ref (i.e., `refs/heads/main`). */ public let name: String - + /** Branch protection settings: diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIFullRepository.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIFullRepository.swift index 47321bad..3451cc80 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIFullRepository.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIFullRepository.swift @@ -8,7 +8,7 @@ import Foundation struct IAPIFullRepository: Codable { - + /** * The parent repository of a fork. * @@ -34,7 +34,7 @@ struct IAPIFullRepository: Codable { let pushedAt: String let hasIssues: Bool let isArchived: Bool - + /** * The high-level permissions that the currently authenticated * user enjoys for the repository. Undefined if the API call diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIRepositoryCloneInfo.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIRepositoryCloneInfo.swift index 2235597b..90f50918 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIRepositoryCloneInfo.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/IAPIRepositoryCloneInfo.swift @@ -9,10 +9,10 @@ import Foundation // Define the IAPIRepositoryCloneInfo struct struct IAPIRepositoryCloneInfo { - + /** Canonical clone URL of the repository. */ let url: String - + /** * Default branch of the repository, if any. This is usually either retrieved * from the API for GitHub repositories, or undefined for other repositories. diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Push/IAPIPushControl.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Push/IAPIPushControl.swift index e5a1446a..838782dd 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Push/IAPIPushControl.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Push/IAPIPushControl.swift @@ -15,14 +15,14 @@ struct IAPIPushControl: Codable { * Empty array if user is admin and branch is not admin-enforced */ let required_status_checks: [String] - + /** * How many reviews are required before merging? * * 0 if user is admin and branch is not admin-enforced */ let required_approving_review_count: Int - + /** * Is user permitted? * @@ -32,7 +32,7 @@ struct IAPIPushControl: Codable { * `false` if `Restrict who can push` is enabled and user is not in list. */ let allow_actor: Bool - + /** * Currently unused properties */ @@ -42,4 +42,3 @@ struct IAPIPushControl: Codable { let allow_deletions: Bool let allow_force_pushes: Bool } - diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRule.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRule.swift index 6c501ff4..3cb245e9 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRule.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRule.swift @@ -13,12 +13,12 @@ struct IAPIRepoRule: Codable { The ID of the ruleset this rule is configured in. */ let ruleset_id: Int - + /** The type of the rule. */ let type: APIRepoRuleType - + /** The parameters that apply to the rule if it is a metadata rule. Other rule types may have parameters, but they are not used in diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleMetadataParameters.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleMetadataParameters.swift index e1f54e07..dba8be86 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleMetadataParameters.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleMetadataParameters.swift @@ -15,21 +15,21 @@ struct IAPIRepoRuleMetadataParameters: Codable { User-supplied name/description of the rule. */ let name: String - + /** Whether the operator is negated. For example, if `true` and `operator` is `starts_with`, then the rule will be negated to 'does not start with'. */ let negate: Bool - + /** The pattern to match against. If the operator is 'regex', then this is a regex string match. Otherwise, it is a raw string match of the type specified by `operator` with no additional parsing. */ let pattern: String - + /** The type of match to use for the pattern. For example, `starts_with` means `pattern` must be at the start of the string. diff --git a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleset.swift b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleset.swift index b91d43b1..41a0c0e2 100644 --- a/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleset.swift +++ b/Sources/Version-Control/Services/API/GitHub/Interfaces/Repo/Ruleset/IAPIRepoRuleset.swift @@ -19,7 +19,7 @@ enum UserCanBypass: String, Codable { struct IAPIRepoRuleset: Codable { /// The ID of the ruleset. let id: Int - + /** Whether the user making the API request can bypass the ruleset. diff --git a/Sources/Version-Control/Services/API/GitHub/Model/Account/GithubAccount.swift b/Sources/Version-Control/Services/API/GitHub/Model/Account/GithubAccount.swift index 778c6718..fb5654b7 100644 --- a/Sources/Version-Control/Services/API/GitHub/Model/Account/GithubAccount.swift +++ b/Sources/Version-Control/Services/API/GitHub/Model/Account/GithubAccount.swift @@ -18,7 +18,7 @@ public class Account: Codable, Equatable { let name: String let plan: String? - public init(login: String, + public init(login: String, endpoint: String, token: String, emails: [IAPIEmail], @@ -50,7 +50,7 @@ public class Account: Codable, Equatable { var friendlyName: String { return self.name != "" ? self.name : self.login } - + public static func == (lhs: Account, rhs: Account) -> Bool { return lhs.endpoint == rhs.endpoint && lhs.id == rhs.id } diff --git a/Sources/Version-Control/Services/API/Gitlab/GitlabAPI.swift b/Sources/Version-Control/Services/API/Gitlab/GitlabAPI.swift index d12b98ea..d284827a 100644 --- a/Sources/Version-Control/Services/API/Gitlab/GitlabAPI.swift +++ b/Sources/Version-Control/Services/API/Gitlab/GitlabAPI.swift @@ -9,7 +9,7 @@ import Foundation struct GitlabAPI { - public init(){} + public init() {} func createRepritory() { diff --git a/Sources/Version-Control/Services/Models/Github/Auth/GitHubEmail.swift b/Sources/Version-Control/Services/Models/Github/Auth/GitHubEmail.swift index bd9c22b4..db51249e 100644 --- a/Sources/Version-Control/Services/Models/Github/Auth/GitHubEmail.swift +++ b/Sources/Version-Control/Services/Models/Github/Auth/GitHubEmail.swift @@ -8,9 +8,9 @@ import Foundation public struct GitHubEmail { - - public init(){} - + + public init() {} + /// Look up the preferred email address for a GitHub account. /// /// This function determines the preferred email address associated with a GitHub account. It follows a set of prioritized conditions to select the preferred email address. diff --git a/Sources/Version-Control/Utils/BranchUtil.swift b/Sources/Version-Control/Utils/BranchUtil.swift index 200ec468..d79a326a 100644 --- a/Sources/Version-Control/Utils/BranchUtil.swift +++ b/Sources/Version-Control/Utils/BranchUtil.swift @@ -9,7 +9,7 @@ import Foundation public struct BranchUtil { - public init(){} + public init() {} /** Merges local and remote Git branches into a single array of Git branches that includes branches with upstream relationships. diff --git a/Sources/Version-Control/Utils/Extensions/String.swift b/Sources/Version-Control/Utils/Extensions/String.swift index 3cb27cb9..1cc2b637 100644 --- a/Sources/Version-Control/Utils/Extensions/String.swift +++ b/Sources/Version-Control/Utils/Extensions/String.swift @@ -9,27 +9,27 @@ import Foundation import CryptoKit extension String { - + /// Removes all `new-line` characters in a `String` /// - Returns: A String public func removingNewLines() -> String { self.replacingOccurrences(of: "\n", with: "") } - + /// Removes all `space` characters in a `String` /// - Returns: A String public func removingSpaces() -> String { self.replacingOccurrences(of: " ", with: "") } - + public func escapedWhiteSpaces() -> String { self.replacingOccurrences(of: " ", with: "\\ ") } - + private func index(from: Int) -> Index { return self.index(self.startIndex, offsetBy: from) } - + public func substring(_ toIndex: Int) -> String { let index = index(from: toIndex) return String(self[.. [[String]] { guard let regex = try? NSRegularExpression(pattern: regex, options: []) else { return [] } let nsString = self as NSString - let results = regex.matches(in: self, options: [], range: NSMakeRange(0, nsString.length)) + let results = regex.matches(in: self, options: [], range: NSRange(location: 0, length: nsString.length)) return results.map { result in (0.. String { var string = self - + // trim whitespaces & new lines if specifiedå if trim { string = string.trimmingCharacters(in: .whitespacesAndNewlines) } - + // make string lowercased if not case sensitive if !caseSensitive { string = string.lowercased() } - + // compute the hash // (note that `String.data(using: .utf8)!` is safe since it will never fail) let computed = Insecure.MD5.hash(data: string.data(using: .utf8)!) - + // map the result to a hex string and return return computed.compactMap { String(format: "%02x", $0) }.joined() } @@ -142,7 +142,7 @@ extension String { } extension StringProtocol where Index == String.Index { - + func ranges( of substring: T, options: String.CompareOptions = [], diff --git a/Sources/Version-Control/Utils/FileUtils.swift b/Sources/Version-Control/Utils/FileUtils.swift index 7127c27e..ecf556b7 100644 --- a/Sources/Version-Control/Utils/FileUtils.swift +++ b/Sources/Version-Control/Utils/FileUtils.swift @@ -9,7 +9,7 @@ import Foundation public struct FileUtils { - func writeToTempFile(content: String, + func writeToTempFile(content: String, tempFileName: String) async throws -> String { let tempDir = NSTemporaryDirectory() let tempFilePath = (tempDir as NSString).appendingPathComponent(tempFileName) diff --git a/Sources/Version-Control/Utils/ShellClient.swift b/Sources/Version-Control/Utils/ShellClient.swift index 0bd120fd..c9c5cdeb 100644 --- a/Sources/Version-Control/Utils/ShellClient.swift +++ b/Sources/Version-Control/Utils/ShellClient.swift @@ -173,7 +173,6 @@ public class ShellClient { return (stdoutString, stderrString) } - /// Shell client /// - Returns: description public static func live() -> ShellClient { diff --git a/Tests/Version-Control-Test/Services/Auth/GitHub/GitHubEmailTest.swift b/Tests/Version-Control-Test/Services/Auth/GitHub/GitHubEmailTest.swift index e9a27478..3cfd3efd 100644 --- a/Tests/Version-Control-Test/Services/Auth/GitHub/GitHubEmailTest.swift +++ b/Tests/Version-Control-Test/Services/Auth/GitHub/GitHubEmailTest.swift @@ -10,7 +10,7 @@ import XCTest import Version_Control class GitHubEmailTest: XCTestCase { - + // Helper method to create an Account object for testing func createAccount(withEmails emails: [IAPIEmail]) -> Account { return Account(login: "janedoe", @@ -22,7 +22,7 @@ class GitHubEmailTest: XCTestCase { name: "Jane Doe", plan: "free") } - + // Helper method to create an Email object for testing func createEmail(email: String, primary: Bool = false, @@ -32,7 +32,7 @@ class GitHubEmailTest: XCTestCase { primary: primary, visibility: visibility) } - + func testLookupPreferredEmailWithPublicEmails() { let publicEmail1 = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .public) let publicEmail2 = createEmail(email: "janedoe2@auroraeditor.com", visibility: .public) @@ -40,7 +40,7 @@ class GitHubEmailTest: XCTestCase { let result = GitHubEmail().lookupPreferredEmail(account: account) XCTAssertEqual(result, "janedoe@auroraeditor.com") } - + func testLookupPreferredEmailWithNoPublicEmails() { let privateEmail1 = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .private) let privateEmail2 = createEmail(email: "user2@private.com", visibility: .private) @@ -48,48 +48,48 @@ class GitHubEmailTest: XCTestCase { let result = GitHubEmail().lookupPreferredEmail(account: account) XCTAssertEqual(result, "janedoe@auroraeditor.com") } - + func testLookupPreferredEmailWithStealthEmail() { let stealthEmail = createEmail(email: "user@stealth.com", visibility: .null) let account = createAccount(withEmails: [stealthEmail]) let result = GitHubEmail().lookupPreferredEmail(account: account) XCTAssertEqual(result, "user@stealth.com") } - + // MARK: - Email Visibility - + func testIsEmailPublicWithPublicVisibility() { let email = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .public) let result = GitHubEmail().isEmailPublic(email: email) XCTAssertTrue(result) } - + func testIsEmailPublicWithNullVisibility() { let email = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .null) let result = GitHubEmail().isEmailPublic(email: email) XCTAssertTrue(result) } - + func testIsEmailPublicWithPrivateVisibility() { let email = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .private) let result = GitHubEmail().isEmailPublic(email: email) XCTAssertFalse(result) } - + // MARK: - Stealth Email - + func testGetStealthEmailHostForEndpoint() { let emailHost = GitHubEmail().getStealthEmailHostForEndpoint() XCTAssertEqual(emailHost, "users.noreply.github.com") } - + func testGetLegacyStealthEmailForUser() { let login = "janedoe" let expectedEmail = "janedoe@users.noreply.github.com" let legacyEmail = GitHubEmail().getLegacyStealthEmailForUser(login: login) XCTAssertEqual(legacyEmail, expectedEmail) } - + func testGetStealthEmailForUser() { let userId = 12345 let login = "janedoe" @@ -97,9 +97,9 @@ class GitHubEmailTest: XCTestCase { let stealthEmail = GitHubEmail().getStealthEmailForUser(id: userId, login: login) XCTAssertEqual(stealthEmail, expectedEmail) } - + // MARK: - Attributable Emails - + func testIsAttributableEmailForWithEmailInAccountEmails() { let publicEmail1 = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .public) let githubAccount = createAccount(withEmails: [publicEmail1]) @@ -107,7 +107,7 @@ class GitHubEmailTest: XCTestCase { let isAttributable = GitHubEmail().isAttributableEmailFor(account: githubAccount, email: emailToCheck) XCTAssertTrue(isAttributable) } - + func testIsAttributableEmailForWithGeneratedStealthEmail() { let publicEmail1 = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .public) let githubAccount = createAccount(withEmails: [publicEmail1]) @@ -115,7 +115,7 @@ class GitHubEmailTest: XCTestCase { let isAttributable = GitHubEmail().isAttributableEmailFor(account: githubAccount, email: emailToCheck) XCTAssertTrue(isAttributable) } - + func testIsAttributableEmailForWithGeneratedLegacyStealthEmail() { let publicEmail1 = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .public) let githubAccount = createAccount(withEmails: [publicEmail1]) @@ -123,7 +123,7 @@ class GitHubEmailTest: XCTestCase { let isAttributable = GitHubEmail().isAttributableEmailFor(account: githubAccount, email: emailToCheck) XCTAssertTrue(isAttributable) } - + func testIsAttributableEmailForWithNonAttributableEmail() { let publicEmail1 = createEmail(email: "janedoe@auroraeditor.com", primary: true, visibility: .public) let githubAccount = createAccount(withEmails: [publicEmail1])