@@ -77,13 +77,12 @@ git.cfg = function(_config)
77
77
ensure_git_env ()
78
78
end
79
79
80
- --- Get lockfile hash if lockfile should be applied
81
- --- @param name string
82
- --- @return string | nil
83
- local function get_lockfile_hash (name )
84
- if config .is_lockfile and not lockfile .is_updating then
85
- return lockfile .get (name )
86
- end
80
+ --- Get lockfile info if lockfile should be applied
81
+ --- @param plugin table @ plugin being applied
82
+ --- @return table @ either table with lockfile info or an empty table
83
+ local function get_lockfile_info (plugin )
84
+ local use_lockfile = config .is_lockfile and not lockfile .is_updating
85
+ return use_lockfile and lockfile .get (plugin .short_name ) or {}
87
86
end
88
87
89
88
--- Resets a git repo `dest` to `commit`
@@ -150,7 +149,7 @@ local handle_checkouts = function(plugin, dest, disp)
150
149
end )
151
150
end
152
151
153
- local commit = plugin .commit or get_lockfile_hash (plugin . short_name )
152
+ local commit = plugin .commit or get_lockfile_info (plugin ). commit
154
153
if commit then
155
154
if disp ~= nil then
156
155
disp :task_update (plugin_name , fmt (' checking out %s...' , commit ))
@@ -203,30 +202,49 @@ local get_rev = function(plugin)
203
202
end )
204
203
end
205
204
206
- git . setup = function (plugin )
205
+ local get_date = function (plugin )
207
206
local plugin_name = util .get_plugin_full_name (plugin )
208
- local install_to = plugin .install_path
209
- local install_cmd
207
+
208
+ local rev_cmd = config .exec_cmd .. config .subcommands .get_date
209
+
210
+ return async (function ()
211
+ local rev = await (jobs .run (rev_cmd , { cwd = plugin .install_path , options = { env = git .job_env }, capture_output = true }))
212
+ :map_ok (function (ok )
213
+ local _ , r = next (ok .output .data .stdout )
214
+ return r
215
+ end )
216
+ :map_err (function (err )
217
+ local _ , msg = fmt (' %s: %s' , plugin_name , next (err .output .data .stderr ))
218
+ return msg
219
+ end )
220
+
221
+ return rev
222
+ end )
223
+ end
224
+
225
+ local get_depth = function (plugin )
210
226
if config .is_lockfile then
211
- install_cmd = vim .split (config .exec_cmd .. fmt (config .subcommands .install , 999999 ), ' %s+' )
227
+ local info = lockfile .get (plugin .short_name )
228
+ return info .date and fmt (' --shallow-since="%s"' , info .date ) or ' --depth=999999'
212
229
else
213
- install_cmd =
214
- vim . split ( config . exec_cmd .. fmt (config . subcommands . install , plugin . commit and 999999 or config . depth ), ' %s+ ' )
230
+ local depth = plugin . commit and 999999 or config . depth
231
+ return fmt (' --depth="%s" ' , depth )
215
232
end
233
+ end
234
+
235
+ git .setup = function (plugin )
236
+ local plugin_name = util .get_plugin_full_name (plugin )
237
+ local install_to = plugin .install_path
238
+ local install_cmd = vim .split (config .exec_cmd .. config .subcommands .install , ' %s+' )
239
+ install_cmd [# install_cmd + 1 ] = get_depth (plugin )
216
240
217
241
local submodule_cmd = config .exec_cmd .. config .subcommands .submodules
218
242
local rev_cmd = config .exec_cmd .. config .subcommands .get_rev
219
243
220
- local update_cmd = config .exec_cmd
221
- if config .is_lockfile then
222
- update_cmd = update_cmd .. config .subcommands .fetch
223
- else
224
- if plugin .commit or plugin .tag then
225
- update_cmd = update_cmd .. config .subcommands .fetch
226
- else
227
- update_cmd = update_cmd .. config .subcommands .update
228
- end
229
- end
244
+ local use_fetch = config .is_lockfile or plugin .commit or plugin .tag
245
+ local update_subcmd = use_fetch and config .subcommands .fetch or config .subcommands .update
246
+ local update_cmd = vim .split (config .exec_cmd .. update_subcmd , ' %s+' )
247
+ update_cmd [# update_cmd + 1 ] = get_depth (plugin )
230
248
231
249
local branch_cmd = config .exec_cmd .. config .subcommands .current_branch
232
250
local current_commit_cmd = vim .split (config .exec_cmd .. config .subcommands .get_header , ' %s+' )
@@ -271,7 +289,7 @@ git.setup = function(plugin)
271
289
installer_opts .cwd = install_to
272
290
r :and_then (await , jobs .run (submodule_cmd , installer_opts ))
273
291
274
- local commit = plugin .commit or get_lockfile_hash (plugin . short_name )
292
+ local commit = plugin .commit or get_lockfile_info (plugin ). commit
275
293
if commit then
276
294
disp :task_update (plugin_name , fmt (' checking out %s...' , commit ))
277
295
r
@@ -556,6 +574,12 @@ git.setup = function(plugin)
556
574
plugin .get_rev = function ()
557
575
return get_rev (plugin )
558
576
end
577
+
578
+ --- Returns HEAD's date
579
+ --- @return string
580
+ plugin .get_date = function ()
581
+ return get_date (plugin )
582
+ end
559
583
end
560
584
561
585
return git
0 commit comments