Implemented the InitGitInFolderTask task in the library target.
This commit is contained in:
parent
2698e1e29c
commit
5f5f902773
@ -1,24 +1,26 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public struct InitGitInFolderTask {
|
public struct InitGitInFolderTask {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let terminalService: TerminalServicing
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
|
|
||||||
public init() {}
|
public init(terminalService: TerminalServicing) {
|
||||||
|
self.terminalService = terminalService
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
public func callAsFunction(at rootFolder: URL) async throws (RunProcessError) {
|
public func callAsFunction(at rootFolder: URL) async throws (TerminalServiceError) {
|
||||||
let pathCommand = "/usr/bin/git"
|
let executableURL = URL(at: "/usr/bin/git")
|
||||||
let pathFolder = rootFolder.pathString
|
let pathFolder = rootFolder.pathString
|
||||||
|
|
||||||
var gitInit = RunProcessTask(process: Process())
|
try await terminalService.run(executableURL, arguments: ["init", pathFolder])
|
||||||
var gitAdd = RunProcessTask(process: Process())
|
try await terminalService.run(executableURL, arguments: ["-C", pathFolder, "add", "."])
|
||||||
var gitCommit = RunProcessTask(process: Process())
|
try await terminalService.run(executableURL, arguments: ["-C", pathFolder, "commit", "-m", "Initial commit"])
|
||||||
|
|
||||||
try await gitInit(path: pathCommand, arguments: ["init", pathFolder])
|
|
||||||
try await gitAdd(path: pathCommand, arguments: ["-C", pathFolder, "add", "."])
|
|
||||||
try await gitCommit(path: pathCommand, arguments: ["-C", pathFolder, "commit", "-m", "Initial commit"])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct InitGitInFolderTaskTests {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let spy = TerminalServiceSpy()
|
||||||
|
|
||||||
|
// MARK:
|
||||||
|
|
||||||
|
@Test(arguments: [URL.someCurrentFolder, .someNewFolder, .someDotFolder, .someTildeFolder])
|
||||||
|
func task(at rootFolder: URL) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let initGitInFolder = InitGitInFolderTask(terminalService: spy)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await initGitInFolder(at: rootFolder)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/git")
|
||||||
|
let pathFolder = rootFolder.pathString
|
||||||
|
|
||||||
|
#expect(spy.actions.count == 3)
|
||||||
|
#expect(spy.actions[0] == .ran(executableURL, ["init", pathFolder]))
|
||||||
|
#expect(spy.actions[1] == .ran(executableURL, ["-C", pathFolder, "add", "."]))
|
||||||
|
#expect(spy.actions[2] == .ran(executableURL, ["-C", pathFolder, "commit", "-m", "Initial commit"]))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user