##// END OF EJS Templates
qrefresh: use "editor" argument of "commit()" instead of explicit "ui.edit()"...
FUJIWARA Katsunori -
r21236:49148d78 default
parent child Browse files
Show More
@@ -1484,6 +1484,7 b' class queue(object):'
1484 self.ui.write(_("no patches applied\n"))
1484 self.ui.write(_("no patches applied\n"))
1485 return 1
1485 return 1
1486 msg = opts.get('msg', '').rstrip()
1486 msg = opts.get('msg', '').rstrip()
1487 editor = opts.get('editor')
1487 newuser = opts.get('user')
1488 newuser = opts.get('user')
1488 newdate = opts.get('date')
1489 newdate = opts.get('date')
1489 if newdate:
1490 if newdate:
@@ -1652,9 +1653,20 b' class queue(object):'
1652 try:
1653 try:
1653 # might be nice to attempt to roll back strip after this
1654 # might be nice to attempt to roll back strip after this
1654
1655
1655 if not msg:
1656 defaultmsg = "[mq]: %s" % patchfn
1657 if editor:
1658 origeditor = editor
1659 def desceditor(repo, ctx, subs):
1660 desc = origeditor(repo, ctx, subs)
1661 if desc.rstrip():
1662 ph.setmessage(desc)
1663 return desc
1664 return defaultmsg
1665 message = msg or "\n".join(ph.message)
1666 editor = desceditor
1667 elif not msg:
1656 if not ph.message:
1668 if not ph.message:
1657 message = "[mq]: %s\n" % patchfn
1669 message = defaultmsg
1658 else:
1670 else:
1659 message = "\n".join(ph.message)
1671 message = "\n".join(ph.message)
1660 else:
1672 else:
@@ -1664,7 +1676,7 b' class queue(object):'
1664 # Ensure we create a new changeset in the same phase than
1676 # Ensure we create a new changeset in the same phase than
1665 # the old one.
1677 # the old one.
1666 n = newcommit(repo, oldphase, message, user, ph.date,
1678 n = newcommit(repo, oldphase, message, user, ph.date,
1667 match=match, force=True)
1679 match=match, force=True, editor=editor)
1668 # only write patch after a successful commit
1680 # only write patch after a successful commit
1669 c = [list(x) for x in refreshchanges]
1681 c = [list(x) for x in refreshchanges]
1670 if inclsubs:
1682 if inclsubs:
@@ -2478,20 +2490,16 b' def refresh(ui, repo, *pats, **opts):'
2478 q = repo.mq
2490 q = repo.mq
2479 message = cmdutil.logmessage(ui, opts)
2491 message = cmdutil.logmessage(ui, opts)
2480 if opts.get('edit'):
2492 if opts.get('edit'):
2481 if not q.applied:
2482 ui.write(_("no patches applied\n"))
2483 return 1
2484 if message:
2493 if message:
2485 raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
2494 raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
2486 patch = q.applied[-1].name
2495 def editor(repo, ctx, subs):
2487 ph = patchheader(q.join(patch), q.plainmode)
2496 return ui.edit(ctx.description() + "\n", ctx.user())
2488 message = ui.edit('\n'.join(ph.message), ph.user or ui.username())
2497 else:
2489 # We don't want to lose the patch message if qrefresh fails (issue2062)
2498 editor = False
2490 repo.savecommitmessage(message)
2491 setupheaderopts(ui, opts)
2499 setupheaderopts(ui, opts)
2492 wlock = repo.wlock()
2500 wlock = repo.wlock()
2493 try:
2501 try:
2494 ret = q.refresh(repo, pats, msg=message, **opts)
2502 ret = q.refresh(repo, pats, msg=message, editor=editor, **opts)
2495 q.savedirty()
2503 q.savedirty()
2496 return ret
2504 return ret
2497 finally:
2505 finally:
@@ -2582,13 +2590,15 b' def fold(ui, repo, *files, **opts):'
2582 message = '\n'.join(message)
2590 message = '\n'.join(message)
2583
2591
2584 if opts.get('edit'):
2592 if opts.get('edit'):
2585 message = ui.edit(message, user or ui.username())
2593 def editor(repo, ctx, subs):
2586 repo.savecommitmessage(message)
2594 return ui.edit(ctx.description() + "\n", ctx.user())
2595 else:
2596 editor = False
2587
2597
2588 diffopts = q.patchopts(q.diffopts(), *patches)
2598 diffopts = q.patchopts(q.diffopts(), *patches)
2589 wlock = repo.wlock()
2599 wlock = repo.wlock()
2590 try:
2600 try:
2591 q.refresh(repo, msg=message, git=diffopts.git)
2601 q.refresh(repo, msg=message, git=diffopts.git, editor=editor)
2592 q.delete(repo, patches, opts)
2602 q.delete(repo, patches, opts)
2593 q.savedirty()
2603 q.savedirty()
2594 finally:
2604 finally:
@@ -153,8 +153,9 b' Test saving last-message.txt:'
153 > repo.__class__ = commitfailure
153 > repo.__class__ = commitfailure
154 > EOF
154 > EOF
155
155
156 $ cat > .hg/hgrc <<EOF
156 $ cat >> .hg/hgrc <<EOF
157 > [extensions]
157 > [extensions]
158 > # this failure occurs before editor invocation
158 > commitfailure = $TESTTMP/commitfailure.py
159 > commitfailure = $TESTTMP/commitfailure.py
159 > EOF
160 > EOF
160
161
@@ -165,15 +166,65 b' Test saving last-message.txt:'
165 > (echo; echo "test saving last-message.txt") >> \$1
166 > (echo; echo "test saving last-message.txt") >> \$1
166 > EOF
167 > EOF
167
168
169 $ hg qapplied
170 p1
171 git
172 $ hg tip --template "{files}\n"
173 aa
174
175 (test that editor is not invoked before transaction starting)
176
168 $ rm -f .hg/last-message.txt
177 $ rm -f .hg/last-message.txt
169 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qfold -e p3
178 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qfold -e p3
170 ==== before editing
171 original message====
172 refresh interrupted while patch was popped! (revert --all, qpush to recover)
179 refresh interrupted while patch was popped! (revert --all, qpush to recover)
173 abort: emulating unexpected abort
180 abort: emulating unexpected abort
174 [255]
181 [255]
175 $ cat .hg/last-message.txt
182 $ cat .hg/last-message.txt
183 cat: .hg/last-message.txt: No such file or directory
184 [1]
185
186 (reset applied patches and directory status)
187
188 $ cat >> .hg/hgrc <<EOF
189 > [extensions]
190 > # this failure occurs after editor invocation
191 > commitfailure = !
192 > EOF
193
194 $ hg qapplied
195 p1
196 $ hg status -A aa
197 ? aa
198 $ rm aa
199 $ hg status -m
200 M a
201 $ hg revert --no-backup -q a
202 $ hg qpush -q git
203 now at: git
204
205 (test that editor is invoked and commit message is saved into
206 "last-message.txt")
207
208 $ cat >> .hg/hgrc <<EOF
209 > [hooks]
210 > # this failure occurs after editor invocation
211 > pretxncommit.unexpectedabort = false
212 > EOF
213
214 $ rm -f .hg/last-message.txt
215 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qfold -e p3
216 ==== before editing
176 original message
217 original message
218 ====
219 transaction abort!
220 rollback completed
221 note: commit message saved in .hg/last-message.txt
222 refresh interrupted while patch was popped! (revert --all, qpush to recover)
223 abort: pretxncommit.unexpectedabort hook exited with status 1
224 [255]
225 $ cat .hg/last-message.txt
226 original message
227
177 test saving last-message.txt
228 test saving last-message.txt
178
229
179 $ cd ..
230 $ cd ..
@@ -59,3 +59,86 b" Should display 'Fifth commit message\\\\\\n"
59 $ hg log -l1 --template "{desc}\n"
59 $ hg log -l1 --template "{desc}\n"
60 Fifth commit message
60 Fifth commit message
61 This is the 5th log message
61 This is the 5th log message
62
63 Test saving last-message.txt:
64
65 $ cat > $TESTTMP/editor.sh << EOF
66 > echo "==== before editing"
67 > cat \$1
68 > echo "===="
69 > (echo; echo "test saving last-message.txt") >> \$1
70 > EOF
71
72 $ cat > $TESTTMP/commitfailure.py <<EOF
73 > from mercurial import util
74 > def reposetup(ui, repo):
75 > class commitfailure(repo.__class__):
76 > def commit(self, *args, **kwargs):
77 > raise util.Abort('emulating unexpected abort')
78 > repo.__class__ = commitfailure
79 > EOF
80
81 $ cat >> .hg/hgrc <<EOF
82 > [extensions]
83 > # this failure occurs before editor invocation
84 > commitfailure = $TESTTMP/commitfailure.py
85 > EOF
86
87 $ hg qapplied
88 first-patch
89 second-patch
90 $ hg tip --template "{files}\n"
91 file2
92
93 (test that editor is not invoked before transaction starting)
94
95 $ rm -f .hg/last-message.txt
96 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qrefresh -e
97 refresh interrupted while patch was popped! (revert --all, qpush to recover)
98 abort: emulating unexpected abort
99 [255]
100 $ cat .hg/last-message.txt
101 cat: .hg/last-message.txt: No such file or directory
102 [1]
103
104 (reset applied patches and directory status)
105
106 $ cat >> .hg/hgrc <<EOF
107 > [extensions]
108 > commitfailure = !
109 > EOF
110
111 $ hg qapplied
112 first-patch
113 $ hg status -A file2
114 ? file2
115 $ rm file2
116 $ hg qpush -q second-patch
117 now at: second-patch
118
119 (test that editor is invoked and commit message is saved into
120 "last-message.txt")
121
122 $ cat >> .hg/hgrc <<EOF
123 > [hooks]
124 > # this failure occurs after editor invocation
125 > pretxncommit.unexpectedabort = false
126 > EOF
127
128 $ rm -f .hg/last-message.txt
129 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qrefresh -e
130 ==== before editing
131 Fifth commit message
132 This is the 5th log message
133 ====
134 transaction abort!
135 rollback completed
136 note: commit message saved in .hg/last-message.txt
137 refresh interrupted while patch was popped! (revert --all, qpush to recover)
138 abort: pretxncommit.unexpectedabort hook exited with status 1
139 [255]
140 $ cat .hg/last-message.txt
141 Fifth commit message
142 This is the 5th log message
143
144 test saving last-message.txt
General Comments 0
You need to be logged in to leave comments. Login now