Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiftlint fixes #6

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ identifier_name:
excluded:
- id
- vc
- to
# (short) File extensions:
- c
- m
Expand Down
66 changes: 66 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Version-Control.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Version-Control"
BuildableName = "Version-Control"
BlueprintName = "Version-Control"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Version-Control"
BuildableName = "Version-Control"
BlueprintName = "Version-Control"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion Sources/Version-Control/Services/Models/Client/Add.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
}
6 changes: 4 additions & 2 deletions Sources/Version-Control/Services/Models/Client/Apply.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
47 changes: 28 additions & 19 deletions Sources/Version-Control/Services/Models/Client/Branch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import Foundation

public struct Branch {

public init() {}

/// Retrieves the name of the current Git branch in a specified directory.
///
/// - Parameters:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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)")
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -402,4 +411,4 @@ public struct Branch {
throw error
}
}
}
} // swiftlint:disable:this file_length
8 changes: 5 additions & 3 deletions Sources/Version-Control/Services/Models/Client/Check.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions Sources/Version-Control/Services/Models/Client/Checkout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import Foundation

public struct Checkout {

public init() {}

/// Checks out a Git branch in a specified directory.
///
/// - Parameters:
Expand Down Expand Up @@ -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)")
Expand All @@ -111,7 +115,7 @@ public struct Checkout {
"--",
file.url.relativePath
]

try ShellClient().run("cd \(directoryURL.relativePath.escapedWhiteSpaces());git \(args)")
}
}
11 changes: 7 additions & 4 deletions Sources/Version-Control/Services/Models/Client/Cherry-Pick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Version-Control/Services/Models/Client/Clone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Foundation

public struct Clone {

public init() {}

/// Clones a repository from a given url into to the specified path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Foundation

public struct Commit {

public init() {}

/// Creates a Git commit in a specified Git repository directory.
Expand Down
Loading
Loading