# # # add_dir "tests/changelog_editor" # # add_file "tests/changelog_editor/__driver__.lua" # content [b62305226b6f71d30943691986ba4a2e72bab153] # # add_file "tests/changelog_editor/changelog.lua" # content [b6eb964c1ffd38244100bbdea4177123d794b4ee] # # patch "cmd_ws_commit.cc" # from [589f05e5e765e61e79a055389fb742d48e8a9f97] # to [1627f47b908995680ca226cfeb94b0ca5a7e904e] # # patch "contrib/edit_comment_from_changelog.lua" # from [392821013c884731eaef31836acab2c2c5938373] # to [fa734b0c03818ea1790aa939ac3db59441eec9fc] # # patch "tests/_MTN_files_handled_correctly_in_aborted_commit/bad_edit_comment.lua" # from [98cfa1aefd465bf9b3e8169c40c33ccc204fdbfd] # to [bb3533964abf2e17d7d7ca490589c497a50285d8] # # patch "tests/commit_using__MTN_log_and_--message/commit_log.lua" # from [09c926209c317efc447dbe6448fe891c2d86e958] # to [e1b07045d69de57d75e5b73df41124c2c94b315d] # # patch "tests/commit_with_--message-file/commit_log.lua" # from [09c926209c317efc447dbe6448fe891c2d86e958] # to [e1b07045d69de57d75e5b73df41124c2c94b315d] # ============================================================ --- tests/changelog_editor/__driver__.lua b62305226b6f71d30943691986ba4a2e72bab153 +++ tests/changelog_editor/__driver__.lua b62305226b6f71d30943691986ba4a2e72bab153 @@ -0,0 +1,162 @@ +mtn_setup() +addfile("a", "hello world") +commit() +writefile("a", "aaa") + +check(get("changelog.lua")) + +-- status warns with bad date format + +check(mtn("status"), 0, false, false) +check(mtn("status", "--date-format", "%F"), 0, false, true) +check(qgrep("date format", "stderr")) + + +-- commits that fail + + +-- commit fails with bad date format + +check(mtn("commit", "--date-format", "%F"), 1, false, true) +check(qgrep("date format", "stderr")) + +-- commit fails with empty message + +writefile("_MTN/log", "empty message") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("empty log message", "stderr")) + +-- commit fails with modified/missing instructions + +writefile("_MTN/log", "missing instructions") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("instructions not found", "stderr")) + +-- commit fails with modified/missing separator, Revision: or Parent: lines + +writefile("_MTN/log", "missing separator") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Revision or Parent header not found", "stderr")) + +writefile("_MTN/log", "missing revision") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Revision or Parent header not found", "stderr")) + +writefile("_MTN/log", "missing parent") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Revision or Parent header not found", "stderr")) + +-- commit fails with modified/missing Author: line + +writefile("_MTN/log", "missing author") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Author header not found", "stderr")) + +-- commit fails with empty Author: line + +writefile("_MTN/log", "empty author") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Author header empty", "stderr")) + +-- commit fails with modified/missing Date: line + +writefile("_MTN/log", "missing date") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Date header not found", "stderr")) + +-- commit fails with empty Date: line + +writefile("_MTN/log", "empty date") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Date header empty", "stderr")) + +-- commit fails with modified/missing Branch: line + +writefile("_MTN/log", "missing branch") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Branch header not found", "stderr")) + +-- commit fails with empty Branch: line + +writefile("_MTN/log", "empty branch") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("Branch header empty", "stderr")) + +-- commit fails with modified/missing ChangeLog section + +writefile("_MTN/log", "missing changelog") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("ChangeLog header not found", "stderr")) + +-- commit fails with missing Change summary section + +writefile("_MTN/log", "missing summary") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("change summary not found", "stderr")) + +-- commit fails with duplicated Changes: section + +writefile("_MTN/log", "duplicated summary") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("text following summary", "stderr")) + +-- commit fails with new text after Changes: section + +writefile("_MTN/log", "trailing text") +check(mtn("commit", "--rcfile=changelog.lua"), 1, false, true) +check(qgrep("text following summary", "stderr")) + + +-- commits that succeed + + +-- test unchanged --date, --author and --branch options + +writefile("a", "a2.1") +writefile("_MTN/log", "fine") +check(mtn("commit", "--rcfile=changelog.lua", "--date", "2010-01-01T01:01:01", "--author", "bobo", "--branch", "left"), 0, false, false) +check(mtn("log", "--last", "1", "--no-graph"), 0, true, false) +check(qgrep("Date: 2010-01-01T01:01:01", "stdout")) +check(qgrep("Author: bobo", "stdout")) +check(qgrep("Branch: left", "stdout")) + +-- test changed --date, --author and --branch options + +writefile("a", "a2.2") +writefile("_MTN/log", "change author/date/branch") +check(mtn("commit", "--rcfile=changelog.lua", "--date", "2010-01-01T01:01:01", "--author", "bobo", "--branch", "left"), 0, false, false) +check(mtn("log", "--last", "1", "--no-graph"), 0, true, false) +check(not qgrep("Date: 2010-01-01T01:01:01", "stdout")) +check(not qgrep("Author: bobo", "stdout")) +check(not qgrep("Branch: left", "stdout")) + +-- test unchanged date gets updated to reflect current time + +writefile("a", "a3.1") +writefile("_MTN/log", "sleep") +check(mtn("commit", "--rcfile=changelog.lua"), 0, false, false) +check(mtn("log", "--last", "1", "--no-graph"), 0, true, false) +log = readfile("stdout") +old = string.match(log, "Old: ([^\n]*)") +new = string.match(log, "Date: ([^\n]*)") +check(old ~= new) + +-- test changed date does not get updated + +writefile("a", "a3.2") +writefile("_MTN/log", "change date") +check(mtn("commit", "--rcfile=changelog.lua"), 0, false, false) +check(mtn("log", "--last", "1", "--no-graph"), 0, true, false) +check(qgrep("Date: 2010-01-01T01:01:01", "stdout")) + +-- message on same line as ChangeLog: header + +writefile("a", "a4") +writefile("_MTN/log", "changelog line") +check(mtn("commit", "--rcfile=changelog.lua"), 0, false, false) + +-- message filling entire ChangeLog section (no leading/trailing blank lines) + +writefile("a", "a5") +writefile("_MTN/log", "full changelog") +check(mtn("commit", "--rcfile=changelog.lua"), 0, false, false) ============================================================ --- tests/changelog_editor/changelog.lua b6eb964c1ffd38244100bbdea4177123d794b4ee +++ tests/changelog_editor/changelog.lua b6eb964c1ffd38244100bbdea4177123d794b4ee @@ -0,0 +1,58 @@ +function edit_comment(user_log_file) + + -- commits that fail + + if (string.find(user_log_file, "\nempty message\n")) then + return string.gsub(user_log_file, "\nempty message\n", "") + elseif (string.find(user_log_file, "\nmissing instructions\n")) then + return "foobar" .. user_log_file + elseif (string.find(user_log_file, "\nmissing separator\n")) then + return string.gsub(user_log_file, "---------------\n", "\n") + elseif (string.find(user_log_file, "\nmissing revision\n")) then + return string.gsub(user_log_file, "\nRevision:", "\nrevision:") + elseif (string.find(user_log_file, "\nmissing parent\n")) then + return string.gsub(user_log_file, "\nAuthor:", "foobar\nAuthor:") + elseif (string.find(user_log_file, "\nmissing author\n")) then + return string.gsub(user_log_file, "\nAuthor:", "\nAutor:") + elseif (string.find(user_log_file, "\nempty author\n")) then + return string.gsub(user_log_file, "\nAuthor: [^\n]*\n", "\nAuthor: \n") + elseif (string.find(user_log_file, "\nmissing date\n")) then + return string.gsub(user_log_file, "\nDate:", "\nDate") + elseif (string.find(user_log_file, "\nempty date\n")) then + return string.gsub(user_log_file, "\nDate: [^\n]*\n", "\nDate: \n") + elseif (string.find(user_log_file, "\nmissing branch\n")) then + return string.gsub(user_log_file, "\nBranch:", "\nranch:") + elseif (string.find(user_log_file, "\nempty branch\n")) then + return string.gsub(user_log_file, "\nBranch: [^\n]*\n", "\nBranch: \n") + elseif (string.find(user_log_file, "\nmissing changelog\n")) then + return string.gsub(user_log_file, "\nChangeLog:", "\n") + elseif (string.find(user_log_file, "\nmissing summary\n")) then + return string.gsub(user_log_file, "\nChanges against parent", "\nChanges against foobar") + elseif (string.find(user_log_file, "\nduplicated summary\n")) then + return string.gsub(user_log_file, "(Changes against parent.*)", "%1%1") + elseif (string.find(user_log_file, "\ntrailing text\n")) then + return user_log_file .. "foobar" + end + + -- commits that succeed + + if (string.find(user_log_file, "\nchange author/date/branch\n")) then + result = user_log_file + result = string.gsub(result, "\nDate: [^\n]*\n", "\nDate: 2010-02-02T02:02:02\n") + result = string.gsub(result, "\nAuthor: bobo\n", "\nAuthor: baba\n") + result = string.gsub(result, "\nBranch: left\n", "\nBranch: right\n") + return result + elseif (string.find(user_log_file, "\nsleep\n")) then + date = string.match(user_log_file, "\nDate: ([^\n]*)") + sleep(2) + return string.gsub(user_log_file, "\nChangeLog: \n\nsleep", "\nChangeLog: \n\nOld: " .. date) + elseif (string.find(user_log_file, "\nchange date\n")) then + return string.gsub(user_log_file, "\nDate: [^\n]*\n", "\nDate: 2010-01-01T01:01:01\n") + elseif (string.find(user_log_file, "\nchangelog line\n")) then + return string.gsub(user_log_file, "\nChangeLog: \n\nchangelog line", "\nChangeLog: message on changelog line") + elseif (string.find(user_log_file, "\nfull changelog\n")) then + return string.gsub(user_log_file, "\nChangeLog: .*\nChanges against parent", "\nChangeLog: no\nspace\naround\nthis\nchangelog\nChanges against parent") + end + + return user_log_file +end ============================================================ --- cmd_ws_commit.cc 589f05e5e765e61e79a055389fb742d48e8a9f97 +++ cmd_ws_commit.cc 1627f47b908995680ca226cfeb94b0ca5a7e904e @@ -187,7 +187,7 @@ get_log_message_interactively(lua_hooks E(message.read(instructions()), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (missing/modified instructions).")); + "Commit failed (instructions not found).")); utf8 const AUTHOR(_("Author: ")); utf8 const DATE(_("Date: ")); @@ -198,38 +198,39 @@ get_log_message_interactively(lua_hooks // Revision: // Parent: // Parent: + // Author: - size_t pos = header().find(AUTHOR()); + size_t pos = header().find(AUTHOR()); // look in unedited header I(pos != string::npos); string prefix = header().substr(0, pos); E(message.read(prefix), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (missing/modified Revision or Parent header).")); + "Commit failed (Revision or Parent header not found).")); // Author: E(message.read(AUTHOR()), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (missing Author header).")); + "Commit failed (Author header not found).")); author = message.readline(); E(!author.empty(), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (empty Author header).")); + "Commit failed (Author header empty).")); // Date: E(message.read(DATE()), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (missing Date header).")); + "Commit failed (Date header not found).")); string d = message.readline(); E(!d.empty(), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (empty Date header).")); + "Commit failed (Date header empty).")); if (date_fmt.empty()) date = date_t(d); @@ -240,13 +241,13 @@ get_log_message_interactively(lua_hooks E(message.read(BRANCH()), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (missing Branch header).")); + "Commit failed (Branch header not found).")); string b = message.readline(); E(!b.empty(), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (empty Branch header).")); + "Commit failed (Branch header empty).")); branch = branch_name(b, origin::user); @@ -254,7 +255,7 @@ get_log_message_interactively(lua_hooks E(message.read(CHANGELOG()), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (missing ChangeLog header).")); + "Commit failed (ChangeLog header not found).")); // remove the summary before extracting the changelog content @@ -262,7 +263,7 @@ get_log_message_interactively(lua_hooks { E(message.contains(summary()), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" - "Commit failed (missing or modified summary).")); + "Commit failed (change summary not found).")); E(message.remove(summary()), origin::user, F("Modifications outside of Author, Date, Branch or ChangeLog.\n" @@ -1356,9 +1357,15 @@ CMD(commit, "commit", "ci", CMD_REF(work string author = app.opts.author(); if (app.opts.date_given) - date = app.opts.date; + { + date = app.opts.date; + L(FL("using specified commit date %s") % date); + } else - date = now; + { + date = now; + L(FL("using current commit date %s") % date); + } if (author.empty()) { @@ -1536,7 +1543,10 @@ CMD(commit, "commit", "ci", CMD_REF(work // update it to reflect the current time. if (date == now && !app.opts.date_given) - date = date_t::now(); + { + date = date_t::now(); + L(FL("updating commit date %s") % date); + } project.put_standard_certs(keys, restricted_rev_id, ============================================================ --- contrib/edit_comment_from_changelog.lua 392821013c884731eaef31836acab2c2c5938373 +++ contrib/edit_comment_from_changelog.lua fa734b0c03818ea1790aa939ac3db59441eec9fc @@ -1,11 +1,11 @@ std_edit_comment = edit_comment std_edit_comment = edit_comment -function edit_comment(basetext, user_log_message) +function edit_comment(user_log_message) local tmp, tname = temp_file() if (tmp == nil) then return nil end if (user_log_message == "") then local ChangeLog = io.open("ChangeLog", "r") if ChangeLog == nil then - return std_edit_comment(basetext, user_log_message) + return std_edit_comment(user_log_message) end local line = ChangeLog:read() local msg = "" @@ -23,5 +23,5 @@ function edit_comment(basetext, user_log user_log_message = msg io.close(ChangeLog) end - return std_edit_comment(basetext, user_log_message) + return std_edit_comment(user_log_message) end ============================================================ --- tests/_MTN_files_handled_correctly_in_aborted_commit/bad_edit_comment.lua 98cfa1aefd465bf9b3e8169c40c33ccc204fdbfd +++ tests/_MTN_files_handled_correctly_in_aborted_commit/bad_edit_comment.lua bb3533964abf2e17d7d7ca490589c497a50285d8 @@ -1,3 +1,3 @@ -function edit_comment(basetext, user_log_message) +function edit_comment(user_log_message) return "" end ============================================================ --- tests/commit_using__MTN_log_and_--message/commit_log.lua 09c926209c317efc447dbe6448fe891c2d86e958 +++ tests/commit_using__MTN_log_and_--message/commit_log.lua e1b07045d69de57d75e5b73df41124c2c94b315d @@ -1,3 +1,3 @@ -function edit_comment(summary, user_log_file) +function edit_comment(user_log_file) return user_log_file end ============================================================ --- tests/commit_with_--message-file/commit_log.lua 09c926209c317efc447dbe6448fe891c2d86e958 +++ tests/commit_with_--message-file/commit_log.lua e1b07045d69de57d75e5b73df41124c2c94b315d @@ -1,3 +1,3 @@ -function edit_comment(summary, user_log_file) +function edit_comment(user_log_file) return user_log_file end