summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 17:45:44 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 17:45:44 +0100
commite4331d213e31f26dfc1e4bde0810732618f6346d (patch)
tree09f180c7468e034801d42b9697686e60036fffba
parentb80edbf10b277115c97a28354a88da97f74d0767 (diff)
downloadgall-e4331d213e31f26dfc1e4bde0810732618f6346d.tar.gz
GALL.COMMIT: Test commit creation
-rw-r--r--lib/gall/commit.lua11
-rw-r--r--test/test-gall.commit.lua196
2 files changed, 204 insertions, 3 deletions
diff --git a/lib/gall/commit.lua b/lib/gall/commit.lua
index 080c7ed..13e3556 100644
--- a/lib/gall/commit.lua
+++ b/lib/gall/commit.lua
@@ -145,6 +145,9 @@ local function _create(repo, data)
}
for i, v in ipairs(data.parents) do
cmd[#cmd+1] = "-p"
+ if not v.sha then
+ return nil, "Parent " .. tostring(i) .. " had no sha?"
+ end
cmd[#cmd+1] = v.sha
end
@@ -152,11 +155,13 @@ local function _create(repo, data)
data.message = data.message .. "\n"
end
- local why, sha = repo:_run_with_input_and_env(env, data.message,
- ll.chomp, unpack(cmd))
+ local why, sha, err = repo:_run_with_input_and_env(env, data.message,
+ ll.chomp, unpack(cmd))
if why ~= 0 then
- return nil, "commit-tree returned " .. tostring(why)
+ return nil, "commit-tree returned " .. tostring(why) ..
+ (sha or "") .. "\n" .. (err or "")
+
end
return repo:get(sha)
diff --git a/test/test-gall.commit.lua b/test/test-gall.commit.lua
index dfb5454..8fd6ed0 100644
--- a/test/test-gall.commit.lua
+++ b/test/test-gall.commit.lua
@@ -91,6 +91,202 @@ function suite.commit_signature()
assert(sig)
end
+function suite.commit_create()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = {
+ realname = "Test Author",
+ email = "author@test"
+ },
+ committer = {
+ realname = "Test Committer",
+ email = "committer@test"
+ },
+ message = "NEWCOMMIT",
+ parents = { head },
+ }
+ local newcommit = assert(gall.commit.create(repo, commitinfo))
+end
+
+function suite.commit_create_no_parents_ok()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = {
+ realname = "Test Author",
+ email = "author@test"
+ },
+ committer = {
+ realname = "Test Committer",
+ email = "committer@test"
+ },
+ message = "NEWCOMMIT",
+ }
+ local newcommit = assert(gall.commit.create(repo, commitinfo))
+end
+
+function suite.commit_create_bad_no_tree()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No tree"))
+end
+
+function suite.commit_create_bad_no_author()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No author"))
+end
+
+function suite.commit_create_bad_no_committer()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = {},
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No committer"))
+end
+
+function suite.commit_create_bad_no_author_name()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = {},
+ committer = {},
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No author name"))
+end
+
+function suite.commit_create_bad_no_author_email()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = { realname = "Author" },
+ committer = {},
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No author email"))
+end
+
+function suite.commit_create_bad_no_committer_name()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = { realname = "Author", email = "author@foo" },
+ committer = {},
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No committer name"))
+end
+
+function suite.commit_create_bad_no_committer_email()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = { realname = "Author", email = "author@foo" },
+ committer = { realname = "Committer" },
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No committer email"))
+end
+
+function suite.commit_create_bad_no_message()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = {
+ realname = "Test Author",
+ email = "author@test"
+ },
+ committer = {
+ realname = "Test Committer",
+ email = "committer@test"
+ },
+ parents = { head },
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("No message"))
+end
+
+function suite.commit_create_bad_parent_no_sha()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = {
+ realname = "Test Author",
+ email = "author@test"
+ },
+ committer = {
+ realname = "Test Committer",
+ email = "committer@test"
+ },
+ message = "NEWCOMMIT",
+ parents = { {} },
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("had no sha"))
+end
+
+function suite.commit_create_bad_parent_bad_sha()
+ local repo = test_repo()
+ local head = repo:get("HEAD").content
+ local tree = head.tree
+ local commitinfo = {
+ tree = tree,
+ author = {
+ realname = "Test Author",
+ email = "author@test"
+ },
+ committer = {
+ realname = "Test Committer",
+ email = "committer@test"
+ },
+ message = "NEWCOMMIT",
+ parents = { { sha = "BADSHA" } },
+ }
+ local ok, msg = gall.commit.create(repo, commitinfo)
+ assert(not ok)
+ assert(msg:find("BADSHA"))
+end
+
local count_ok = 0
for _, testname in ipairs(testnames) do
-- print("Run: " .. testname)