6
6
module Git
7
7
class Lib
8
8
9
- @@semaphore = Mutex . new
10
-
11
9
# The path to the Git working copy. The default is '"./.git"'.
12
10
#
13
11
# @return [Pathname] the path to the Git working copy.
@@ -1142,41 +1140,14 @@ def command_lines(cmd, *opts, chdir: nil)
1142
1140
op . split ( "\n " )
1143
1141
end
1144
1142
1145
- # Takes the current git's system ENV variables and store them.
1146
- def store_git_system_env_variables
1147
- @git_system_env_variables = { }
1148
- ENV_VARIABLE_NAMES . each do |env_variable_name |
1149
- @git_system_env_variables [ env_variable_name ] = ENV [ env_variable_name ]
1150
- end
1151
- end
1152
-
1153
- # Takes the previously stored git's ENV variables and set them again on ENV.
1154
- def restore_git_system_env_variables
1155
- ENV_VARIABLE_NAMES . each do |env_variable_name |
1156
- ENV [ env_variable_name ] = @git_system_env_variables [ env_variable_name ]
1157
- end
1158
- end
1159
-
1160
- # Sets git's ENV variables to the custom values for the current instance.
1161
- def set_custom_git_env_variables
1162
- ENV [ 'GIT_DIR' ] = @git_dir
1163
- ENV [ 'GIT_WORK_TREE' ] = @git_work_dir
1164
- ENV [ 'GIT_INDEX_FILE' ] = @git_index_file
1165
- ENV [ 'GIT_SSH' ] = Git ::Base . config . git_ssh
1166
- end
1167
-
1168
- # Runs a block inside an environment with customized ENV variables.
1169
- # It restores the ENV after execution.
1170
- #
1171
- # @param [Proc] block block to be executed within the customized environment
1172
- def with_custom_env_variables ( &block )
1173
- @@semaphore . synchronize do
1174
- store_git_system_env_variables ( )
1175
- set_custom_git_env_variables ( )
1176
- return block . call ( )
1177
- end
1178
- ensure
1179
- restore_git_system_env_variables ( )
1143
+ # git's ENV variables for the current instance.
1144
+ def custom_git_env_variables
1145
+ {
1146
+ 'GIT_DIR' => @git_dir ,
1147
+ 'GIT_WORK_TREE' => @git_work_dir ,
1148
+ 'GIT_INDEX_FILE' => @git_index_file ,
1149
+ 'GIT_SSH' => Git ::Base . config . git_ssh ,
1150
+ }
1180
1151
end
1181
1152
1182
1153
def command ( *cmd , redirect : '' , chomp : true , chdir : nil , &block )
@@ -1196,19 +1167,8 @@ def command(*cmd, redirect: '', chomp: true, chdir: nil, &block)
1196
1167
1197
1168
git_cmd = "#{ Git ::Base . config . binary_path } #{ global_opts } #{ escaped_cmd } #{ redirect } 2>&1"
1198
1169
1199
- output = nil
1200
-
1201
- command_thread = nil ;
1202
-
1203
- status = nil
1204
-
1205
- with_custom_env_variables do
1206
- command_thread = Thread . new do
1207
- output = run_command ( git_cmd , chdir , &block )
1208
- status = $?
1209
- end
1210
- command_thread . join
1211
- end
1170
+ output = run_command ( git_cmd , chdir , &block )
1171
+ status = $?
1212
1172
1213
1173
@logger . info ( git_cmd )
1214
1174
@logger . debug ( output )
@@ -1293,9 +1253,9 @@ def run_command(git_cmd, chdir=nil, &block)
1293
1253
end
1294
1254
1295
1255
if chdir
1296
- IO . popen ( git_cmd , chdir : chdir , &block )
1256
+ IO . popen ( custom_git_env_variables , git_cmd , chdir : chdir , &block )
1297
1257
else
1298
- IO . popen ( git_cmd , &block )
1258
+ IO . popen ( custom_git_env_variables , git_cmd , &block )
1299
1259
end
1300
1260
end
1301
1261
0 commit comments