reduce number of opts for functions, and allow links with .git at the end
This commit is contained in:
37
eatit.lua
37
eatit.lua
@ -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
|
||||
|
Reference in New Issue
Block a user