# # add_file "tests/t_commit_msgfile.at" # # patch "app_state.cc" # from [99273877068314cdc8d24e06032a022e72e01352] # to [39251492f7af52437b24e862a27b64d510cb0df1] # # patch "app_state.hh" # from [a5ac3a99f998fee5a71b4f6201e6d26b086c7589] # to [791f2012071e9f37c1d64b714aa32fe669ffcd7c] # # patch "commands.cc" # from [0f98a702a8e1e21a444c42c7a79ec359f7f441c8] # to [a8ed896668d925eace10eb6e702fcb0b270dcc40] # # patch "monotone.1" # from [2b4b5dcbaba333709862fe47c0f02647e138a315] # to [64c4d756237b9b94182647ca7cd9ac2ee557087d] # # patch "monotone.cc" # from [bdcc7b74c7406ae184eb45958ee49ef02980e4fd] # to [3b0c50406d41dc42a457a8b2f34158b1f29f2e7c] # # patch "monotone.texi" # from [1043aaa99cad1d0060f75058661a71ad85c12ac5] # to [84e0e5505c11cfe360f3fb2d640dce5949ffeba3] # # patch "options.hh" # from [de2a21d88f641eeb889184d57af3c433b91556ec] # to [4c2651f57f221b2224b9a9dca93a4b1e9c99b281] # # patch "tests/t_commit_msgfile.at" # from [] # to [8ee2818fe2ba49cdab72bf4e0a8b4b95001dbbaa] # # patch "testsuite.at" # from [00f75eef6202608c3cdfb512a2ef98014dda907a] # to [16f6a7eb239fb44d34b1b3bbda7817ce32317151] # --- app_state.cc +++ app_state.cc @@ -274,6 +274,12 @@ } void +app_state::set_msgfile(utf8 const & m) +{ + msgfile = 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 msgfile; 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_msgfile(utf8 const & msgfile); 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,31 @@ 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 --msgfile ... + N(app.message().length() == 0 || app.msgfile().length() == 0, + F("--message and --msgfile 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.msgfile().length() > 0 && has_contents_user_log()), + F("MT/log is non-empty and --msgfile supplied\n" + "perhaps move or delete MT/log,\n" + "or remove --msgfile from the command line?")); + + // fill app.message with msgfile contents + if (app.msgfile().length() > 0) + { + local_path msgpath(app.msgfile()); + N(file_exists(msgpath) , F("message file \"%s\" not found") % app.msgfile()); + + data dat; + read_data(msgpath, dat); + app.message = dat(); + } + if (app.message().length() > 0) log_message = app.message(); else --- monotone.1 +++ monotone.1 @@ -144,10 +144,12 @@ \fBrename\fP \fI \fI\fP Rename files from \fI \fP to \fI \fP in working copy. .TP -\fBcommit\fP \fI[--message=] [...]\fP +\fBcommit\fP \fI[(--message=|--msgfile=)] [...]\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. +the command line, it is used; if a --msgfile option is provided, the +content of the named file will be used as a commit message. +Otherwise a log message editor will be invoked. +If the optional file MT/log exists, its content is used to prefill the editor. .TP \fBupdate\fP \fI[revision-id]\fP Update working copy. @@ -261,10 +263,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 --msgfile .TP \fB-m \fI\fP An alias for \fB--message=\fI\fP .TP +\fB--msgfile=\fI\fP +Use the content of the given file as the changelog when committing a +new revision 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. +.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}, + {"msgfile", 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_msgfile(string(argstr)); + break; + case OPT_DATE: app.set_date(string(argstr)); break; --- monotone.texi +++ monotone.texi @@ -3408,12 +3408,14 @@ @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 +loading the evision 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 @@ -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{--msgfile} 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,13 @@ Rename files from @i{} to @i{} in working copy. @comment TROFF INPUT: .TP address@hidden @b{commit} @i{[--message=log message] [...]} address@hidden @b{commit} @i{[--message=log message | --msgfile=log message file] [...]} 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. +provided on the command line, it is used; if a --msgfile address@hidden is provided, the content of the named file is used as +a commit message. +Otherwise a log message editor will be invoked. If @i{MT/log} exists, +its content will be passed to the message editor. @comment TROFF INPUT: .TP @item @b{update} @i{[revision]} @@ -6477,6 +6486,12 @@ 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. 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_msgfile.at +++ tests/t_commit_msgfile.at @@ -0,0 +1,51 @@ +AT_SETUP([commit with --msgfile]) + +MONOTONE_SETUP + +AT_CHECK(rm -f MT/log) + +#-------------------- +#first, verify that --msgfile 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 --msgfile option +]) + +AT_CHECK(MONOTONE --branch=testbranch commit --msgfile=msgfile.txt, [], [ignore], [ignore]) + +TSHA=`BASE_REVISION` +AT_CHECK(MONOTONE ls certs $TSHA, [], [stdout], [ignore]) +AT_CHECK(grep -q 'this commit uses the --msgfile option' stdout, []) + +#-------------------- +#then verify that --message and --msgfile together cause an error +#-------------------- + +AT_DATA(input2.txt, [another file +]) + +AT_CHECK(MONOTONE add input2.txt, [], [ignore], [ignore]) + +AT_CHECK(MONOTONE --branch=testbranch commit --msgfile=msgfile.txt --message="also a message", [1], [ignore], [ignore]) + +# -------------------- +# finally, --msgfile 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 --msgfile=msgfile.txt, [1], [ignore], [ignore]) + +AT_CLEANUP --- testsuite.at +++ testsuite.at @@ -612,3 +612,4 @@ m4_include(tests/t_monotone_up.at) m4_include(tests/t_drop_vs_patch_rename.at) m4_include(tests/t_unreadable_MT.at) +m4_include(tests/t_commit_msgfile.at)