@@ -85,6 +85,11 @@ local mock_timestamp = function(timestamp)
85
85
child .lua (lua_cmd )
86
86
end
87
87
88
+ local mock_bad_env_vars = function ()
89
+ child .fn .setenv (' GIT_DIR' , test_dir_absolute .. ' /.git' )
90
+ child .fn .setenv (' GIT_WORK_TREE' , test_dir_absolute )
91
+ end
92
+
88
93
local mock_hide_path = function (path )
89
94
path = path or test_dir_absolute
90
95
-- NOTE: use "^" as pattern separator because "/" can cause troubles
@@ -103,6 +108,10 @@ local get_spawn_log = function() return child.lua_get('_G.spawn_log') end
103
108
local validate_git_spawn_log = function (ref_log )
104
109
local spawn_log = get_spawn_log ()
105
110
111
+ local ref_env = child .fn .environ ()
112
+ -- Should never include environment variables that can affect Git operations
113
+ ref_env .GIT_DIR , ref_env .GIT_WORK_TREE = nil , nil
114
+
106
115
local n = math.max (# spawn_log , # ref_log )
107
116
for i = 1 , n do
108
117
local real , ref = spawn_log [i ], ref_log [i ]
@@ -114,23 +123,25 @@ local validate_git_spawn_log = function(ref_log)
114
123
-- Assume default `git` options
115
124
local args = { ' -c' , ' gc.auto=0' }
116
125
vim .list_extend (args , ref )
117
- eq (real , { executable = ' git' , options = { args = args , cwd = real .options .cwd } })
126
+ local opts = { args = args , cwd = real .options .cwd , env = ref_env , clear_env = true }
127
+ local ref_val = { executable = ' git' , options = opts }
128
+ eq (real , ref_val )
118
129
else
119
130
local opts = vim .deepcopy (ref )
120
131
-- Assume default `git` options
121
132
local args = { ' -c' , ' gc.auto=0' }
122
133
opts .args = vim .list_extend (args , opts .args )
134
+ if opts .env == nil then
135
+ opts .env = opts .env or ref_env
136
+ opts .clear_env = true
137
+ end
123
138
eq (real , { executable = ' git' , options = opts })
124
139
end
125
140
end
126
141
end
127
142
128
- local clear_spawn_log = function () child .lua (' _G.spawn_log = {}' ) end
129
-
130
143
local get_process_log = function () return child .lua_get (' _G.process_log' ) end
131
144
132
- local clear_process_log = function () child .lua (' _G.process_log = {}' ) end
133
-
134
145
-- Work with notifications
135
146
local mock_notify = function ()
136
147
child .lua ([[
@@ -541,6 +552,9 @@ T['add()']['Install'] = new_set({
541
552
})
542
553
543
554
T [' add()' ][' Install' ][' works' ] = function ()
555
+ mock_bad_env_vars ()
556
+ local ref_environ = child .fn .environ ()
557
+
544
558
child .lua ([[
545
559
_G.stdio_queue = {
546
560
{ out = 'git version 2.43.0'}, -- Check Git executable
@@ -596,6 +610,9 @@ T['add()']['Install']['works'] = function()
596
610
{ ' (mini.deps) (1/1) Installed `new_plugin`' , ' INFO' },
597
611
}
598
612
validate_notifications (ref_notify_log )
613
+
614
+ -- Should not affect any environment variables
615
+ eq (child .fn .environ (), ref_environ )
599
616
end
600
617
601
618
T [' add()' ][' Install' ][' checks for executable Git' ] = function ()
@@ -1222,6 +1239,8 @@ local update = forward_lua('MiniDeps.update')
1222
1239
1223
1240
T [' update()' ][' works' ] = function ()
1224
1241
child .set_size (40 , 80 )
1242
+ mock_bad_env_vars ()
1243
+ local ref_environ = child .fn .environ ()
1225
1244
1226
1245
-- By default should update all plugins in session
1227
1246
add (' plugin_1' )
@@ -1310,6 +1329,9 @@ T['update()']['works'] = function()
1310
1329
mock_hide_path (test_dir_absolute )
1311
1330
child .expect_screenshot ()
1312
1331
validate_confirm_buf (' confirm-update' )
1332
+
1333
+ -- Should not affect any environment variables
1334
+ eq (child .fn .environ (), ref_environ )
1313
1335
end
1314
1336
1315
1337
T [' update()' ][' checks for executable Git' ] = function ()
@@ -1371,6 +1393,9 @@ T['update()']['Confirm buffer'] = new_set({
1371
1393
})
1372
1394
1373
1395
T [' update()' ][' Confirm buffer' ][' can apply changes' ] = function ()
1396
+ mock_bad_env_vars ()
1397
+ local ref_environ = child .fn .environ ()
1398
+
1374
1399
-- Should run `update()` on buffer write with only valid plugin names
1375
1400
-- Remove 'plugin_1' from being updated
1376
1401
child .cmd (' g/^+++ plugin_1/normal! dd/' )
@@ -1379,6 +1404,9 @@ T['update()']['Confirm buffer']['can apply changes'] = function()
1379
1404
-- Should update and close confirmation buffer
1380
1405
eq (child .lua_get (' _G.update_args' ), { { ' plugin_2' }, { force = true , offline = true } })
1381
1406
validate_not_confirm_buf ()
1407
+
1408
+ -- Should not affect any environment variables
1409
+ eq (child .fn .environ (), ref_environ )
1382
1410
end
1383
1411
1384
1412
T [' update()' ][' Confirm buffer' ][' can cancel' ] = function ()
0 commit comments