#
# add_file "tests/t_commit_message_file.at"
#
# patch "ChangeLog"
# from [6bab66b8552bb212be3d0ef97a96b403a46782bc]
# to [259c2fe395420c6107295c1d4bd1715fb4811e7f]
#
# patch "app_state.cc"
# from [99273877068314cdc8d24e06032a022e72e01352]
# to [392734be5cdd5ba62dd214b28aa434e67b678171]
#
# patch "app_state.hh"
# from [a5ac3a99f998fee5a71b4f6201e6d26b086c7589]
# to [d0009cab364bc2ee2fa53170aa4bc61ce16a6f11]
#
# patch "commands.cc"
# from [82065a698ea04492cefc84b2935774b9fc3b92a8]
# to [00ef62e671f25b832bb1280d1c66c0bbc7c39545]
#
# patch "monotone.1"
# from [2b4b5dcbaba333709862fe47c0f02647e138a315]
# to [5783b0220be5236c92caf72d3f42add790f654bc]
#
# patch "monotone.cc"
# from [42020d9e45090f7a39457f9e376a968fcb003fb4]
# to [0d67d084ddfc9f143006b339c925a5fe86dce4c5]
#
# patch "monotone.texi"
# from [1043aaa99cad1d0060f75058661a71ad85c12ac5]
# to [5519123717fd914cd03e67098b48b821eb551821]
#
# patch "options.hh"
# from [de2a21d88f641eeb889184d57af3c433b91556ec]
# to [4c2651f57f221b2224b9a9dca93a4b1e9c99b281]
#
# patch "tests/t_commit_message_file.at"
# from []
# to [f09e3f925f53d49d5bcd0d4e3d7673b328485331]
#
# patch "testsuite.at"
# from [341cd75fc0ab1bbe6ebc96c826840285edbe7020]
# to [9d5a9fc124934f2f1ab6415377d8ce12ec54fb37]
#
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,14 @@
+2005-05-12 Riccardo Ghetta
+
+ * options.hh (OPT_MSGFILE): New option.
+ * monotone.cc (message-file): New option.
+ (cpp_main): Handle it.
+ * app_state.{cc,hh} (set_message_file): New function.
+ * commands.cc (commit): Accept and handle new option.
+ * monotone.1, monotone.texi: Document it.
+ * tests/t_commit_message_file.at: New test.
+ * testsuite.at: Add it.
+
2005-05-12 Timothy Brownawell
* (20 files): Do not indent with both tabs and spaces in the same file.
--- app_state.cc
+++ app_state.cc
@@ -274,6 +274,12 @@
}
void
+app_state::set_message_file(utf8 const & m)
+{
+ message_file = m;
+}
+
+void
app_state::set_date(utf8 const & d)
{
date = d;
--- app_state.hh
+++ app_state.hh
@@ -33,6 +33,7 @@
bool rcfiles;
options_map options;
utf8 message;
+ utf8 message_file;
utf8 date;
utf8 author;
utf8 search_root;
@@ -65,6 +66,7 @@
void set_signing_key(utf8 const & key);
void set_root(utf8 const & root);
void set_message(utf8 const & message);
+ void set_message_file(utf8 const & message_file);
void set_date(utf8 const & date);
void set_author(utf8 const & author);
void set_depth(long depth);
--- commands.cc
+++ commands.cc
@@ -2232,7 +2232,7 @@
CMD(commit, "working copy", "[PATH]...",
"commit working copy to database",
- OPT_BRANCH_NAME % OPT_MESSAGE % OPT_DATE % OPT_AUTHOR)
+ OPT_BRANCH_NAME % OPT_MESSAGE % OPT_MSGFILE % OPT_DATE % OPT_AUTHOR)
{
string log_message("");
revision_set rs;
@@ -2264,12 +2264,28 @@
L(F("new manifest %s\n") % rs.new_manifest);
L(F("new revision %s\n") % rid);
- // get log message
- N(!(app.message().length() > 0 && has_contents_user_log()),
+ // can't have both a --message and a --message-file ...
+ N(app.message().length() == 0 || app.message_file().length() == 0,
+ F("--message and --message-file are mutually exclusive"));
+
+ N(!( app.message().length() > 0 && has_contents_user_log()),
F("MT/log is non-empty and --message supplied\n"
"perhaps move or delete MT/log,\n"
"or remove --message from the command line?"));
+ N(!( app.message_file().length() > 0 && has_contents_user_log()),
+ F("MT/log is non-empty and --message-file supplied\n"
+ "perhaps move or delete MT/log,\n"
+ "or remove --message-file from the command line?"));
+
+ // fill app.message with message_file contents
+ if (app.message_file().length() > 0)
+ {
+ data dat;
+ read_data_for_command_line(app.message_file(), dat);
+ app.message = dat();
+ }
+
if (app.message().length() > 0)
log_message = app.message();
else
--- monotone.1
+++ monotone.1
@@ -144,10 +144,17 @@
\fBrename\fP \fI \fI\fP
Rename files from \fI \fP to \fI \fP in working copy.
.TP
-\fBcommit\fP \fI[--message=] [...]\fP
-Commit working copy to database. If a --message option is provided on
-the command line, it is used; otherwise a log message editor will be
-invoked.
+\fBcommit\fP \fI[(--message=|--message-file=)] [...]\fP
+Commit working copy to database. Each commit has a changelog message
+associated with it. If --message is provided on the command line, it
+is used; if --message-file is provided, the content of the
+named file will be used as a commit message. If the filename is '-'
+the commit message will be read from standard input. Otherwise a log
+message editor will be invoked. If the file MT/log exists
+and is non-empty, its content is used to prefill the editor. You
+cannot specify both --message and --message-file at the same time, and
+if MT/log exists and is non-empty, you can cannot specify either of them
+at all.
.TP
\fBupdate\fP \fI[revision-id]\fP
Update working copy.
@@ -261,10 +268,18 @@
rather than invoking the log message editor. Currently this option only
applies to the commit command but it may also apply to the comment
command in the future.
+This option is alternative to --message-file
.TP
\fB-m \fI\fP
An alias for \fB--message=\fI\fP
.TP
+\fB--message-file=\fI\fP
+Use the content of the given file as the changelog when committing a
+new revision rather than invoking the log message editor. If the passed filename is '-' the changelog message will be read from standard input.
+Currently this option only applies to the commit command but it may also apply
+to the comment command in the future.
+This option is alternative to --message.
+.TP
\fB--author=\fI\fP
Use the given author as the value of the "author" cert when committing
a new revision, rather than the default author. Useful when
--- monotone.cc
+++ monotone.cc
@@ -44,6 +44,7 @@
{"branch", 'b', POPT_ARG_STRING, &argstr, OPT_BRANCH_NAME, "select branch cert for operation", NULL},
{"revision", 'r', POPT_ARG_STRING, &argstr, OPT_REVISION, "select revision id for operation", NULL},
{"message", 'm', POPT_ARG_STRING, &argstr, OPT_MESSAGE, "set commit changelog message", NULL},
+ {"message-file", 0, POPT_ARG_STRING, &argstr, OPT_MSGFILE, "set filename containing commit changelog message", NULL},
{"date", 0, POPT_ARG_STRING, &argstr, OPT_DATE, "override date/time for commit", NULL},
{"author", 0, POPT_ARG_STRING, &argstr, OPT_AUTHOR, "override author for commit", NULL},
{"depth", 0, POPT_ARG_LONG, &arglong, OPT_DEPTH, "limit the log output to the given number of entries", NULL},
@@ -333,6 +334,10 @@
app.set_message(string(argstr));
break;
+ case OPT_MSGFILE:
+ app.set_message_file(absolutify_for_command_line(tilde_expand(string(argstr))));
+ break;
+
case OPT_DATE:
app.set_date(string(argstr));
break;
--- monotone.texi
+++ monotone.texi
@@ -3408,16 +3408,18 @@
@item monotone commit
@itemx monotone commit address@hidden
address@hidden monotone commit address@hidden
@itemx monotone commit @var{pathname...}
@itemx monotone commit address@hidden @var{pathname...}
address@hidden monotone commit address@hidden @var{pathname...}
This command looks at your working copy, decides which files have
-changed, and saves the changes to your database. It does this by
-loading the revision named in the @file{MT/revision} file, locating
-the base manifest for your working copy, applying any changes
-described in the @file{MT/work} file, and then comparing the updated
-base manifest to the files it finds in your working copy, to determine
-which files have been edited.
+changed, and saves the changes to your database. It does this by loading
+the revision named in the @file{MT/revision} file, locating the base
+manifest for your working copy, applying any changes described in the
address@hidden/work} file, and then comparing the updated base manifest to the
+files it finds in your working copy, to determine which files have been
+edited.
For each edited file, a delta is copied into the database. Then the
newly constructed manifest is recorded (as a delta) and finally the
@@ -3438,6 +3440,11 @@
copy. Specifying only the pathname "." will restrict @command{commit}
to files changed within the current subdirectory of the working copy.
+The @option{--message} and @option{--message-file} options are mutually
+exclusive. Both provide a @var{logmsg} describing the commit.
address@hidden actually specifies the name of the file containing
+the log message, while @option{--message} provides it directly.
+
The @file{MT/log} file can be edited by the user during their daily work
to record the changes made to the working copy. When running the
@command{commit} command without a @var{logmsg} supplied, the contents
@@ -6343,11 +6350,17 @@
Rename files from @i{} to @i{} in working copy.
@comment TROFF INPUT: .TP
address@hidden @b{commit} @i{[--message=log message] [...]}
-Commit working copy to database. If a --message @option{option} is
-provided on the command line, it is used; otherwise a log message
-editor will be invoked. If @i{MT/log} exists, its content will be
-passed to the message editor.
address@hidden @b{commit} @i{[--message=log message | --message-file=log message file] [...]}
+Commit working copy to database. Each commit has a changelog message
+associated with it. If @option{--message} is provided on the command
+line, it is used; if @option{--message-file} is provided, the content of
+the named file will be used as a commit message. If the filename is '-'
+the commit message will be read from standard input. Otherwise a log
+message editor will be invoked. If the file @file{MT/log} exists and is
+non-empty, its content is used to prefill the editor. You cannot
+specify both @option{--message} and @option{--message-file} at the same
+time, and if @file{MT/log} exists and is non-empty, you can cannot
+specify either of them at all.
@comment TROFF INPUT: .TP
@item @b{update} @i{[revision]}
@@ -6477,6 +6490,13 @@
two specific revisions. It will likely apply to other commands in the
future.
address@hidden @address@hidden}
+Use the content of the given file as the changelog when committing a new
+revision rather than invoking the log message editor. If the filename
+is '-' the changelog is read from standard input. Currently this option
+only applies to the commit command, but it may also apply to the comment
+command in the future.
+
@item @address@hidden}
@itemx @b{-m} @i{}
Use the given message as the changelog when committing a new revision
--- options.hh
+++ options.hh
@@ -29,3 +29,4 @@
#define OPT_AUTHOR 20
#define OPT_ALL_FILES 21
#define OPT_PIDFILE 22
+#define OPT_MSGFILE 23
--- tests/t_commit_message_file.at
+++ tests/t_commit_message_file.at
@@ -0,0 +1,150 @@
+AT_SETUP([commit with --message-file])
+
+MONOTONE_SETUP
+
+AT_CHECK(rm -f MT/log)
+
+#--------------------
+#first, verify that --message-file actually works
+#--------------------
+
+AT_DATA(input.txt, [version 0 of the file
+])
+
+AT_CHECK(MONOTONE add input.txt, [], [ignore], [ignore])
+
+AT_DATA(msgfile.txt, [this commit uses the --message-file option
+])
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=msgfile.txt, [], [ignore], [ignore])
+
+TSHA=`BASE_REVISION`
+AT_CHECK(MONOTONE ls certs $TSHA, [], [stdout], [ignore])
+AT_CHECK(grep -q 'this commit uses the --message-file option' stdout, [])
+
+#--------------------
+#also with a file coming outside the working copy
+#--------------------
+AT_CHECK(MONOTONE setup alt_wrk, [], [ignore], [ignore])
+
+AT_DATA(alt_wrk/input1.txt, [files... files...
+])
+
+AT_DATA(message-out-of-copy.txt, [out out out
+])
+
+AT_CHECK(cd alt_wrk && MONOTONE add input1.txt, [], [ignore], [ignore])
+
+AT_CHECK(cd alt_wrk && MONOTONE --branch=outbranch commit --message-file=../message-out-of-copy.txt, [], [ignore], [ignore])
+
+TSHA=`cd alt_wrk && BASE_REVISION`
+AT_CHECK(cd alt_wrk && MONOTONE ls certs $TSHA, [], [stdout], [ignore])
+AT_CHECK(grep -q 'out out out' stdout, [])
+
+#--------------------
+#start with the failures: non existing file
+#--------------------
+AT_DATA(input2.txt, [another file
+])
+
+AT_CHECK(MONOTONE add input2.txt, [], [ignore], [ignore])
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=to-be-or-not-to-be.txt, [1], [ignore], [ignore])
+
+#--------------------
+#then verify that --message and --message-file together cause an error
+#--------------------
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=msgfile.txt --message="also a message", [1], [ignore], [ignore])
+
+# --------------------
+# finally, --message-file and a filled MT/log should also fail
+# --------------------
+
+AT_DATA(commit_log.lua, [
+function edit_comment(summary, user_log_file)
+ return user_log_file
+end
+])
+
+AT_DATA(MT/log, [Log entry
+])
+
+AT_CHECK(MONOTONE --branch=testbranch --rcfile=commit_log.lua commit --message-file=msgfile.txt, [1], [ignore], [ignore])
+
+AT_CLEANUP
+AT_SETUP([commit with --message-file])
+
+MONOTONE_SETUP
+
+AT_CHECK(rm -f MT/log)
+
+#--------------------
+#first, verify that --message-file actually works
+#--------------------
+
+AT_DATA(input.txt, [version 0 of the file
+])
+
+AT_CHECK(MONOTONE add input.txt, [], [ignore], [ignore])
+
+AT_DATA(msgfile.txt, [this commit uses the --message-file option
+])
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=msgfile.txt, [], [ignore], [ignore])
+
+TSHA=`BASE_REVISION`
+AT_CHECK(MONOTONE ls certs $TSHA, [], [stdout], [ignore])
+AT_CHECK(grep -q 'this commit uses the --message-file option' stdout, [])
+
+#--------------------
+#also with a file coming outside the working copy
+#--------------------
+AT_CHECK(MONOTONE setup alt_wrk, [], [ignore], [ignore])
+
+AT_DATA(alt_wrk/input1.txt, [files... files...
+])
+
+AT_DATA(message-out-of-copy.txt, [out out out
+])
+
+AT_CHECK(cd alt_wrk && MONOTONE add input1.txt, [], [ignore], [ignore])
+
+AT_CHECK(cd alt_wrk && MONOTONE --branch=outbranch commit --message-file=../message-out-of-copy.txt, [], [ignore], [ignore])
+
+TSHA=`cd alt_wrk && BASE_REVISION`
+AT_CHECK(cd alt_wrk && MONOTONE ls certs $TSHA, [], [stdout], [ignore])
+AT_CHECK(grep -q 'out out out' stdout, [])
+
+#--------------------
+#start with the failures: non existing file
+#--------------------
+AT_DATA(input2.txt, [another file
+])
+
+AT_CHECK(MONOTONE add input2.txt, [], [ignore], [ignore])
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=to-be-or-not-to-be.txt, [1], [ignore], [ignore])
+
+#--------------------
+#then verify that --message and --message-file together cause an error
+#--------------------
+
+AT_CHECK(MONOTONE --branch=testbranch commit --message-file=msgfile.txt --message="also a message", [1], [ignore], [ignore])
+
+# --------------------
+# finally, --message-file and a filled MT/log should also fail
+# --------------------
+
+AT_DATA(commit_log.lua, [
+function edit_comment(summary, user_log_file)
+ return user_log_file
+end
+])
+
+AT_DATA(MT/log, [Log entry
+])
+
+AT_CHECK(MONOTONE --branch=testbranch --rcfile=commit_log.lua commit --message-file=msgfile.txt, [1], [ignore], [ignore])
+
+AT_CLEANUP
--- testsuite.at
+++ testsuite.at
@@ -636,3 +636,4 @@
m4_include(tests/t_drop_vs_patch_rename.at)
m4_include(tests/t_unreadable_MT.at)
m4_include(tests/t_cvsimport3.at)
+m4_include(tests/t_commit_message_file.at)