diff options
author | Squibid <me@zacharyscheiman.com> | 2023-07-03 15:53:01 -0400 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2023-07-03 15:53:01 -0400 |
commit | 1f407569f19677564be75ef21467ced344d2154e (patch) | |
tree | c41a8dc48e5a3d9c905377f4ac6c912e09315b6d /eatit.lua | |
parent | f183533b821c157b1d2a51c655477c9ca046d2f0 (diff) | |
download | eat-it-1f407569f19677564be75ef21467ced344d2154e.tar.gz eat-it-1f407569f19677564be75ef21467ced344d2154e.tar.bz2 eat-it-1f407569f19677564be75ef21467ced344d2154e.zip |
reduce number of opts for functions, and allow links with .git at the end
Diffstat (limited to 'eatit.lua')
-rw-r--r-- | eatit.lua | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -37,11 +37,12 @@ local function logwrite(string) end end -local function clonegit(pluginlink) - logwrite('downloading ' .. pluginlink) +-- get the requested git repos +local function clonegit(i) + logwrite('downloading ' .. plugins[i][1]) -- construct the git cmd - local cmd = 'git -C ' .. opts.dl.dir .. ' clone ' .. pluginlink + local cmd = 'git -C ' .. opts.dl.dir .. ' clone ' .. plugins[i][1] -- run the command and get the result for logging local run = io.popen(cmd) @@ -51,15 +52,16 @@ local function clonegit(pluginlink) run:close() end -local function checkupdates(i, pluginfile, pluginlink) +-- check for updates +local function checkupdates(i) local plugdir = opts.dl.dir .. '/' .. - string.match(pluginlink, '/([^/]+)$') + string.match(plugins[i][1], '/([^/]+)$'):gsub('.git', '') - local localhashcmd = 'cd ' .. plugdir .. - '; git log -1 --format=format:"%H"' + local localhashcmd = 'git -C ' .. plugdir .. ' log -1 --format=format:"%H"' - local remotehashcmd = 'cd ' .. plugdir .. - '; git log -n 1 $(git branch -r | head -1 | cut -d " " -f 3)' .. + local remotehashcmd = 'git -C ' .. plugdir .. + ' log -n 1 $(git -C ' .. plugdir .. + ' branch -r | head -1 | cut -d " " -f 3)' .. ' | head -1 | cut -d " " -f 2' local a = io.popen(localhashcmd) @@ -71,10 +73,9 @@ local function checkupdates(i, pluginfile, pluginlink) a:close() if localhash ~= remotehash then - logwrite(plugins[i]['file'] .. ' is updating.') - clonegit(pluginlink) + return true else - logwrite(plugins[i]['file'] .. ' is up to date!') + return false end end @@ -97,7 +98,7 @@ local function startinstall() -- get the file's dir local pluginfile = opts.dl.dir .. '/' .. - string.match(plugins[i][1], '/([^/]+)$') .. + string.match(plugins[i][1], '/([^/]+)$'):gsub('.git', '') .. '/' .. plugins[i]['file'] -- get the dest dir @@ -106,9 +107,15 @@ local function startinstall() '/' .. plugins[i]['file'] if fileexists(pluginfile) then - checkupdates(i, pluginfile, plugins[i][1]) + -- if we need to update, update + if checkupdates(i) then + logwrite(plugins[i]['file'] .. ' is updating.') + clonegit(i) + else + logwrite(plugins[i]['file'] .. ' is up to date!') + end else - clonegit(plugins[i][1]) + clonegit(i) end -- copy the file contents over to the desired location |