Created
September 30, 2010 22:08
-
-
Save mkottman/605411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/lua | |
require 'lfs' | |
-- Path to where packages are located | |
REPO = 'packages' | |
-- List of packages (e.g. loaded from dist manifest) | |
PACKAGES = { | |
p1 = true, p2 = true, p3 = true, | |
} | |
function git(...) | |
local args = {...} | |
table.insert(args, 1, 'git') | |
local cmd = table.concat(args, ' ') | |
print('Executing:', cmd) | |
os.execute(cmd) | |
end | |
-- Check, whether the current directory has a repo. If not, creates the .last | |
-- file, which contains the number of the last tag, and adds it to .gitignore | |
if not lfs.attributes('.last') then | |
local f = io.open('.last', 'w') | |
f:write('0') | |
f:close() | |
f = io.open('.gitignore', 'w') | |
f:write('.last\n') | |
f:close() | |
git "init -q" | |
git "add .gitignore" | |
git "commit -q -m 'Versioning started'" | |
end | |
-- Commits using `comment` and creates the next tag (1, 2, 3, ...) | |
-- and writes the new number in .last | |
function createTag(comment) | |
git("commit -q -m", ('%q'):format(comment)) | |
local f = io.open('.last') | |
local tagno = f:read('*n') | |
tagno = tagno + 1 | |
f:close() | |
git("tag", tagno) | |
f = io.open('.last', 'w') | |
f:write(tagno) | |
f:close() | |
end | |
local command = arg[1] | |
if command == 'install' then | |
local package = arg[2] | |
assert(package, "Usage: gitdist install package") | |
assert(PACKAGES[package], "Package " .. package .. " does not exist") | |
git("remote", "add", package, REPO .. '/' .. package) | |
git("fetch", "-q", package) | |
git("merge", "-q --no-commit", package..'/master') | |
createTag("Installed "..package) | |
elseif command == 'uninstall' then | |
local package = arg[2] | |
assert(package, "Usage: gitdist uninstall package") | |
createTag("Uninstalled "..package) | |
elseif command =='clean' then | |
os.execute('rm -rf .git .last') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment