@@ -77,13 +77,12 @@ git.cfg = function(_config)
7777 ensure_git_env ()
7878end
7979
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 {}
8786end
8887
8988--- Resets a git repo `dest` to `commit`
@@ -150,7 +149,7 @@ local handle_checkouts = function(plugin, dest, disp)
150149 end )
151150 end
152151
153- local commit = plugin .commit or get_lockfile_hash (plugin . short_name )
152+ local commit = plugin .commit or get_lockfile_info (plugin ). commit
154153 if commit then
155154 if disp ~= nil then
156155 disp :task_update (plugin_name , fmt (' checking out %s...' , commit ))
@@ -203,30 +202,49 @@ local get_rev = function(plugin)
203202 end )
204203end
205204
206- git . setup = function (plugin )
205+ local get_date = function (plugin )
207206 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 )
210226 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'
212229 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 )
215232 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 )
216240
217241 local submodule_cmd = config .exec_cmd .. config .subcommands .submodules
218242 local rev_cmd = config .exec_cmd .. config .subcommands .get_rev
219243
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 )
230248
231249 local branch_cmd = config .exec_cmd .. config .subcommands .current_branch
232250 local current_commit_cmd = vim .split (config .exec_cmd .. config .subcommands .get_header , ' %s+' )
@@ -271,7 +289,7 @@ git.setup = function(plugin)
271289 installer_opts .cwd = install_to
272290 r :and_then (await , jobs .run (submodule_cmd , installer_opts ))
273291
274- local commit = plugin .commit or get_lockfile_hash (plugin . short_name )
292+ local commit = plugin .commit or get_lockfile_info (plugin ). commit
275293 if commit then
276294 disp :task_update (plugin_name , fmt (' checking out %s...' , commit ))
277295 r
@@ -556,6 +574,12 @@ git.setup = function(plugin)
556574 plugin .get_rev = function ()
557575 return get_rev (plugin )
558576 end
577+
578+ --- Returns HEAD's date
579+ --- @return string
580+ plugin .get_date = function ()
581+ return get_date (plugin )
582+ end
559583end
560584
561585return git
0 commit comments