Skip to content

Commit

Permalink
Merge pull request #18 from 0xWDG/main
Browse files Browse the repository at this point in the history
Fixed some swiftlint errors
  • Loading branch information
0xWDG authored Nov 30, 2023
2 parents a1a7766 + 85e4b35 commit 194470f
Show file tree
Hide file tree
Showing 65 changed files with 215 additions and 239 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ let package = Package(
dependencies: [
"Version-Control"
]
),
)
]
)
16 changes: 8 additions & 8 deletions Sources/Version-Control/Base/Actions/GitHub/GitHubActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ 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
}
}
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.
Expand Down Expand Up @@ -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.
Expand All @@ -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!)
}
}
2 changes: 1 addition & 1 deletion Sources/Version-Control/Base/Commands/Apply.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions Sources/Version-Control/Base/Commands/Branch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public struct Branch {
"HEAD",
"-n",
"2500",
"--",
"--"
]

let result = try GitShell().git(args: args,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Version-Control/Base/Commands/Checkout-Index.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

public struct CheckoutIndex {

public init(){}
public init() {}

public func checkoutIndex(directoryURL: URL,
paths: [String]) async throws {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Version-Control/Base/Commands/Checkout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -50,7 +50,7 @@ public struct GitCheckout {
} else {
if branch.type == BranchType.remote {
return baseArgs + [
branch.name,
branch.name,
"-b",
branch.nameWithoutRemote,
"--"
Expand Down
6 changes: 3 additions & 3 deletions Sources/Version-Control/Base/Commands/Cherry-Pick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/Version-Control/Base/Commands/Clone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions Sources/Version-Control/Base/Commands/Diff-Check.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Version-Control/Base/Commands/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
12 changes: 6 additions & 6 deletions Sources/Version-Control/Base/Commands/GitLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct GitLog {
return nil
}

func mapStatus(rawStatus: String,
func mapStatus(rawStatus: String,
oldPath: String?,
srcMode: String,
dstMode: String) -> AppFileStatus {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -178,7 +178,7 @@ public struct GitLog {
"--format=format:",
"--numstat",
"-z",
"--",
"--"
]

let result = try GitShell().git(args: args,
Expand Down Expand Up @@ -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]()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Version-Control/Base/Commands/LFS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<result.stdout.endIndex,
let range = NSRange(result.stdout.startIndex..<result.stdout.endIndex,
in: result.stdout)

let match = lfsFilterRegex.firstMatch(in: result.stdout,
Expand Down Expand Up @@ -250,7 +250,7 @@ public struct LFS {
// Iterate through the provided relative file paths.
for filePath in filePaths {
// Check if the file is tracked by Git LFS.
let isTracked = try isTrackedByLFS(directoryURL: directoryURL,
let isTracked = try isTrackedByLFS(directoryURL: directoryURL,
path: filePath)

// If not tracked by Git LFS, add it to the list.
Expand Down
1 change: 0 additions & 1 deletion Sources/Version-Control/Base/Commands/Pull.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public struct GitPull {
progressCallback: ((IPullProgress) -> Void)? = nil) throws -> [String] {
let divergentPathArgs = getDefaultPullDivergentBranchArguments(directoryURL: directoryURL)


var args = gitNetworkArguments + gitRebaseArguments + ["pull"] + divergentPathArgs

args.append("--recurse-submodules")
Expand Down
1 change: 0 additions & 1 deletion Sources/Version-Control/Base/Commands/Push.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public struct Push {

public init() {}


public func push(directoryURL: URL,
remote: IRemote,
localBranch: String,
Expand Down
19 changes: 9 additions & 10 deletions Sources/Version-Control/Base/Commands/Rebase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -227,7 +227,7 @@ public struct Rebase {
return .aborted
}

options = configureOptionsForRebase(options: options,
options = configureOptionsForRebase(options: options,
progress: RebaseProgressOptions(commits: snapshot.commits,
progressCallback: progressCallback))
}
Expand All @@ -249,7 +249,6 @@ public struct Rebase {
return parseRebaseResult(result: result)
}


func rebaseInteractive(directoryURL: URL,
pathOfGeneratedTodo: String,
lastRetainedCommitRef: String?,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions Sources/Version-Control/Base/Commands/Reflog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -187,5 +186,4 @@ public struct Reflog {
return checkouts
}


}
2 changes: 1 addition & 1 deletion Sources/Version-Control/Base/Commands/Refs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Loading

0 comments on commit 194470f

Please sign in to comment.