diff options
Diffstat (limited to 'lib/gitano/command.lua')
-rw-r--r-- | lib/gitano/command.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua index bde7c54..023eb49 100644 --- a/lib/gitano/command.lua +++ b/lib/gitano/command.lua @@ -318,6 +318,45 @@ assert(register_cmd("set-owner", builtin_set_owner_short, builtin_set_owner_prep, builtin_set_owner_run, true, false)) +local builtin_set_head_short = "Set the repo's HEAD symbolic reference" +local builtin_set_head_helptext = [[ +usage: set-head <repo> <ref> + +Sets the HEAD of the repository to the given ref. You may need to be +the owner of the repository to use this command. +]] + +local function builtin_set_head_validate(conf, repo, cmdline) + if not repo or repo.is_nascent then + log.error("Cannot set the HEAD on a nascent repository") + return false + end + if #cmdline ~= 3 then + log.error("set-head takes a repository and a ref") + return false + end + return true +end + +local function builtin_set_head_prep(conf, repo, cmdline, context) + context.operation = "sethead" + context.ref = cmdline[3] + return repo:run_lace(context) +end + +local function builtin_set_head_run(conf, repo, cmdline, env) + local ok, msg = repo:set_head(cmdline[3]) + if not ok then + log.fatal(msg) + end + return "exit", 0 +end + +assert(register_cmd("set-head", builtin_set_head_short, + builtin_set_head_helptext, + builtin_set_head_validate, builtin_set_head_prep, + builtin_set_head_run, true, false)) + local builtin_readme_short = "View readme for a repository (if present)" local builtin_readme_helptext = [[ usage: readme <reponame> |