##// END OF EJS Templates
amend: add a flag `-n/--note` to store note with amend...
Pulkit Goyal -
r34796:530b7361 default
parent child Browse files
Show More
@@ -1,51 +1,52 b''
1 # amend.py - provide the amend command
1 # amend.py - provide the amend command
2 #
2 #
3 # Copyright 2017 Facebook, Inc.
3 # Copyright 2017 Facebook, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 """provide the amend command (EXPERIMENTAL)
7 """provide the amend command (EXPERIMENTAL)
8
8
9 This extension provides an ``amend`` command that is similar to
9 This extension provides an ``amend`` command that is similar to
10 ``commit --amend`` but does not prompt an editor.
10 ``commit --amend`` but does not prompt an editor.
11 """
11 """
12
12
13 from __future__ import absolute_import
13 from __future__ import absolute_import
14
14
15 from mercurial.i18n import _
15 from mercurial.i18n import _
16 from mercurial import (
16 from mercurial import (
17 cmdutil,
17 cmdutil,
18 commands,
18 commands,
19 registrar,
19 registrar,
20 )
20 )
21
21
22 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
22 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
23 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
23 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
24 # be specifying the version(s) of Mercurial they are tested with, or
24 # be specifying the version(s) of Mercurial they are tested with, or
25 # leave the attribute unspecified.
25 # leave the attribute unspecified.
26 testedwith = 'ships-with-hg-core'
26 testedwith = 'ships-with-hg-core'
27
27
28 cmdtable = {}
28 cmdtable = {}
29 command = registrar.command(cmdtable)
29 command = registrar.command(cmdtable)
30
30
31 @command('amend',
31 @command('amend',
32 [('A', 'addremove', None,
32 [('A', 'addremove', None,
33 _('mark new/missing files as added/removed before committing')),
33 _('mark new/missing files as added/removed before committing')),
34 ('e', 'edit', None, _('invoke editor on commit messages')),
34 ('e', 'edit', None, _('invoke editor on commit messages')),
35 ('i', 'interactive', None, _('use interactive mode')),
35 ('i', 'interactive', None, _('use interactive mode')),
36 ('n', 'note', '', _('store a note on the amend')),
36 ] + cmdutil.walkopts + cmdutil.commitopts + cmdutil.commitopts2,
37 ] + cmdutil.walkopts + cmdutil.commitopts + cmdutil.commitopts2,
37 _('[OPTION]... [FILE]...'),
38 _('[OPTION]... [FILE]...'),
38 inferrepo=True)
39 inferrepo=True)
39 def amend(ui, repo, *pats, **opts):
40 def amend(ui, repo, *pats, **opts):
40 """amend the working copy parent with all or specified outstanding changes
41 """amend the working copy parent with all or specified outstanding changes
41
42
42 Similar to :hg:`commit --amend`, but reuse the commit message without
43 Similar to :hg:`commit --amend`, but reuse the commit message without
43 invoking editor, unless ``--edit`` was set.
44 invoking editor, unless ``--edit`` was set.
44
45
45 See :hg:`help commit` for more details.
46 See :hg:`help commit` for more details.
46 """
47 """
47 with repo.wlock(), repo.lock():
48 with repo.wlock(), repo.lock():
48 if not opts.get('logfile'):
49 if not opts.get('logfile'):
49 opts['message'] = opts.get('message') or repo['.'].description()
50 opts['message'] = opts.get('message') or repo['.'].description()
50 opts['amend'] = True
51 opts['amend'] = True
51 return commands._docommit(ui, repo, *pats, **opts)
52 return commands._docommit(ui, repo, *pats, **opts)
@@ -1,225 +1,233 b''
1 #testcases obsstore-off obsstore-on
1 #testcases obsstore-off obsstore-on
2
2
3 $ cat << EOF >> $HGRCPATH
3 $ cat << EOF >> $HGRCPATH
4 > [extensions]
4 > [extensions]
5 > amend=
5 > amend=
6 > debugdrawdag=$TESTDIR/drawdag.py
6 > debugdrawdag=$TESTDIR/drawdag.py
7 > [diff]
7 > [diff]
8 > git=1
8 > git=1
9 > EOF
9 > EOF
10
10
11 #if obsstore-on
11 #if obsstore-on
12 $ cat << EOF >> $HGRCPATH
12 $ cat << EOF >> $HGRCPATH
13 > [experimental]
13 > [experimental]
14 > stabilization=createmarkers
14 > stabilization=createmarkers
15 > EOF
15 > EOF
16 #endif
16 #endif
17
17
18 Basic amend
18 Basic amend
19
19
20 $ hg init repo1
20 $ hg init repo1
21 $ cd repo1
21 $ cd repo1
22 $ hg debugdrawdag <<'EOS'
22 $ hg debugdrawdag <<'EOS'
23 > B
23 > B
24 > |
24 > |
25 > A
25 > A
26 > EOS
26 > EOS
27
27
28 $ hg update B -q
28 $ hg update B -q
29 $ echo 2 >> B
29 $ echo 2 >> B
30
30
31 $ hg amend
31 $ hg amend
32 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/112478962961-7e959a55-amend.hg (glob) (obsstore-off !)
32 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/112478962961-7e959a55-amend.hg (glob) (obsstore-off !)
33 #if obsstore-off
33 #if obsstore-off
34 $ hg log -p -G --hidden -T '{rev} {node|short} {desc}\n'
34 $ hg log -p -G --hidden -T '{rev} {node|short} {desc}\n'
35 @ 1 be169c7e8dbe B
35 @ 1 be169c7e8dbe B
36 | diff --git a/B b/B
36 | diff --git a/B b/B
37 | new file mode 100644
37 | new file mode 100644
38 | --- /dev/null
38 | --- /dev/null
39 | +++ b/B
39 | +++ b/B
40 | @@ -0,0 +1,1 @@
40 | @@ -0,0 +1,1 @@
41 | +B2
41 | +B2
42 |
42 |
43 o 0 426bada5c675 A
43 o 0 426bada5c675 A
44 diff --git a/A b/A
44 diff --git a/A b/A
45 new file mode 100644
45 new file mode 100644
46 --- /dev/null
46 --- /dev/null
47 +++ b/A
47 +++ b/A
48 @@ -0,0 +1,1 @@
48 @@ -0,0 +1,1 @@
49 +A
49 +A
50 \ No newline at end of file
50 \ No newline at end of file
51
51
52 #else
52 #else
53 $ hg log -p -G --hidden -T '{rev} {node|short} {desc}\n'
53 $ hg log -p -G --hidden -T '{rev} {node|short} {desc}\n'
54 @ 2 be169c7e8dbe B
54 @ 2 be169c7e8dbe B
55 | diff --git a/B b/B
55 | diff --git a/B b/B
56 | new file mode 100644
56 | new file mode 100644
57 | --- /dev/null
57 | --- /dev/null
58 | +++ b/B
58 | +++ b/B
59 | @@ -0,0 +1,1 @@
59 | @@ -0,0 +1,1 @@
60 | +B2
60 | +B2
61 |
61 |
62 | x 1 112478962961 B
62 | x 1 112478962961 B
63 |/ diff --git a/B b/B
63 |/ diff --git a/B b/B
64 | new file mode 100644
64 | new file mode 100644
65 | --- /dev/null
65 | --- /dev/null
66 | +++ b/B
66 | +++ b/B
67 | @@ -0,0 +1,1 @@
67 | @@ -0,0 +1,1 @@
68 | +B
68 | +B
69 | \ No newline at end of file
69 | \ No newline at end of file
70 |
70 |
71 o 0 426bada5c675 A
71 o 0 426bada5c675 A
72 diff --git a/A b/A
72 diff --git a/A b/A
73 new file mode 100644
73 new file mode 100644
74 --- /dev/null
74 --- /dev/null
75 +++ b/A
75 +++ b/A
76 @@ -0,0 +1,1 @@
76 @@ -0,0 +1,1 @@
77 +A
77 +A
78 \ No newline at end of file
78 \ No newline at end of file
79
79
80 #endif
80 #endif
81
81
82 Nothing changed
82 Nothing changed
83
83
84 $ hg amend
84 $ hg amend
85 nothing changed
85 nothing changed
86 [1]
86 [1]
87
87
88 $ hg amend -d "0 0"
88 $ hg amend -d "0 0"
89 nothing changed
89 nothing changed
90 [1]
90 [1]
91
91
92 $ hg amend -d "Thu Jan 01 00:00:00 1970 UTC"
92 $ hg amend -d "Thu Jan 01 00:00:00 1970 UTC"
93 nothing changed
93 nothing changed
94 [1]
94 [1]
95
95
96 Matcher and metadata options
96 Matcher and metadata options
97
97
98 $ echo 3 > C
98 $ echo 3 > C
99 $ echo 4 > D
99 $ echo 4 > D
100 $ hg add C D
100 $ hg add C D
101 $ hg amend -m NEWMESSAGE -I C
101 $ hg amend -m NEWMESSAGE -I C
102 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/be169c7e8dbe-7684ddc5-amend.hg (glob) (obsstore-off !)
102 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/be169c7e8dbe-7684ddc5-amend.hg (glob) (obsstore-off !)
103 $ hg log -r . -T '{node|short} {desc} {files}\n'
103 $ hg log -r . -T '{node|short} {desc} {files}\n'
104 c7ba14d9075b NEWMESSAGE B C
104 c7ba14d9075b NEWMESSAGE B C
105 $ echo 5 > E
105 $ echo 5 > E
106 $ rm C
106 $ rm C
107 $ hg amend -d '2000 1000' -u 'Foo <foo@example.com>' -A C D
107 $ hg amend -d '2000 1000' -u 'Foo <foo@example.com>' -A C D
108 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/c7ba14d9075b-b3e76daa-amend.hg (glob) (obsstore-off !)
108 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/c7ba14d9075b-b3e76daa-amend.hg (glob) (obsstore-off !)
109 $ hg log -r . -T '{node|short} {desc} {files} {author} {date}\n'
109 $ hg log -r . -T '{node|short} {desc} {files} {author} {date}\n'
110 14f6c4bcc865 NEWMESSAGE B D Foo <foo@example.com> 2000.01000
110 14f6c4bcc865 NEWMESSAGE B D Foo <foo@example.com> 2000.01000
111
111
112 Amend with editor
112 Amend with editor
113
113
114 $ cat > $TESTTMP/prefix.sh <<'EOF'
114 $ cat > $TESTTMP/prefix.sh <<'EOF'
115 > printf 'EDITED: ' > $TESTTMP/msg
115 > printf 'EDITED: ' > $TESTTMP/msg
116 > cat "$1" >> $TESTTMP/msg
116 > cat "$1" >> $TESTTMP/msg
117 > mv $TESTTMP/msg "$1"
117 > mv $TESTTMP/msg "$1"
118 > EOF
118 > EOF
119 $ chmod +x $TESTTMP/prefix.sh
119 $ chmod +x $TESTTMP/prefix.sh
120
120
121 $ HGEDITOR="sh $TESTTMP/prefix.sh" hg amend --edit
121 $ HGEDITOR="sh $TESTTMP/prefix.sh" hg amend --edit
122 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/14f6c4bcc865-6591f15d-amend.hg (glob) (obsstore-off !)
122 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/14f6c4bcc865-6591f15d-amend.hg (glob) (obsstore-off !)
123 $ hg log -r . -T '{node|short} {desc}\n'
123 $ hg log -r . -T '{node|short} {desc}\n'
124 298f085230c3 EDITED: NEWMESSAGE
124 298f085230c3 EDITED: NEWMESSAGE
125 $ HGEDITOR="sh $TESTTMP/prefix.sh" hg amend -e -m MSG
125 $ HGEDITOR="sh $TESTTMP/prefix.sh" hg amend -e -m MSG
126 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/298f085230c3-d81a6ad3-amend.hg (glob) (obsstore-off !)
126 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/298f085230c3-d81a6ad3-amend.hg (glob) (obsstore-off !)
127 $ hg log -r . -T '{node|short} {desc}\n'
127 $ hg log -r . -T '{node|short} {desc}\n'
128 974f07f28537 EDITED: MSG
128 974f07f28537 EDITED: MSG
129
129
130 $ echo FOO > $TESTTMP/msg
130 $ echo FOO > $TESTTMP/msg
131 $ hg amend -l $TESTTMP/msg -m BAR
131 $ hg amend -l $TESTTMP/msg -m BAR
132 abort: options --message and --logfile are mutually exclusive
132 abort: options --message and --logfile are mutually exclusive
133 [255]
133 [255]
134 $ hg amend -l $TESTTMP/msg
134 $ hg amend -l $TESTTMP/msg
135 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/974f07f28537-edb6470a-amend.hg (glob) (obsstore-off !)
135 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/974f07f28537-edb6470a-amend.hg (glob) (obsstore-off !)
136 $ hg log -r . -T '{node|short} {desc}\n'
136 $ hg log -r . -T '{node|short} {desc}\n'
137 507be9bdac71 FOO
137 507be9bdac71 FOO
138
138
139 Interactive mode
139 Interactive mode
140
140
141 $ touch F G
141 $ touch F G
142 $ hg add F G
142 $ hg add F G
143 $ cat <<EOS | hg amend -i --config ui.interactive=1
143 $ cat <<EOS | hg amend -i --config ui.interactive=1
144 > y
144 > y
145 > n
145 > n
146 > EOS
146 > EOS
147 diff --git a/F b/F
147 diff --git a/F b/F
148 new file mode 100644
148 new file mode 100644
149 examine changes to 'F'? [Ynesfdaq?] y
149 examine changes to 'F'? [Ynesfdaq?] y
150
150
151 diff --git a/G b/G
151 diff --git a/G b/G
152 new file mode 100644
152 new file mode 100644
153 examine changes to 'G'? [Ynesfdaq?] n
153 examine changes to 'G'? [Ynesfdaq?] n
154
154
155 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/507be9bdac71-c8077452-amend.hg (glob) (obsstore-off !)
155 saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/507be9bdac71-c8077452-amend.hg (glob) (obsstore-off !)
156 $ hg log -r . -T '{files}\n'
156 $ hg log -r . -T '{files}\n'
157 B D F
157 B D F
158
158
159 Amend in the middle of a stack
159 Amend in the middle of a stack
160
160
161 $ hg init $TESTTMP/repo2
161 $ hg init $TESTTMP/repo2
162 $ cd $TESTTMP/repo2
162 $ cd $TESTTMP/repo2
163 $ hg debugdrawdag <<'EOS'
163 $ hg debugdrawdag <<'EOS'
164 > C
164 > C
165 > |
165 > |
166 > B
166 > B
167 > |
167 > |
168 > A
168 > A
169 > EOS
169 > EOS
170
170
171 $ hg update -q B
171 $ hg update -q B
172 $ echo 2 >> B
172 $ echo 2 >> B
173 $ hg amend
173 $ hg amend
174 abort: cannot amend changeset with children
174 abort: cannot amend changeset with children
175 [255]
175 [255]
176
176
177 #if obsstore-on
177 #if obsstore-on
178
178
179 With allowunstable, amend could work in the middle of a stack
179 With allowunstable, amend could work in the middle of a stack
180
180
181 $ cat >> $HGRCPATH <<EOF
181 $ cat >> $HGRCPATH <<EOF
182 > [experimental]
182 > [experimental]
183 > stabilization=createmarkers, allowunstable
183 > stabilization=createmarkers, allowunstable
184 > EOF
184 > EOF
185
185
186 $ hg amend
186 $ hg amend
187 $ hg log -T '{rev} {node|short} {desc}\n' -G
187 $ hg log -T '{rev} {node|short} {desc}\n' -G
188 @ 3 be169c7e8dbe B
188 @ 3 be169c7e8dbe B
189 |
189 |
190 | o 2 26805aba1e60 C
190 | o 2 26805aba1e60 C
191 | |
191 | |
192 | x 1 112478962961 B
192 | x 1 112478962961 B
193 |/
193 |/
194 o 0 426bada5c675 A
194 o 0 426bada5c675 A
195
195
196 Checking the note stored in the obsmarker
197
198 $ echo foo > bar
199 $ hg add bar
200 $ hg amend --note "adding bar"
201 $ hg debugobsolete -r .
202 112478962961147124edd43549aedd1a335e44bf be169c7e8dbe21cd10b3d79691cbe7f241e3c21c 0 (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'amend', 'user': 'test'}
203 be169c7e8dbe21cd10b3d79691cbe7f241e3c21c 16084da537dd8f84cfdb3055c633772269d62e1b 0 (Thu Jan 01 00:00:00 1970 +0000) {'note': 'adding bar', 'operation': 'amend', 'user': 'test'}
196 #endif
204 #endif
197
205
198 Cannot amend public changeset
206 Cannot amend public changeset
199
207
200 $ hg phase -r A --public
208 $ hg phase -r A --public
201 $ hg update -C -q A
209 $ hg update -C -q A
202 $ hg amend -m AMEND
210 $ hg amend -m AMEND
203 abort: cannot amend public changesets
211 abort: cannot amend public changesets
204 [255]
212 [255]
205
213
206 Amend a merge changeset
214 Amend a merge changeset
207
215
208 $ hg init $TESTTMP/repo3
216 $ hg init $TESTTMP/repo3
209 $ cd $TESTTMP/repo3
217 $ cd $TESTTMP/repo3
210 $ hg debugdrawdag <<'EOS'
218 $ hg debugdrawdag <<'EOS'
211 > C
219 > C
212 > /|
220 > /|
213 > A B
221 > A B
214 > EOS
222 > EOS
215 $ hg update -q C
223 $ hg update -q C
216 $ hg amend -m FOO
224 $ hg amend -m FOO
217 saved backup bundle to $TESTTMP/repo3/.hg/strip-backup/a35c07e8a2a4-15ff4612-amend.hg (glob) (obsstore-off !)
225 saved backup bundle to $TESTTMP/repo3/.hg/strip-backup/a35c07e8a2a4-15ff4612-amend.hg (glob) (obsstore-off !)
218 $ rm .hg/localtags
226 $ rm .hg/localtags
219 $ hg log -G -T '{desc}\n'
227 $ hg log -G -T '{desc}\n'
220 @ FOO
228 @ FOO
221 |\
229 |\
222 | o B
230 | o B
223 |
231 |
224 o A
232 o A
225
233
General Comments 0
You need to be logged in to leave comments. Login now