@@ -86,13 +86,12 @@ git.cfg = function(_config)
8686 ensure_git_env ()
8787end
8888
89- --- Get lockfile hash if lockfile should be applied
90- --- @param name string
91- --- @return string | nil
92- local function get_lockfile_hash (name )
93- if config .is_lockfile and not lockfile .is_updating then
94- return lockfile .get (name )
95- end
89+ --- Get lockfile info if lockfile should be applied
90+ --- @param plugin table @ plugin being applied
91+ --- @return table @ either table with lockfile info or an empty table
92+ local function get_lockfile_info (plugin )
93+ local use_lockfile = config .is_lockfile and not lockfile .is_updating
94+ return use_lockfile and lockfile .get (plugin .short_name ) or {}
9695end
9796
9897--- Resets a git repo `dest` to `commit`
@@ -159,7 +158,7 @@ local handle_checkouts = function(plugin, dest, disp)
159158 end )
160159 end
161160
162- local commit = plugin .commit or get_lockfile_hash (plugin . short_name )
161+ local commit = plugin .commit or get_lockfile_info (plugin ). commit
163162 if commit then
164163 if disp ~= nil then
165164 disp :task_update (plugin_name , fmt (' checking out %s...' , commit ))
@@ -212,30 +211,49 @@ local get_rev = function(plugin)
212211 end )
213212end
214213
215- git . setup = function (plugin )
214+ local get_date = function (plugin )
216215 local plugin_name = util .get_plugin_full_name (plugin )
217- local install_to = plugin .install_path
218- local install_cmd
216+
217+ local rev_cmd = config .exec_cmd .. config .subcommands .get_date
218+
219+ return async (function ()
220+ local rev = await (jobs .run (rev_cmd , { cwd = plugin .install_path , options = { env = git .job_env }, capture_output = true }))
221+ :map_ok (function (ok )
222+ local _ , r = next (ok .output .data .stdout )
223+ return r
224+ end )
225+ :map_err (function (err )
226+ local _ , msg = fmt (' %s: %s' , plugin_name , next (err .output .data .stderr ))
227+ return msg
228+ end )
229+
230+ return rev
231+ end )
232+ end
233+
234+ local get_depth = function (plugin )
219235 if config .is_lockfile then
220- install_cmd = vim .split (config .exec_cmd .. fmt (config .subcommands .install , 999999 ), ' %s+' )
236+ local info = lockfile .get (plugin .short_name )
237+ return info .date and fmt (' --shallow-since="%s"' , info .date ) or ' --depth=999999'
221238 else
222- install_cmd =
223- vim . split ( config . exec_cmd .. fmt (config . subcommands . install , plugin . commit and 999999 or config . depth ), ' %s+ ' )
239+ local depth = plugin . commit and 999999 or config . depth
240+ return fmt (' --depth="%s" ' , depth )
224241 end
242+ end
243+
244+ git .setup = function (plugin )
245+ local plugin_name = util .get_plugin_full_name (plugin )
246+ local install_to = plugin .install_path
247+ local install_cmd = vim .split (config .exec_cmd .. config .subcommands .install , ' %s+' )
248+ install_cmd [# install_cmd + 1 ] = get_depth (plugin )
225249
226250 local submodule_cmd = config .exec_cmd .. config .subcommands .submodules
227251 local rev_cmd = config .exec_cmd .. config .subcommands .get_rev
228252
229- local update_cmd = config .exec_cmd
230- if config .is_lockfile then
231- update_cmd = update_cmd .. config .subcommands .fetch
232- else
233- if plugin .commit or plugin .tag then
234- update_cmd = update_cmd .. config .subcommands .fetch
235- else
236- update_cmd = update_cmd .. config .subcommands .update
237- end
238- end
253+ local use_fetch = config .is_lockfile or plugin .commit or plugin .tag
254+ local update_subcmd = use_fetch and config .subcommands .fetch or config .subcommands .update
255+ local update_cmd = vim .split (config .exec_cmd .. update_subcmd , ' %s+' )
256+ update_cmd [# update_cmd + 1 ] = get_depth (plugin )
239257
240258 local branch_cmd = config .exec_cmd .. config .subcommands .current_branch
241259 local current_commit_cmd = vim .split (config .exec_cmd .. config .subcommands .get_header , ' %s+' )
@@ -280,7 +298,7 @@ git.setup = function(plugin)
280298 installer_opts .cwd = install_to
281299 r :and_then (await , jobs .run (submodule_cmd , installer_opts ))
282300
283- local commit = plugin .commit or get_lockfile_hash (plugin . short_name )
301+ local commit = plugin .commit or get_lockfile_info (plugin ). commit
284302 if commit then
285303 disp :task_update (plugin_name , fmt (' checking out %s...' , commit ))
286304 r
@@ -565,6 +583,12 @@ git.setup = function(plugin)
565583 plugin .get_rev = function ()
566584 return get_rev (plugin )
567585 end
586+
587+ --- Returns HEAD's date
588+ --- @return string
589+ plugin .get_date = function ()
590+ return get_date (plugin )
591+ end
568592end
569593
570594return git
0 commit comments