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
|
||||||
end
|
end
|
||||||
|
|
||||||
local function clonegit(pluginlink)
|
-- get the requested git repos
|
||||||
logwrite('downloading ' .. pluginlink)
|
local function clonegit(i)
|
||||||
|
logwrite('downloading ' .. plugins[i][1])
|
||||||
|
|
||||||
-- construct the git cmd
|
-- 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
|
-- run the command and get the result for logging
|
||||||
local run = io.popen(cmd)
|
local run = io.popen(cmd)
|
||||||
@ -51,15 +52,16 @@ local function clonegit(pluginlink)
|
|||||||
run:close()
|
run:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function checkupdates(i, pluginfile, pluginlink)
|
-- check for updates
|
||||||
|
local function checkupdates(i)
|
||||||
local plugdir = opts.dl.dir .. '/' ..
|
local plugdir = opts.dl.dir .. '/' ..
|
||||||
string.match(pluginlink, '/([^/]+)$')
|
string.match(plugins[i][1], '/([^/]+)$'):gsub('.git', '')
|
||||||
|
|
||||||
local localhashcmd = 'cd ' .. plugdir ..
|
local localhashcmd = 'git -C ' .. plugdir .. ' log -1 --format=format:"%H"'
|
||||||
'; git log -1 --format=format:"%H"'
|
|
||||||
|
|
||||||
local remotehashcmd = 'cd ' .. plugdir ..
|
local remotehashcmd = 'git -C ' .. plugdir ..
|
||||||
'; git log -n 1 $(git branch -r | head -1 | cut -d " " -f 3)' ..
|
' log -n 1 $(git -C ' .. plugdir ..
|
||||||
|
' branch -r | head -1 | cut -d " " -f 3)' ..
|
||||||
' | head -1 | cut -d " " -f 2'
|
' | head -1 | cut -d " " -f 2'
|
||||||
|
|
||||||
local a = io.popen(localhashcmd)
|
local a = io.popen(localhashcmd)
|
||||||
@ -71,10 +73,9 @@ local function checkupdates(i, pluginfile, pluginlink)
|
|||||||
a:close()
|
a:close()
|
||||||
|
|
||||||
if localhash ~= remotehash then
|
if localhash ~= remotehash then
|
||||||
logwrite(plugins[i]['file'] .. ' is updating.')
|
return true
|
||||||
clonegit(pluginlink)
|
|
||||||
else
|
else
|
||||||
logwrite(plugins[i]['file'] .. ' is up to date!')
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ local function startinstall()
|
|||||||
|
|
||||||
-- get the file's dir
|
-- get the file's dir
|
||||||
local pluginfile = opts.dl.dir .. '/' ..
|
local pluginfile = opts.dl.dir .. '/' ..
|
||||||
string.match(plugins[i][1], '/([^/]+)$') ..
|
string.match(plugins[i][1], '/([^/]+)$'):gsub('.git', '') ..
|
||||||
'/' .. plugins[i]['file']
|
'/' .. plugins[i]['file']
|
||||||
|
|
||||||
-- get the dest dir
|
-- get the dest dir
|
||||||
@ -106,9 +107,15 @@ local function startinstall()
|
|||||||
'/' .. plugins[i]['file']
|
'/' .. plugins[i]['file']
|
||||||
|
|
||||||
if fileexists(pluginfile) then
|
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
|
else
|
||||||
clonegit(plugins[i][1])
|
clonegit(i)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- copy the file contents over to the desired location
|
-- copy the file contents over to the desired location
|
||||||
|
Reference in New Issue
Block a user