Skip to content

Commit

Permalink
Use GitResetService to reset git repos
Browse files Browse the repository at this point in the history
  • Loading branch information
fredpi committed May 3, 2019
1 parent c78a837 commit c7ec9d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 2 additions & 4 deletions Sources/AccioKit/Commands/Protocols/DependencyInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ extension DependencyInstaller {

if try FileManager.default.isDirectory(atPath: frameworkCheckoutPath) {
do {
try bash("git -C '\(frameworkCheckoutPath)' reset HEAD --hard --quiet 2> /dev/null")
try bash("git -C '\(frameworkCheckoutPath)' clean -fd --quiet 2> /dev/null")
try bash("git -C '\(frameworkCheckoutPath)' clean -fdX --quiet 2> /dev/null")
try GitResetService.shared.resetGit(atPath: frameworkCheckoutPath)
}
catch {
// Remove checkout if git reset fails for some reason
// If the checkout is missing, SPM will automatically clone again in the next step
try FileManager.default.removeItem(atPath: frameworkCheckoutPath)
try bash("rm -rf '\(frameworkCheckoutPath)'")
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/AccioKit/Services/CachedBuilderService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ final class CachedBuilderService {
frameworkProducts.append(frameworkProduct)

case .carthage:
try bash("git -C '\(framework.projectDirectory)' reset HEAD --hard --quiet")
try bash("git -C '\(framework.projectDirectory)' clean -fd --quiet")

try GitResetService.shared.resetGit(atPath: framework.projectDirectory)
let frameworkProduct = try carthageBuilderService.build(
framework: framework,
platform: platform,
Expand Down
4 changes: 1 addition & 3 deletions Sources/AccioKit/Services/CarthageBuilderService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ final class CarthageBuilderService {

// revert any changes to prevent issues when removing checked out dependency
try bash("rm -rf '\(framework.projectDirectory)/Carthage/Build'")
try bash("git -C '\(framework.projectDirectory)' reset HEAD --hard --quiet 2> /dev/null")
try bash("git -C '\(framework.projectDirectory)' clean -fd --quiet 2> /dev/null")
try bash("git -C '\(framework.projectDirectory)' clean -fdX --quiet 2> /dev/null")
try GitResetService.shared.resetGit(atPath: framework.projectDirectory)

guard FileManager.default.fileExists(atPath: frameworkProduct.frameworkDirPath) && FileManager.default.fileExists(atPath: frameworkProduct.symbolsFilePath) else {
print("Failed to build products to \(platformBuildDir)/\(framework.libraryName).framework(.dSYM).", level: .error)
Expand Down
12 changes: 12 additions & 0 deletions Sources/AccioKit/Services/GitResetService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

final class GitResetService {
static let shared = GitResetService()

private init() { }

func resetGit(atPath directory: String) throws {
try bash("git -C '\(directory)' reset HEAD --hard --quiet 2> /dev/null")
try bash("git -C '\(directory)' clean -fd --quiet 2> /dev/null")
}
}

0 comments on commit c7ec9d9

Please sign in to comment.