From 1fcbc382536ad54b21c8737427785e8c3270c5b4 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sat, 18 Jan 2025 20:33:26 +0100 Subject: [PATCH] Implemented the InitGitInFolderTask task in the library target. --- .../Public/Tasks/InitGitInFolderTask.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Library/Sources/Public/Tasks/InitGitInFolderTask.swift diff --git a/Library/Sources/Public/Tasks/InitGitInFolderTask.swift b/Library/Sources/Public/Tasks/InitGitInFolderTask.swift new file mode 100644 index 0000000..850e1c2 --- /dev/null +++ b/Library/Sources/Public/Tasks/InitGitInFolderTask.swift @@ -0,0 +1,24 @@ +import Foundation + +public struct InitGitInFolderTask { + + // MARK: Initialisers + + public init() {} + + // MARK: Functions + + public func callAsFunction(at rootFolder: URL) async throws (RunProcessError) { + let pathCommand = "/usr/bin/git" + let pathFolder = rootFolder.pathString + + var gitInit = RunProcessTask(process: Process()) + var gitAdd = RunProcessTask(process: Process()) + var gitCommit = RunProcessTask(process: Process()) + + 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"]) + } + +}