summaryrefslogtreecommitdiff
path: root/lib/gitano/command.lua
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-01 11:18:48 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-01 11:18:48 +0100
commitce591e6833f652c6e60b90a53420c5095e272b24 (patch)
tree0c9187c584123ead891b8d69826709ed1887648c /lib/gitano/command.lua
parentbcbe90e230c79f61b0a27d652d9c6789d62c083c (diff)
downloadgitano-ce591e6833f652c6e60b90a53420c5095e272b24.tar.gz
COMMAND: Add a set-head command
Diffstat (limited to 'lib/gitano/command.lua')
-rw-r--r--lib/gitano/command.lua39
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>