Skip to content

Commit 7ad591d

Browse files
authored
Revert "Update Git type for ProcessEnvironmentBlock (#470)"
This reverts commit 930e82e.
1 parent 930e82e commit 7ad591d

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

Sources/TSCUtility/Git.swift

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,51 @@
1111
import class Foundation.ProcessInfo
1212
import TSCBasic
1313

14+
extension Version {
15+
// FIXME: deprecate 2/2021 (used below), remove once clients transitioned
16+
@available(*, deprecated, message: "moved to SwiftPM")
17+
init?(tag: String) {
18+
if tag.first == "v" {
19+
self.init(string: String(tag.dropFirst()))
20+
} else {
21+
self.init(string: tag)
22+
}
23+
}
24+
}
25+
1426
public enum Git {
27+
// FIXME: deprecate 2/2021, remove once clients transitioned
28+
@available(*, deprecated, message: "moved to SwiftPM")
29+
public static func convertTagsToVersionMap(_ tags: [String]) -> [Version: [String]] {
30+
// First, check if we need to restrict the tag set to version-specific tags.
31+
var knownVersions: [Version: [String]] = [:]
32+
var versionSpecificKnownVersions: [Version: [String]] = [:]
33+
34+
for tag in tags {
35+
for versionSpecificKey in Versioning.currentVersionSpecificKeys {
36+
if tag.hasSuffix(versionSpecificKey) {
37+
let trimmedTag = String(tag.dropLast(versionSpecificKey.count))
38+
if let version = Version(tag: trimmedTag) {
39+
versionSpecificKnownVersions[version, default: []].append(tag)
40+
}
41+
break
42+
}
43+
}
44+
45+
if let version = Version(tag: tag) {
46+
knownVersions[version, default: []].append(tag)
47+
}
48+
}
49+
// Check if any version specific tags were found.
50+
// If true, then return the version specific tags,
51+
// or else return the version independent tags.
52+
if !versionSpecificKnownVersions.isEmpty {
53+
return versionSpecificKnownVersions
54+
} else {
55+
return knownVersions
56+
}
57+
}
58+
1559
/// A shell command to run for Git. Can be either a name or a path.
1660
/// - Note: modification is not thread safe, designed for testing only
1761
public static var tool: String = "git\(executableFileSuffix)"
@@ -26,55 +70,20 @@ public enum Git {
2670
}
2771
}
2872

29-
private static var _gitEnvironment = ProcessEnv.block
30-
31-
@available(*,
32-
deprecated,
33-
renamed: "environmentBlock",
34-
message: "Previous `[String: String]` representation did not account for case insensitivity on Windows."
35-
)
36-
public static var environment: [String: String] {
37-
get {
38-
var env = Self._gitEnvironment
39-
40-
// These variables are inserted into the environment when shelling out
41-
// to git if not already present.
42-
let underrideVariables: ProcessEnvironmentBlock = [
43-
// Disable terminal prompts in git. This will make git error out and return
44-
// when it needs a user/pass etc instead of hanging the terminal (SR-3981).
45-
"GIT_TERMINAL_PROMPT": "0",
46-
47-
// The above is env variable is not enough. However, ssh_config's batch
48-
// mode is made for this purpose. see: https://linux.die.net/man/5/ssh_config
49-
"GIT_SSH_COMMAND": "ssh -oBatchMode=yes",
50-
]
51-
52-
for (key, value) in underrideVariables {
53-
// Skip this key is already present in the env.
54-
if env.keys.contains(key) { continue }
55-
56-
env[key] = value
57-
}
58-
59-
return Dictionary(env.map { ($0.value, $1) }, uniquingKeysWith: { $1 })
60-
}
61-
set {
62-
Self._gitEnvironment = .init(newValue)
63-
}
64-
}
73+
private static var _gitEnvironment = ProcessInfo.processInfo.environment
6574

6675
/// Returns the environment variables for launching the git subprocess.
6776
///
6877
/// This contains the current environment with custom overrides for using
6978
/// git from swift build.
7079
/// - Note: modification is not thread safe, designed for testing only
71-
public static var environmentBlock: ProcessEnvironmentBlock {
80+
public static var environment: [String: String] {
7281
get {
7382
var env = Self._gitEnvironment
7483

7584
// These variables are inserted into the environment when shelling out
7685
// to git if not already present.
77-
let underrideVariables: ProcessEnvironmentBlock = [
86+
let underrideVariables = [
7887
// Disable terminal prompts in git. This will make git error out and return
7988
// when it needs a user/pass etc instead of hanging the terminal (SR-3981).
8089
"GIT_TERMINAL_PROMPT": "0",

0 commit comments

Comments
 (0)