-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathGitShow.swift
More file actions
24 lines (20 loc) · 827 Bytes
/
GitShow.swift
File metadata and controls
24 lines (20 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Foundation
import SystemUtils
public struct GitShow {
public static func showHeadContent(of filePath: String, repositoryURL: URL) -> String? {
let escapedFilePath = Self.escapePath(filePath)
let arguments = ["show", "HEAD:\(escapedFilePath)"]
let result = try? SystemUtils.executeCommand(
inDirectory: repositoryURL.path,
path: GitPath,
arguments: arguments
)
return result
}
private static func escapePath(_ string: String) -> String {
let charactersToEscape = CharacterSet(charactersIn: " '\"&()[]{}$`\\|;<>*?~")
return string.unicodeScalars.map { scalar in
charactersToEscape.contains(scalar) ? "\\\(Character(scalar))" : String(Character(scalar))
}.joined()
}
}