Skip to content

Commit 76d4d01

Browse files
Added check for git installation presence (#2047)
* added check for git installation presence * Update CodeEdit/Features/SourceControl/Clone/ViewModels/GitCloneViewModel.swift --------- Co-authored-by: Austin Condiff <austin.condiff@gmail.com>
1 parent c0eac3b commit 76d4d01

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

CodeEdit/Features/SourceControl/Clone/ViewModels/GitCloneViewModel.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ class GitCloneViewModel: ObservableObject {
3131
}
3232
return false
3333
}
34+
/// Check if Git is installed
35+
/// - Returns: True if Git is found by running "which git" command
36+
func isGitInstalled() -> Bool {
37+
let process = Process()
38+
process.executableURL = URL(fileURLWithPath: "/usr/bin/which")
39+
process.arguments = ["git"]
40+
let pipe = Pipe()
41+
process.standardOutput = pipe
42+
do {
43+
try process.run()
44+
process.waitUntilExit()
45+
return process.terminationStatus == 0
46+
} catch {
47+
return false
48+
}
49+
}
3450

3551
/// Check if clipboard contains git url
3652
func checkClipboard() {
@@ -43,6 +59,13 @@ class GitCloneViewModel: ObservableObject {
4359

4460
/// Clone repository
4561
func cloneRepository(completionHandler: @escaping (URL) -> Void) {
62+
if !isGitInstalled() {
63+
showAlert(
64+
alertMsg: "Git installation not found.",
65+
infoText: "Ensure Git is installed on your system and try again."
66+
)
67+
return
68+
}
4669
if repoUrlStr == "" {
4770
showAlert(
4871
alertMsg: "Url cannot be empty",

0 commit comments

Comments
 (0)