@@ -57,6 +57,7 @@ public enum Git {
57
57
}
58
58
59
59
/// A shell command to run for Git. Can be either a name or a path.
60
+ /// - Note: modification is not thread safe, designed for testing only
60
61
public static var tool : String = " git \( executableFileSuffix) "
61
62
62
63
/// Returns true if the git reference name is well formed.
@@ -69,32 +70,40 @@ public enum Git {
69
70
}
70
71
}
71
72
73
+ private static var _gitEnvironment = ProcessInfo . processInfo. environment
74
+
72
75
/// Returns the environment variables for launching the git subprocess.
73
76
///
74
77
/// This contains the current environment with custom overrides for using
75
78
/// git from swift build.
79
+ /// - Note: modification is not thread safe, designed for testing only
76
80
public static var environment : [ String : String ] {
77
- var env = ProcessInfo . processInfo. environment
81
+ get {
82
+ var env = Self . _gitEnvironment
78
83
79
- // These variables are inserted into the environment when shelling out
80
- // to git if not already present.
81
- let underrideVariables = [
82
- // Disable terminal prompts in git. This will make git error out and return
83
- // when it needs a user/pass etc instead of hanging the terminal (SR-3981).
84
- " GIT_TERMINAL_PROMPT " : " 0 " ,
84
+ // These variables are inserted into the environment when shelling out
85
+ // to git if not already present.
86
+ let underrideVariables = [
87
+ // Disable terminal prompts in git. This will make git error out and return
88
+ // when it needs a user/pass etc instead of hanging the terminal (SR-3981).
89
+ " GIT_TERMINAL_PROMPT " : " 0 " ,
85
90
86
- // The above is env variable is not enough. However, ssh_config's batch
87
- // mode is made for this purpose. see: https://linux.die.net/man/5/ssh_config
88
- " GIT_SSH_COMMAND " : " ssh -oBatchMode=yes " ,
89
- ]
91
+ // The above is env variable is not enough. However, ssh_config's batch
92
+ // mode is made for this purpose. see: https://linux.die.net/man/5/ssh_config
93
+ " GIT_SSH_COMMAND " : " ssh -oBatchMode=yes " ,
94
+ ]
90
95
91
- for (key, value) in underrideVariables {
92
- // Skip this key is already present in the env.
93
- if env. keys. contains ( key) { continue }
96
+ for (key, value) in underrideVariables {
97
+ // Skip this key is already present in the env.
98
+ if env. keys. contains ( key) { continue }
94
99
95
- env [ key] = value
96
- }
100
+ env [ key] = value
101
+ }
97
102
98
- return env
103
+ return env
104
+ }
105
+ set {
106
+ Self . _gitEnvironment = newValue
107
+ }
99
108
}
100
109
}
0 commit comments