##// END OF EJS Templates
qnew: use "editor" argument of "commit()" instead of explicit "ui.edit()"...
FUJIWARA Katsunori -
r21234:b9a16ed5 default
parent child Browse files
Show More
@@ -1026,6 +1026,7 b' class queue(object):'
1026 msg: a string or a no-argument function returning a string
1026 msg: a string or a no-argument function returning a string
1027 """
1027 """
1028 msg = opts.get('msg')
1028 msg = opts.get('msg')
1029 editor = opts.get('editor')
1029 user = opts.get('user')
1030 user = opts.get('user')
1030 date = opts.get('date')
1031 date = opts.get('date')
1031 if date:
1032 if date:
@@ -1078,12 +1079,23 b' class queue(object):'
1078 p.write("# User " + user + "\n")
1079 p.write("# User " + user + "\n")
1079 if date:
1080 if date:
1080 p.write("# Date %s %s\n\n" % date)
1081 p.write("# Date %s %s\n\n" % date)
1081 if util.safehasattr(msg, '__call__'):
1082
1082 msg = msg()
1083 defaultmsg = "[mq]: %s" % patchfn
1083 repo.savecommitmessage(msg)
1084 if editor:
1084 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
1085 origeditor = editor
1086 def desceditor(repo, ctx, subs):
1087 desc = origeditor(repo, ctx, subs)
1088 if desc.rstrip():
1089 return desc
1090 else:
1091 return defaultmsg
1092 commitmsg = msg
1093 editor = desceditor
1094 else:
1095 commitmsg = msg or defaultmsg
1096
1085 n = newcommit(repo, None, commitmsg, user, date, match=match,
1097 n = newcommit(repo, None, commitmsg, user, date, match=match,
1086 force=True)
1098 force=True, editor=editor)
1087 if n is None:
1099 if n is None:
1088 raise util.Abort(_("repo commit failed"))
1100 raise util.Abort(_("repo commit failed"))
1089 try:
1101 try:
@@ -1092,8 +1104,9 b' class queue(object):'
1092 self.parseseries()
1104 self.parseseries()
1093 self.seriesdirty = True
1105 self.seriesdirty = True
1094 self.applieddirty = True
1106 self.applieddirty = True
1095 if msg:
1107 nctx = repo[n]
1096 msg = msg + "\n\n"
1108 if nctx.description() != defaultmsg.rstrip():
1109 msg = nctx.description() + "\n\n"
1097 p.write(msg)
1110 p.write(msg)
1098 if commitfiles:
1111 if commitfiles:
1099 parent = self.qparents(repo, n)
1112 parent = self.qparents(repo, n)
@@ -2417,14 +2430,12 b' def new(ui, repo, patch, *args, **opts):'
2417 Returns 0 on successful creation of a new patch.
2430 Returns 0 on successful creation of a new patch.
2418 """
2431 """
2419 msg = cmdutil.logmessage(ui, opts)
2432 msg = cmdutil.logmessage(ui, opts)
2420 def getmsg():
2421 return ui.edit(msg, opts.get('user') or ui.username())
2422 q = repo.mq
2433 q = repo.mq
2423 opts['msg'] = msg
2434 opts['msg'] = msg
2424 if opts.get('edit'):
2435 if opts.get('edit'):
2425 opts['msg'] = getmsg
2436 def editor(repo, ctx, subs):
2426 else:
2437 return ui.edit(ctx.description() + "\n", ctx.user())
2427 opts['msg'] = msg
2438 opts['editor'] = editor
2428 setupheaderopts(ui, opts)
2439 setupheaderopts(ui, opts)
2429 q.new(repo, patch, *args, **opts)
2440 q.new(repo, patch, *args, **opts)
2430 q.savedirty()
2441 q.savedirty()
@@ -247,8 +247,9 b' Test saving last-message.txt'
247 > raise util.Abort('emulating unexpected abort')
247 > raise util.Abort('emulating unexpected abort')
248 > repo.__class__ = commitfailure
248 > repo.__class__ = commitfailure
249 > EOF
249 > EOF
250 $ cat > .hg/hgrc <<EOF
250 $ cat >> .hg/hgrc <<EOF
251 > [extensions]
251 > [extensions]
252 > # this failure occurs before editor invocation
252 > commitfailure = $TESTTMP/commitfailure.py
253 > commitfailure = $TESTTMP/commitfailure.py
253 > EOF
254 > EOF
254
255
@@ -259,13 +260,62 b' Test saving last-message.txt'
259 > echo "test saving last-message.txt" >> \$1
260 > echo "test saving last-message.txt" >> \$1
260 > EOF
261 > EOF
261
262
263 (test that editor is not invoked before transaction starting)
264
265 $ rm -f .hg/last-message.txt
266 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qnew -e patch
267 abort: emulating unexpected abort
268 [255]
269 $ cat .hg/last-message.txt
270 cat: .hg/last-message.txt: No such file or directory
271 [1]
272
273 (test that editor is invoked and commit message is saved into
274 "last-message.txt")
275
276 $ cat >> .hg/hgrc <<EOF
277 > [extensions]
278 > commitfailure = !
279 > [hooks]
280 > # this failure occurs after editor invocation
281 > pretxncommit.unexpectedabort = false
282 > EOF
283
262 $ rm -f .hg/last-message.txt
284 $ rm -f .hg/last-message.txt
263 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qnew -e patch
285 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qnew -e patch
264 ==== before editing
286 ==== before editing
287
265 ====
288 ====
266 abort: emulating unexpected abort
289 transaction abort!
290 rollback completed
291 note: commit message saved in .hg/last-message.txt
292 abort: pretxncommit.unexpectedabort hook exited with status 1
267 [255]
293 [255]
268 $ cat .hg/last-message.txt
294 $ cat .hg/last-message.txt
295
269 test saving last-message.txt
296 test saving last-message.txt
270
297
298 $ cat >> .hg/hgrc <<EOF
299 > [hooks]
300 > pretxncommit.unexpectedabort =
301 > EOF
302
303 Test handling default message with the patch filename with tail whitespaces
304
305 $ cat > $TESTTMP/editor.sh << EOF
306 > echo "==== before editing"
307 > cat \$1
308 > echo "===="
309 > echo "[mq]: patch " > \$1
310 > EOF
311
312 $ rm -f .hg/last-message.txt
313 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qnew -e "patch "
314 ==== before editing
315
316 ====
317 $ cat ".hg/patches/patch "
318 # HG changeset patch
319 # Parent 0000000000000000000000000000000000000000
320
271 $ cd ..
321 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now