##// END OF EJS Templates
cmdutil: make commit message shown in text editor customizable by template...
FUJIWARA Katsunori -
r21924:5375ba75 default
parent child Browse files
Show More
@@ -2173,7 +2173,11 b' def commiteditor(repo, ctx, subs):'
2173 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
2173 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
2174 if not extramsg:
2174 if not extramsg:
2175 extramsg = _("Leave message empty to abort commit.")
2175 extramsg = _("Leave message empty to abort commit.")
2176 committext = buildcommittext(repo, ctx, subs, extramsg)
2176 tmpl = repo.ui.config('committemplate', 'changeset', '').strip()
2177 if tmpl:
2178 committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
2179 else:
2180 committext = buildcommittext(repo, ctx, subs, extramsg)
2177
2181
2178 # run editor in the repository root
2182 # run editor in the repository root
2179 olddir = os.getcwd()
2183 olddir = os.getcwd()
@@ -2189,6 +2193,22 b' def commitforceeditor(repo, ctx, subs, f'
2189
2193
2190 return text
2194 return text
2191
2195
2196 def buildcommittemplate(repo, ctx, subs, extramsg, tmpl):
2197 ui = repo.ui
2198 tmpl, mapfile = gettemplate(ui, tmpl, None)
2199
2200 try:
2201 t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False)
2202 except SyntaxError, inst:
2203 raise util.Abort(inst.args[0])
2204
2205 if not extramsg:
2206 extramsg = '' # ensure that extramsg is string
2207
2208 ui.pushbuffer()
2209 t.show(ctx, extramsg=extramsg)
2210 return ui.popbuffer()
2211
2192 def buildcommittext(repo, ctx, subs, extramsg):
2212 def buildcommittext(repo, ctx, subs, extramsg):
2193 edittext = []
2213 edittext = []
2194 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
2214 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
@@ -330,6 +330,64 b' If no suitable authentication entry is f'
330 for credentials as usual if required by the remote.
330 for credentials as usual if required by the remote.
331
331
332
332
333 ``committemplate``
334 ------------------
335
336 ``changeset`` configuration in this section is used as the template to
337 customize the text shown in the editor when committing.
338
339 In addition to pre-defined template keywords, commit log specific one
340 below can be used for customization:
341
342 ``extramsg``
343 String: Extra message (typically 'Leave message empty to abort
344 commit.'). This may be changed by some commands or extensions.
345
346 For example, the template configuration below shows as same text as
347 one shown by default::
348
349 [committemplate]
350 changeset = {desc}\n\n
351 HG: Enter commit message. Lines beginning with 'HG:' are removed.
352 HG: {extramsg}
353 HG: --
354 HG: user: {author}\n{ifeq(p2rev, "-1", "",
355 "HG: branch merge\n")
356 }HG: branch '{branch}'\n{if(currentbookmark,
357 "HG: bookmark '{currentbookmark}'\n") }{subrepos %
358 "HG: subrepo {subrepo}\n" }{file_adds %
359 "HG: added {file}\n" }{file_mods %
360 "HG: changed {file}\n" }{file_dels %
361 "HG: removed {file}\n" }{if(files, "",
362 "HG: no files changed\n")}
363
364 .. note::
365
366 For some problematic encodings (see :hg:`help win32mbcs` for
367 detail), this customization should be configured carefully, to
368 avoid showing broken characters.
369
370 For example, if multibyte character ending with backslash (0x5c) is
371 followed by ASCII character 'n' in the customized template,
372 sequence of backslash and 'n' is treated as line-feed unexpectedly
373 (and multibyte character is broken, too).
374
375 Customized template is used for commands below (``--edit`` may be
376 required):
377
378 - :hg:`backout`
379 - :hg:`commit`
380 - :hg:`fetch` (for merge commit only)
381 - :hg:`graft`
382 - :hg:`histedit`
383 - :hg:`import`
384 - :hg:`qfold`, :hg:`qnew` and :hg:`qrefresh`
385 - :hg:`rebase`
386 - :hg:`shelve`
387 - :hg:`sign`
388 - :hg:`tag`
389 - :hg:`transplant`
390
333 ``decode/encode``
391 ``decode/encode``
334 -----------------
392 -----------------
335
393
@@ -354,6 +354,48 b' test saving last-message.txt'
354
354
355 test saving last-message.txt
355 test saving last-message.txt
356
356
357 test that '[committemplate] changeset' definition and commit log
358 specific template keywords work well
359
360 $ cat >> .hg/hgrc <<EOF
361 > [committemplate]
362 > changeset = HG: this is customized commit template
363 > HG: {extramsg}
364 > {if(currentbookmark,
365 > "HG: bookmark '{currentbookmark}' is activated\n",
366 > "HG: no bookmark is activated\n")}{subrepos %
367 > "HG: subrepo '{subrepo}' is changed\n"}
368 > EOF
369
370 $ hg init sub2
371 $ echo a > sub2/a
372 $ hg -R sub2 add sub2/a
373 $ echo 'sub2 = sub2' >> .hgsub
374
375 $ HGEDITOR=cat hg commit -S -q
376 HG: this is customized commit template
377 HG: Leave message empty to abort commit.
378 HG: bookmark 'currentbookmark' is activated
379 HG: subrepo 'sub' is changed
380 HG: subrepo 'sub2' is changed
381 abort: empty commit message
382 [255]
383
384 $ hg bookmark --inactive currentbookmark
385 $ hg forget .hgsub
386 $ HGEDITOR=cat hg commit -q
387 HG: this is customized commit template
388 HG: Leave message empty to abort commit.
389 HG: no bookmark is activated
390 abort: empty commit message
391 [255]
392
393 $ cat >> .hg/hgrc <<EOF
394 > # disable customizing for subsequent tests
395 > [committemplate]
396 > changeset =
397 > EOF
398
357 $ cd ..
399 $ cd ..
358
400
359
401
@@ -26,10 +26,28 b" Should display 'First commit message'"
26 First commit message
26 First commit message
27
27
28 Testing changing message with -m
28 Testing changing message with -m
29 (this tests also that '--edit' can be used with '--message')
29 (this tests also that '--edit' can be used with '--message', and
30 that '[committemplate] changeset' definition and commit log specific
31 template keyword 'extramsg' work well)
32
33 $ cat >> .hg/hgrc <<EOF
34 > [committemplate]
35 > changeset = HG: this is customized commit template
36 > {desc}\n\n
37 > HG: Enter commit message. Lines beginning with 'HG:' are removed.
38 > HG: {extramsg}
39 > HG: --
40 > HG: user: {author}
41 > HG: branch '{branch}'\n{file_adds %
42 > "HG: added {file}\n" }{file_mods %
43 > "HG: changed {file}\n" }{file_dels %
44 > "HG: removed {file}\n" }{if(files, "",
45 > "HG: no files changed\n")}
46 > EOF
30
47
31 $ echo bbbb > file
48 $ echo bbbb > file
32 $ HGEDITOR=cat hg qrefresh -m "Second commit message" -e
49 $ HGEDITOR=cat hg qrefresh -m "Second commit message" -e
50 HG: this is customized commit template
33 Second commit message
51 Second commit message
34
52
35
53
@@ -40,6 +58,12 b' Testing changing message with -m'
40 HG: branch 'default'
58 HG: branch 'default'
41 HG: added file
59 HG: added file
42
60
61 $ cat >> .hg/hgrc <<EOF
62 > # disable customizing for subsequent tests
63 > [committemplate]
64 > changeset =
65 > EOF
66
43 Should display 'Second commit message'
67 Should display 'Second commit message'
44
68
45 $ hg log -l1 --template "{desc}\n"
69 $ hg log -l1 --template "{desc}\n"
General Comments 0
You need to be logged in to leave comments. Login now