From 5b42414a3c42fd9b020ad9208fb40b58ba9173d6 Mon Sep 17 00:00:00 2001 From: rustemd02 Date: Sat, 17 May 2025 11:18:20 +0300 Subject: [PATCH] added check for git installation presence --- .../Clone/ViewModels/GitCloneViewModel.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CodeEdit/Features/SourceControl/Clone/ViewModels/GitCloneViewModel.swift b/CodeEdit/Features/SourceControl/Clone/ViewModels/GitCloneViewModel.swift index 4c1dd789d..838279b7c 100644 --- a/CodeEdit/Features/SourceControl/Clone/ViewModels/GitCloneViewModel.swift +++ b/CodeEdit/Features/SourceControl/Clone/ViewModels/GitCloneViewModel.swift @@ -31,6 +31,22 @@ class GitCloneViewModel: ObservableObject { } return false } + /// Check if Git is installed + /// - Returns: True if Git is found by running "which git" command + func isGitInstalled() -> Bool { + let process = Process() + process.executableURL = URL(fileURLWithPath: "/usr/bin/which") + process.arguments = ["git"] + let pipe = Pipe() + process.standardOutput = pipe + do { + try process.run() + process.waitUntilExit() + return process.terminationStatus == 0 + } catch { + return false + } + } /// Check if clipboard contains git url func checkClipboard() { @@ -43,6 +59,13 @@ class GitCloneViewModel: ObservableObject { /// Clone repository func cloneRepository(completionHandler: @escaping (URL) -> Void) { + if !isGitInstalled() { + showAlert( + alertMsg: "Git installation not found", + infoText: "Ensure Git is installed on your system and try again" + ) + return + } if repoUrlStr == "" { showAlert( alertMsg: "Url cannot be empty",