@@ -57,6 +57,7 @@ public enum Git {
5757 }
5858
5959 /// 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
6061 public static var tool : String = " git \( executableFileSuffix) "
6162
6263 /// Returns true if the git reference name is well formed.
@@ -69,32 +70,40 @@ public enum Git {
6970 }
7071 }
7172
73+ private static var _gitEnvironment = ProcessInfo . processInfo. environment
74+
7275 /// Returns the environment variables for launching the git subprocess.
7376 ///
7477 /// This contains the current environment with custom overrides for using
7578 /// git from swift build.
79+ /// - Note: modification is not thread safe, designed for testing only
7680 public static var environment : [ String : String ] {
77- var env = ProcessInfo . processInfo. environment
81+ get {
82+ var env = Self . _gitEnvironment
7883
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 " ,
8590
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+ ]
9095
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 }
9499
95- env [ key] = value
96- }
100+ env [ key] = value
101+ }
97102
98- return env
103+ return env
104+ }
105+ set {
106+ Self . _gitEnvironment = newValue
107+ }
99108 }
100109}
0 commit comments