##// END OF EJS Templates
fix: add some new test cases...
Danny Hooper -
r42890:4b04244f default
parent child Browse files
Show More
@@ -1,1289 +1,1316 b''
1 A script that implements uppercasing of specific lines in a file. This
1 A script that implements uppercasing of specific lines in a file. This
2 approximates the behavior of code formatters well enough for our tests.
2 approximates the behavior of code formatters well enough for our tests.
3
3
4 $ UPPERCASEPY="$TESTTMP/uppercase.py"
4 $ UPPERCASEPY="$TESTTMP/uppercase.py"
5 $ cat > $UPPERCASEPY <<EOF
5 $ cat > $UPPERCASEPY <<EOF
6 > import sys
6 > import sys
7 > from mercurial.utils.procutil import setbinary
7 > from mercurial.utils.procutil import setbinary
8 > setbinary(sys.stdin)
8 > setbinary(sys.stdin)
9 > setbinary(sys.stdout)
9 > setbinary(sys.stdout)
10 > lines = set()
10 > lines = set()
11 > for arg in sys.argv[1:]:
11 > for arg in sys.argv[1:]:
12 > if arg == 'all':
12 > if arg == 'all':
13 > sys.stdout.write(sys.stdin.read().upper())
13 > sys.stdout.write(sys.stdin.read().upper())
14 > sys.exit(0)
14 > sys.exit(0)
15 > else:
15 > else:
16 > first, last = arg.split('-')
16 > first, last = arg.split('-')
17 > lines.update(range(int(first), int(last) + 1))
17 > lines.update(range(int(first), int(last) + 1))
18 > for i, line in enumerate(sys.stdin.readlines()):
18 > for i, line in enumerate(sys.stdin.readlines()):
19 > if i + 1 in lines:
19 > if i + 1 in lines:
20 > sys.stdout.write(line.upper())
20 > sys.stdout.write(line.upper())
21 > else:
21 > else:
22 > sys.stdout.write(line)
22 > sys.stdout.write(line)
23 > EOF
23 > EOF
24 $ TESTLINES="foo\nbar\nbaz\nqux\n"
24 $ TESTLINES="foo\nbar\nbaz\nqux\n"
25 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY
25 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY
26 foo
26 foo
27 bar
27 bar
28 baz
28 baz
29 qux
29 qux
30 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY all
30 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY all
31 FOO
31 FOO
32 BAR
32 BAR
33 BAZ
33 BAZ
34 QUX
34 QUX
35 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-1
35 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-1
36 FOO
36 FOO
37 bar
37 bar
38 baz
38 baz
39 qux
39 qux
40 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-2
40 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-2
41 FOO
41 FOO
42 BAR
42 BAR
43 baz
43 baz
44 qux
44 qux
45 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-3
45 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-3
46 foo
46 foo
47 BAR
47 BAR
48 BAZ
48 BAZ
49 qux
49 qux
50 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-2 4-4
50 $ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-2 4-4
51 foo
51 foo
52 BAR
52 BAR
53 baz
53 baz
54 QUX
54 QUX
55
55
56 Set up the config with two simple fixers: one that fixes specific line ranges,
56 Set up the config with two simple fixers: one that fixes specific line ranges,
57 and one that always fixes the whole file. They both "fix" files by converting
57 and one that always fixes the whole file. They both "fix" files by converting
58 letters to uppercase. They use different file extensions, so each test case can
58 letters to uppercase. They use different file extensions, so each test case can
59 choose which behavior to use by naming files.
59 choose which behavior to use by naming files.
60
60
61 $ cat >> $HGRCPATH <<EOF
61 $ cat >> $HGRCPATH <<EOF
62 > [extensions]
62 > [extensions]
63 > fix =
63 > fix =
64 > [experimental]
64 > [experimental]
65 > evolution.createmarkers=True
65 > evolution.createmarkers=True
66 > evolution.allowunstable=True
66 > evolution.allowunstable=True
67 > [fix]
67 > [fix]
68 > uppercase-whole-file:command="$PYTHON" $UPPERCASEPY all
68 > uppercase-whole-file:command="$PYTHON" $UPPERCASEPY all
69 > uppercase-whole-file:pattern=set:**.whole
69 > uppercase-whole-file:pattern=set:**.whole
70 > uppercase-changed-lines:command="$PYTHON" $UPPERCASEPY
70 > uppercase-changed-lines:command="$PYTHON" $UPPERCASEPY
71 > uppercase-changed-lines:linerange={first}-{last}
71 > uppercase-changed-lines:linerange={first}-{last}
72 > uppercase-changed-lines:pattern=set:**.changed
72 > uppercase-changed-lines:pattern=set:**.changed
73 > EOF
73 > EOF
74
74
75 Help text for fix.
75 Help text for fix.
76
76
77 $ hg help fix
77 $ hg help fix
78 hg fix [OPTION]... [FILE]...
78 hg fix [OPTION]... [FILE]...
79
79
80 rewrite file content in changesets or working directory
80 rewrite file content in changesets or working directory
81
81
82 Runs any configured tools to fix the content of files. Only affects files
82 Runs any configured tools to fix the content of files. Only affects files
83 with changes, unless file arguments are provided. Only affects changed
83 with changes, unless file arguments are provided. Only affects changed
84 lines of files, unless the --whole flag is used. Some tools may always
84 lines of files, unless the --whole flag is used. Some tools may always
85 affect the whole file regardless of --whole.
85 affect the whole file regardless of --whole.
86
86
87 If revisions are specified with --rev, those revisions will be checked,
87 If revisions are specified with --rev, those revisions will be checked,
88 and they may be replaced with new revisions that have fixed file content.
88 and they may be replaced with new revisions that have fixed file content.
89 It is desirable to specify all descendants of each specified revision, so
89 It is desirable to specify all descendants of each specified revision, so
90 that the fixes propagate to the descendants. If all descendants are fixed
90 that the fixes propagate to the descendants. If all descendants are fixed
91 at the same time, no merging, rebasing, or evolution will be required.
91 at the same time, no merging, rebasing, or evolution will be required.
92
92
93 If --working-dir is used, files with uncommitted changes in the working
93 If --working-dir is used, files with uncommitted changes in the working
94 copy will be fixed. If the checked-out revision is also fixed, the working
94 copy will be fixed. If the checked-out revision is also fixed, the working
95 directory will update to the replacement revision.
95 directory will update to the replacement revision.
96
96
97 When determining what lines of each file to fix at each revision, the
97 When determining what lines of each file to fix at each revision, the
98 whole set of revisions being fixed is considered, so that fixes to earlier
98 whole set of revisions being fixed is considered, so that fixes to earlier
99 revisions are not forgotten in later ones. The --base flag can be used to
99 revisions are not forgotten in later ones. The --base flag can be used to
100 override this default behavior, though it is not usually desirable to do
100 override this default behavior, though it is not usually desirable to do
101 so.
101 so.
102
102
103 (use 'hg help -e fix' to show help for the fix extension)
103 (use 'hg help -e fix' to show help for the fix extension)
104
104
105 options ([+] can be repeated):
105 options ([+] can be repeated):
106
106
107 --all fix all non-public non-obsolete revisions
107 --all fix all non-public non-obsolete revisions
108 --base REV [+] revisions to diff against (overrides automatic selection,
108 --base REV [+] revisions to diff against (overrides automatic selection,
109 and applies to every revision being fixed)
109 and applies to every revision being fixed)
110 -r --rev REV [+] revisions to fix
110 -r --rev REV [+] revisions to fix
111 -w --working-dir fix the working directory
111 -w --working-dir fix the working directory
112 --whole always fix every line of a file
112 --whole always fix every line of a file
113
113
114 (some details hidden, use --verbose to show complete help)
114 (some details hidden, use --verbose to show complete help)
115
115
116 $ hg help -e fix
116 $ hg help -e fix
117 fix extension - rewrite file content in changesets or working copy
117 fix extension - rewrite file content in changesets or working copy
118 (EXPERIMENTAL)
118 (EXPERIMENTAL)
119
119
120 Provides a command that runs configured tools on the contents of modified
120 Provides a command that runs configured tools on the contents of modified
121 files, writing back any fixes to the working copy or replacing changesets.
121 files, writing back any fixes to the working copy or replacing changesets.
122
122
123 Here is an example configuration that causes 'hg fix' to apply automatic
123 Here is an example configuration that causes 'hg fix' to apply automatic
124 formatting fixes to modified lines in C++ code:
124 formatting fixes to modified lines in C++ code:
125
125
126 [fix]
126 [fix]
127 clang-format:command=clang-format --assume-filename={rootpath}
127 clang-format:command=clang-format --assume-filename={rootpath}
128 clang-format:linerange=--lines={first}:{last}
128 clang-format:linerange=--lines={first}:{last}
129 clang-format:pattern=set:**.cpp or **.hpp
129 clang-format:pattern=set:**.cpp or **.hpp
130
130
131 The :command suboption forms the first part of the shell command that will be
131 The :command suboption forms the first part of the shell command that will be
132 used to fix a file. The content of the file is passed on standard input, and
132 used to fix a file. The content of the file is passed on standard input, and
133 the fixed file content is expected on standard output. Any output on standard
133 the fixed file content is expected on standard output. Any output on standard
134 error will be displayed as a warning. If the exit status is not zero, the file
134 error will be displayed as a warning. If the exit status is not zero, the file
135 will not be affected. A placeholder warning is displayed if there is a non-
135 will not be affected. A placeholder warning is displayed if there is a non-
136 zero exit status but no standard error output. Some values may be substituted
136 zero exit status but no standard error output. Some values may be substituted
137 into the command:
137 into the command:
138
138
139 {rootpath} The path of the file being fixed, relative to the repo root
139 {rootpath} The path of the file being fixed, relative to the repo root
140 {basename} The name of the file being fixed, without the directory path
140 {basename} The name of the file being fixed, without the directory path
141
141
142 If the :linerange suboption is set, the tool will only be run if there are
142 If the :linerange suboption is set, the tool will only be run if there are
143 changed lines in a file. The value of this suboption is appended to the shell
143 changed lines in a file. The value of this suboption is appended to the shell
144 command once for every range of changed lines in the file. Some values may be
144 command once for every range of changed lines in the file. Some values may be
145 substituted into the command:
145 substituted into the command:
146
146
147 {first} The 1-based line number of the first line in the modified range
147 {first} The 1-based line number of the first line in the modified range
148 {last} The 1-based line number of the last line in the modified range
148 {last} The 1-based line number of the last line in the modified range
149
149
150 The :pattern suboption determines which files will be passed through each
150 The :pattern suboption determines which files will be passed through each
151 configured tool. See 'hg help patterns' for possible values. If there are file
151 configured tool. See 'hg help patterns' for possible values. If there are file
152 arguments to 'hg fix', the intersection of these patterns is used.
152 arguments to 'hg fix', the intersection of these patterns is used.
153
153
154 There is also a configurable limit for the maximum size of file that will be
154 There is also a configurable limit for the maximum size of file that will be
155 processed by 'hg fix':
155 processed by 'hg fix':
156
156
157 [fix]
157 [fix]
158 maxfilesize = 2MB
158 maxfilesize = 2MB
159
159
160 Normally, execution of configured tools will continue after a failure
160 Normally, execution of configured tools will continue after a failure
161 (indicated by a non-zero exit status). It can also be configured to abort
161 (indicated by a non-zero exit status). It can also be configured to abort
162 after the first such failure, so that no files will be affected if any tool
162 after the first such failure, so that no files will be affected if any tool
163 fails. This abort will also cause 'hg fix' to exit with a non-zero status:
163 fails. This abort will also cause 'hg fix' to exit with a non-zero status:
164
164
165 [fix]
165 [fix]
166 failure = abort
166 failure = abort
167
167
168 When multiple tools are configured to affect a file, they execute in an order
168 When multiple tools are configured to affect a file, they execute in an order
169 defined by the :priority suboption. The priority suboption has a default value
169 defined by the :priority suboption. The priority suboption has a default value
170 of zero for each tool. Tools are executed in order of descending priority. The
170 of zero for each tool. Tools are executed in order of descending priority. The
171 execution order of tools with equal priority is unspecified. For example, you
171 execution order of tools with equal priority is unspecified. For example, you
172 could use the 'sort' and 'head' utilities to keep only the 10 smallest numbers
172 could use the 'sort' and 'head' utilities to keep only the 10 smallest numbers
173 in a text file by ensuring that 'sort' runs before 'head':
173 in a text file by ensuring that 'sort' runs before 'head':
174
174
175 [fix]
175 [fix]
176 sort:command = sort -n
176 sort:command = sort -n
177 head:command = head -n 10
177 head:command = head -n 10
178 sort:pattern = numbers.txt
178 sort:pattern = numbers.txt
179 head:pattern = numbers.txt
179 head:pattern = numbers.txt
180 sort:priority = 2
180 sort:priority = 2
181 head:priority = 1
181 head:priority = 1
182
182
183 To account for changes made by each tool, the line numbers used for
183 To account for changes made by each tool, the line numbers used for
184 incremental formatting are recomputed before executing the next tool. So, each
184 incremental formatting are recomputed before executing the next tool. So, each
185 tool may see different values for the arguments added by the :linerange
185 tool may see different values for the arguments added by the :linerange
186 suboption.
186 suboption.
187
187
188 Each fixer tool is allowed to return some metadata in addition to the fixed
188 Each fixer tool is allowed to return some metadata in addition to the fixed
189 file content. The metadata must be placed before the file content on stdout,
189 file content. The metadata must be placed before the file content on stdout,
190 separated from the file content by a zero byte. The metadata is parsed as a
190 separated from the file content by a zero byte. The metadata is parsed as a
191 JSON value (so, it should be UTF-8 encoded and contain no zero bytes). A fixer
191 JSON value (so, it should be UTF-8 encoded and contain no zero bytes). A fixer
192 tool is expected to produce this metadata encoding if and only if the
192 tool is expected to produce this metadata encoding if and only if the
193 :metadata suboption is true:
193 :metadata suboption is true:
194
194
195 [fix]
195 [fix]
196 tool:command = tool --prepend-json-metadata
196 tool:command = tool --prepend-json-metadata
197 tool:metadata = true
197 tool:metadata = true
198
198
199 The metadata values are passed to hooks, which can be used to print summaries
199 The metadata values are passed to hooks, which can be used to print summaries
200 or perform other post-fixing work. The supported hooks are:
200 or perform other post-fixing work. The supported hooks are:
201
201
202 "postfixfile"
202 "postfixfile"
203 Run once for each file in each revision where any fixer tools made changes
203 Run once for each file in each revision where any fixer tools made changes
204 to the file content. Provides "$HG_REV" and "$HG_PATH" to identify the file,
204 to the file content. Provides "$HG_REV" and "$HG_PATH" to identify the file,
205 and "$HG_METADATA" with a map of fixer names to metadata values from fixer
205 and "$HG_METADATA" with a map of fixer names to metadata values from fixer
206 tools that affected the file. Fixer tools that didn't affect the file have a
206 tools that affected the file. Fixer tools that didn't affect the file have a
207 valueof None. Only fixer tools that executed are present in the metadata.
207 valueof None. Only fixer tools that executed are present in the metadata.
208
208
209 "postfix"
209 "postfix"
210 Run once after all files and revisions have been handled. Provides
210 Run once after all files and revisions have been handled. Provides
211 "$HG_REPLACEMENTS" with information about what revisions were created and
211 "$HG_REPLACEMENTS" with information about what revisions were created and
212 made obsolete. Provides a boolean "$HG_WDIRWRITTEN" to indicate whether any
212 made obsolete. Provides a boolean "$HG_WDIRWRITTEN" to indicate whether any
213 files in the working copy were updated. Provides a list "$HG_METADATA"
213 files in the working copy were updated. Provides a list "$HG_METADATA"
214 mapping fixer tool names to lists of metadata values returned from
214 mapping fixer tool names to lists of metadata values returned from
215 executions that modified a file. This aggregates the same metadata
215 executions that modified a file. This aggregates the same metadata
216 previously passed to the "postfixfile" hook.
216 previously passed to the "postfixfile" hook.
217
217
218 list of commands:
218 list of commands:
219
219
220 fix rewrite file content in changesets or working directory
220 fix rewrite file content in changesets or working directory
221
221
222 (use 'hg help -v -e fix' to show built-in aliases and global options)
222 (use 'hg help -v -e fix' to show built-in aliases and global options)
223
223
224 There is no default behavior in the absence of --rev and --working-dir.
224 There is no default behavior in the absence of --rev and --working-dir.
225
225
226 $ hg init badusage
226 $ hg init badusage
227 $ cd badusage
227 $ cd badusage
228
228
229 $ hg fix
229 $ hg fix
230 abort: no changesets specified
230 abort: no changesets specified
231 (use --rev or --working-dir)
231 (use --rev or --working-dir)
232 [255]
232 [255]
233 $ hg fix --whole
233 $ hg fix --whole
234 abort: no changesets specified
234 abort: no changesets specified
235 (use --rev or --working-dir)
235 (use --rev or --working-dir)
236 [255]
236 [255]
237 $ hg fix --base 0
237 $ hg fix --base 0
238 abort: no changesets specified
238 abort: no changesets specified
239 (use --rev or --working-dir)
239 (use --rev or --working-dir)
240 [255]
240 [255]
241
241
242 Fixing a public revision isn't allowed. It should abort early enough that
242 Fixing a public revision isn't allowed. It should abort early enough that
243 nothing happens, even to the working directory.
243 nothing happens, even to the working directory.
244
244
245 $ printf "hello\n" > hello.whole
245 $ printf "hello\n" > hello.whole
246 $ hg commit -Aqm "hello"
246 $ hg commit -Aqm "hello"
247 $ hg phase -r 0 --public
247 $ hg phase -r 0 --public
248 $ hg fix -r 0
248 $ hg fix -r 0
249 abort: can't fix immutable changeset 0:6470986d2e7b
249 abort: can't fix immutable changeset 0:6470986d2e7b
250 [255]
250 [255]
251 $ hg fix -r 0 --working-dir
251 $ hg fix -r 0 --working-dir
252 abort: can't fix immutable changeset 0:6470986d2e7b
252 abort: can't fix immutable changeset 0:6470986d2e7b
253 [255]
253 [255]
254 $ hg cat -r tip hello.whole
254 $ hg cat -r tip hello.whole
255 hello
255 hello
256 $ cat hello.whole
256 $ cat hello.whole
257 hello
257 hello
258
258
259 $ cd ..
259 $ cd ..
260
260
261 Fixing a clean working directory should do nothing. Even the --whole flag
261 Fixing a clean working directory should do nothing. Even the --whole flag
262 shouldn't cause any clean files to be fixed. Specifying a clean file explicitly
262 shouldn't cause any clean files to be fixed. Specifying a clean file explicitly
263 should only fix it if the fixer always fixes the whole file. The combination of
263 should only fix it if the fixer always fixes the whole file. The combination of
264 an explicit filename and --whole should format the entire file regardless.
264 an explicit filename and --whole should format the entire file regardless.
265
265
266 $ hg init fixcleanwdir
266 $ hg init fixcleanwdir
267 $ cd fixcleanwdir
267 $ cd fixcleanwdir
268
268
269 $ printf "hello\n" > hello.changed
269 $ printf "hello\n" > hello.changed
270 $ printf "world\n" > hello.whole
270 $ printf "world\n" > hello.whole
271 $ hg commit -Aqm "foo"
271 $ hg commit -Aqm "foo"
272 $ hg fix --working-dir
272 $ hg fix --working-dir
273 $ hg diff
273 $ hg diff
274 $ hg fix --working-dir --whole
274 $ hg fix --working-dir --whole
275 $ hg diff
275 $ hg diff
276 $ hg fix --working-dir *
276 $ hg fix --working-dir *
277 $ cat *
277 $ cat *
278 hello
278 hello
279 WORLD
279 WORLD
280 $ hg revert --all --no-backup
280 $ hg revert --all --no-backup
281 reverting hello.whole
281 reverting hello.whole
282 $ hg fix --working-dir * --whole
282 $ hg fix --working-dir * --whole
283 $ cat *
283 $ cat *
284 HELLO
284 HELLO
285 WORLD
285 WORLD
286
286
287 The same ideas apply to fixing a revision, so we create a revision that doesn't
287 The same ideas apply to fixing a revision, so we create a revision that doesn't
288 modify either of the files in question and try fixing it. This also tests that
288 modify either of the files in question and try fixing it. This also tests that
289 we ignore a file that doesn't match any configured fixer.
289 we ignore a file that doesn't match any configured fixer.
290
290
291 $ hg revert --all --no-backup
291 $ hg revert --all --no-backup
292 reverting hello.changed
292 reverting hello.changed
293 reverting hello.whole
293 reverting hello.whole
294 $ printf "unimportant\n" > some.file
294 $ printf "unimportant\n" > some.file
295 $ hg commit -Aqm "some other file"
295 $ hg commit -Aqm "some other file"
296
296
297 $ hg fix -r .
297 $ hg fix -r .
298 $ hg cat -r tip *
298 $ hg cat -r tip *
299 hello
299 hello
300 world
300 world
301 unimportant
301 unimportant
302 $ hg fix -r . --whole
302 $ hg fix -r . --whole
303 $ hg cat -r tip *
303 $ hg cat -r tip *
304 hello
304 hello
305 world
305 world
306 unimportant
306 unimportant
307 $ hg fix -r . *
307 $ hg fix -r . *
308 $ hg cat -r tip *
308 $ hg cat -r tip *
309 hello
309 hello
310 WORLD
310 WORLD
311 unimportant
311 unimportant
312 $ hg fix -r . * --whole --config experimental.evolution.allowdivergence=true
312 $ hg fix -r . * --whole --config experimental.evolution.allowdivergence=true
313 2 new content-divergent changesets
313 2 new content-divergent changesets
314 $ hg cat -r tip *
314 $ hg cat -r tip *
315 HELLO
315 HELLO
316 WORLD
316 WORLD
317 unimportant
317 unimportant
318
318
319 $ cd ..
319 $ cd ..
320
320
321 Fixing the working directory should still work if there are no revisions.
321 Fixing the working directory should still work if there are no revisions.
322
322
323 $ hg init norevisions
323 $ hg init norevisions
324 $ cd norevisions
324 $ cd norevisions
325
325
326 $ printf "something\n" > something.whole
326 $ printf "something\n" > something.whole
327 $ hg add
327 $ hg add
328 adding something.whole
328 adding something.whole
329 $ hg fix --working-dir
329 $ hg fix --working-dir
330 $ cat something.whole
330 $ cat something.whole
331 SOMETHING
331 SOMETHING
332
332
333 $ cd ..
333 $ cd ..
334
334
335 Test the effect of fixing the working directory for each possible status, with
335 Test the effect of fixing the working directory for each possible status, with
336 and without providing explicit file arguments.
336 and without providing explicit file arguments.
337
337
338 $ hg init implicitlyfixstatus
338 $ hg init implicitlyfixstatus
339 $ cd implicitlyfixstatus
339 $ cd implicitlyfixstatus
340
340
341 $ printf "modified\n" > modified.whole
341 $ printf "modified\n" > modified.whole
342 $ printf "removed\n" > removed.whole
342 $ printf "removed\n" > removed.whole
343 $ printf "deleted\n" > deleted.whole
343 $ printf "deleted\n" > deleted.whole
344 $ printf "clean\n" > clean.whole
344 $ printf "clean\n" > clean.whole
345 $ printf "ignored.whole" > .hgignore
345 $ printf "ignored.whole" > .hgignore
346 $ hg commit -Aqm "stuff"
346 $ hg commit -Aqm "stuff"
347
347
348 $ printf "modified!!!\n" > modified.whole
348 $ printf "modified!!!\n" > modified.whole
349 $ printf "unknown\n" > unknown.whole
349 $ printf "unknown\n" > unknown.whole
350 $ printf "ignored\n" > ignored.whole
350 $ printf "ignored\n" > ignored.whole
351 $ printf "added\n" > added.whole
351 $ printf "added\n" > added.whole
352 $ hg add added.whole
352 $ hg add added.whole
353 $ hg remove removed.whole
353 $ hg remove removed.whole
354 $ rm deleted.whole
354 $ rm deleted.whole
355
355
356 $ hg status --all
356 $ hg status --all
357 M modified.whole
357 M modified.whole
358 A added.whole
358 A added.whole
359 R removed.whole
359 R removed.whole
360 ! deleted.whole
360 ! deleted.whole
361 ? unknown.whole
361 ? unknown.whole
362 I ignored.whole
362 I ignored.whole
363 C .hgignore
363 C .hgignore
364 C clean.whole
364 C clean.whole
365
365
366 $ hg fix --working-dir
366 $ hg fix --working-dir
367
367
368 $ hg status --all
368 $ hg status --all
369 M modified.whole
369 M modified.whole
370 A added.whole
370 A added.whole
371 R removed.whole
371 R removed.whole
372 ! deleted.whole
372 ! deleted.whole
373 ? unknown.whole
373 ? unknown.whole
374 I ignored.whole
374 I ignored.whole
375 C .hgignore
375 C .hgignore
376 C clean.whole
376 C clean.whole
377
377
378 $ cat *.whole
378 $ cat *.whole
379 ADDED
379 ADDED
380 clean
380 clean
381 ignored
381 ignored
382 MODIFIED!!!
382 MODIFIED!!!
383 unknown
383 unknown
384
384
385 $ printf "modified!!!\n" > modified.whole
385 $ printf "modified!!!\n" > modified.whole
386 $ printf "added\n" > added.whole
386 $ printf "added\n" > added.whole
387
387
388 Listing the files explicitly causes untracked files to also be fixed, but
388 Listing the files explicitly causes untracked files to also be fixed, but
389 ignored files are still unaffected.
389 ignored files are still unaffected.
390
390
391 $ hg fix --working-dir *.whole
391 $ hg fix --working-dir *.whole
392
392
393 $ hg status --all
393 $ hg status --all
394 M clean.whole
394 M clean.whole
395 M modified.whole
395 M modified.whole
396 A added.whole
396 A added.whole
397 R removed.whole
397 R removed.whole
398 ! deleted.whole
398 ! deleted.whole
399 ? unknown.whole
399 ? unknown.whole
400 I ignored.whole
400 I ignored.whole
401 C .hgignore
401 C .hgignore
402
402
403 $ cat *.whole
403 $ cat *.whole
404 ADDED
404 ADDED
405 CLEAN
405 CLEAN
406 ignored
406 ignored
407 MODIFIED!!!
407 MODIFIED!!!
408 UNKNOWN
408 UNKNOWN
409
409
410 $ cd ..
410 $ cd ..
411
411
412 Test that incremental fixing works on files with additions, deletions, and
412 Test that incremental fixing works on files with additions, deletions, and
413 changes in multiple line ranges. Note that deletions do not generally cause
413 changes in multiple line ranges. Note that deletions do not generally cause
414 neighboring lines to be fixed, so we don't return a line range for purely
414 neighboring lines to be fixed, so we don't return a line range for purely
415 deleted sections. In the future we should support a :deletion config that
415 deleted sections. In the future we should support a :deletion config that
416 allows fixers to know where deletions are located.
416 allows fixers to know where deletions are located.
417
417
418 $ hg init incrementalfixedlines
418 $ hg init incrementalfixedlines
419 $ cd incrementalfixedlines
419 $ cd incrementalfixedlines
420
420
421 $ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.txt
421 $ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.txt
422 $ hg commit -Aqm "foo"
422 $ hg commit -Aqm "foo"
423 $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.txt
423 $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.txt
424
424
425 $ hg --config "fix.fail:command=echo" \
425 $ hg --config "fix.fail:command=echo" \
426 > --config "fix.fail:linerange={first}:{last}" \
426 > --config "fix.fail:linerange={first}:{last}" \
427 > --config "fix.fail:pattern=foo.txt" \
427 > --config "fix.fail:pattern=foo.txt" \
428 > fix --working-dir
428 > fix --working-dir
429 $ cat foo.txt
429 $ cat foo.txt
430 1:1 4:6 8:8
430 1:1 4:6 8:8
431
431
432 $ cd ..
432 $ cd ..
433
433
434 Test that --whole fixes all lines regardless of the diffs present.
434 Test that --whole fixes all lines regardless of the diffs present.
435
435
436 $ hg init wholeignoresdiffs
436 $ hg init wholeignoresdiffs
437 $ cd wholeignoresdiffs
437 $ cd wholeignoresdiffs
438
438
439 $ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.changed
439 $ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.changed
440 $ hg commit -Aqm "foo"
440 $ hg commit -Aqm "foo"
441 $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.changed
441 $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.changed
442
443 $ hg fix --working-dir
444 $ cat foo.changed
445 ZZ
446 a
447 c
448 DD
449 EE
450 FF
451 f
452 GG
453
442 $ hg fix --working-dir --whole
454 $ hg fix --working-dir --whole
443 $ cat foo.changed
455 $ cat foo.changed
444 ZZ
456 ZZ
445 A
457 A
446 C
458 C
447 DD
459 DD
448 EE
460 EE
449 FF
461 FF
450 F
462 F
451 GG
463 GG
452
464
453 $ cd ..
465 $ cd ..
454
466
455 We should do nothing with symlinks, and their targets should be unaffected. Any
467 We should do nothing with symlinks, and their targets should be unaffected. Any
456 other behavior would be more complicated to implement and harder to document.
468 other behavior would be more complicated to implement and harder to document.
457
469
458 #if symlink
470 #if symlink
459 $ hg init dontmesswithsymlinks
471 $ hg init dontmesswithsymlinks
460 $ cd dontmesswithsymlinks
472 $ cd dontmesswithsymlinks
461
473
462 $ printf "hello\n" > hello.whole
474 $ printf "hello\n" > hello.whole
463 $ ln -s hello.whole hellolink
475 $ ln -s hello.whole hellolink
464 $ hg add
476 $ hg add
465 adding hello.whole
477 adding hello.whole
466 adding hellolink
478 adding hellolink
467 $ hg fix --working-dir hellolink
479 $ hg fix --working-dir hellolink
468 $ hg status
480 $ hg status
469 A hello.whole
481 A hello.whole
470 A hellolink
482 A hellolink
471
483
472 $ cd ..
484 $ cd ..
473 #endif
485 #endif
474
486
475 We should allow fixers to run on binary files, even though this doesn't sound
487 We should allow fixers to run on binary files, even though this doesn't sound
476 like a common use case. There's not much benefit to disallowing it, and users
488 like a common use case. There's not much benefit to disallowing it, and users
477 can add "and not binary()" to their filesets if needed. The Mercurial
489 can add "and not binary()" to their filesets if needed. The Mercurial
478 philosophy is generally to not handle binary files specially anyway.
490 philosophy is generally to not handle binary files specially anyway.
479
491
480 $ hg init cantouchbinaryfiles
492 $ hg init cantouchbinaryfiles
481 $ cd cantouchbinaryfiles
493 $ cd cantouchbinaryfiles
482
494
483 $ printf "hello\0\n" > hello.whole
495 $ printf "hello\0\n" > hello.whole
484 $ hg add
496 $ hg add
485 adding hello.whole
497 adding hello.whole
486 $ hg fix --working-dir 'set:binary()'
498 $ hg fix --working-dir 'set:binary()'
487 $ cat hello.whole
499 $ cat hello.whole
488 HELLO\x00 (esc)
500 HELLO\x00 (esc)
489
501
490 $ cd ..
502 $ cd ..
491
503
492 We have a config for the maximum size of file we will attempt to fix. This can
504 We have a config for the maximum size of file we will attempt to fix. This can
493 be helpful to avoid running unsuspecting fixer tools on huge inputs, which
505 be helpful to avoid running unsuspecting fixer tools on huge inputs, which
494 could happen by accident without a well considered configuration. A more
506 could happen by accident without a well considered configuration. A more
495 precise configuration could use the size() fileset function if one global limit
507 precise configuration could use the size() fileset function if one global limit
496 is undesired.
508 is undesired.
497
509
498 $ hg init maxfilesize
510 $ hg init maxfilesize
499 $ cd maxfilesize
511 $ cd maxfilesize
500
512
501 $ printf "this file is huge\n" > hello.whole
513 $ printf "this file is huge\n" > hello.whole
502 $ hg add
514 $ hg add
503 adding hello.whole
515 adding hello.whole
504 $ hg --config fix.maxfilesize=10 fix --working-dir
516 $ hg --config fix.maxfilesize=10 fix --working-dir
505 ignoring file larger than 10 bytes: hello.whole
517 ignoring file larger than 10 bytes: hello.whole
506 $ cat hello.whole
518 $ cat hello.whole
507 this file is huge
519 this file is huge
508
520
509 $ cd ..
521 $ cd ..
510
522
511 If we specify a file to fix, other files should be left alone, even if they
523 If we specify a file to fix, other files should be left alone, even if they
512 have changes.
524 have changes.
513
525
514 $ hg init fixonlywhatitellyouto
526 $ hg init fixonlywhatitellyouto
515 $ cd fixonlywhatitellyouto
527 $ cd fixonlywhatitellyouto
516
528
517 $ printf "fix me!\n" > fixme.whole
529 $ printf "fix me!\n" > fixme.whole
518 $ printf "not me.\n" > notme.whole
530 $ printf "not me.\n" > notme.whole
519 $ hg add
531 $ hg add
520 adding fixme.whole
532 adding fixme.whole
521 adding notme.whole
533 adding notme.whole
522 $ hg fix --working-dir fixme.whole
534 $ hg fix --working-dir fixme.whole
523 $ cat *.whole
535 $ cat *.whole
524 FIX ME!
536 FIX ME!
525 not me.
537 not me.
526
538
527 $ cd ..
539 $ cd ..
528
540
541 If we try to fix a missing file, we still fix other files.
542
543 $ hg init fixmissingfile
544 $ cd fixmissingfile
545
546 $ printf "fix me!\n" > foo.whole
547 $ hg add
548 adding foo.whole
549 $ hg fix --working-dir foo.whole bar.whole
550 bar.whole: $ENOENT$
551 $ cat *.whole
552 FIX ME!
553
554 $ cd ..
555
529 Specifying a directory name should fix all its files and subdirectories.
556 Specifying a directory name should fix all its files and subdirectories.
530
557
531 $ hg init fixdirectory
558 $ hg init fixdirectory
532 $ cd fixdirectory
559 $ cd fixdirectory
533
560
534 $ mkdir -p dir1/dir2
561 $ mkdir -p dir1/dir2
535 $ printf "foo\n" > foo.whole
562 $ printf "foo\n" > foo.whole
536 $ printf "bar\n" > dir1/bar.whole
563 $ printf "bar\n" > dir1/bar.whole
537 $ printf "baz\n" > dir1/dir2/baz.whole
564 $ printf "baz\n" > dir1/dir2/baz.whole
538 $ hg add
565 $ hg add
539 adding dir1/bar.whole
566 adding dir1/bar.whole
540 adding dir1/dir2/baz.whole
567 adding dir1/dir2/baz.whole
541 adding foo.whole
568 adding foo.whole
542 $ hg fix --working-dir dir1
569 $ hg fix --working-dir dir1
543 $ cat foo.whole dir1/bar.whole dir1/dir2/baz.whole
570 $ cat foo.whole dir1/bar.whole dir1/dir2/baz.whole
544 foo
571 foo
545 BAR
572 BAR
546 BAZ
573 BAZ
547
574
548 $ cd ..
575 $ cd ..
549
576
550 Fixing a file in the working directory that needs no fixes should not actually
577 Fixing a file in the working directory that needs no fixes should not actually
551 write back to the file, so for example the mtime shouldn't change.
578 write back to the file, so for example the mtime shouldn't change.
552
579
553 $ hg init donttouchunfixedfiles
580 $ hg init donttouchunfixedfiles
554 $ cd donttouchunfixedfiles
581 $ cd donttouchunfixedfiles
555
582
556 $ printf "NO FIX NEEDED\n" > foo.whole
583 $ printf "NO FIX NEEDED\n" > foo.whole
557 $ hg add
584 $ hg add
558 adding foo.whole
585 adding foo.whole
559 $ cp -p foo.whole foo.whole.orig
586 $ cp -p foo.whole foo.whole.orig
560 $ cp -p foo.whole.orig foo.whole
587 $ cp -p foo.whole.orig foo.whole
561 $ sleep 2 # mtime has a resolution of one or two seconds.
588 $ sleep 2 # mtime has a resolution of one or two seconds.
562 $ hg fix --working-dir
589 $ hg fix --working-dir
563 $ f foo.whole.orig --newer foo.whole
590 $ f foo.whole.orig --newer foo.whole
564 foo.whole.orig: newer than foo.whole
591 foo.whole.orig: newer than foo.whole
565
592
566 $ cd ..
593 $ cd ..
567
594
568 When a fixer prints to stderr, we don't assume that it has failed. We show the
595 When a fixer prints to stderr, we don't assume that it has failed. We show the
569 error messages to the user, and we still let the fixer affect the file it was
596 error messages to the user, and we still let the fixer affect the file it was
570 fixing if its exit code is zero. Some code formatters might emit error messages
597 fixing if its exit code is zero. Some code formatters might emit error messages
571 on stderr and nothing on stdout, which would cause us the clear the file,
598 on stderr and nothing on stdout, which would cause us the clear the file,
572 except that they also exit with a non-zero code. We show the user which fixer
599 except that they also exit with a non-zero code. We show the user which fixer
573 emitted the stderr, and which revision, but we assume that the fixer will print
600 emitted the stderr, and which revision, but we assume that the fixer will print
574 the filename if it is relevant (since the issue may be non-specific). There is
601 the filename if it is relevant (since the issue may be non-specific). There is
575 also a config to abort (without affecting any files whatsoever) if we see any
602 also a config to abort (without affecting any files whatsoever) if we see any
576 tool with a non-zero exit status.
603 tool with a non-zero exit status.
577
604
578 $ hg init showstderr
605 $ hg init showstderr
579 $ cd showstderr
606 $ cd showstderr
580
607
581 $ printf "hello\n" > hello.txt
608 $ printf "hello\n" > hello.txt
582 $ hg add
609 $ hg add
583 adding hello.txt
610 adding hello.txt
584 $ cat > $TESTTMP/work.sh <<'EOF'
611 $ cat > $TESTTMP/work.sh <<'EOF'
585 > printf 'HELLO\n'
612 > printf 'HELLO\n'
586 > printf "$@: some\nerror that didn't stop the tool" >&2
613 > printf "$@: some\nerror that didn't stop the tool" >&2
587 > exit 0 # success despite the stderr output
614 > exit 0 # success despite the stderr output
588 > EOF
615 > EOF
589 $ hg --config "fix.work:command=sh $TESTTMP/work.sh {rootpath}" \
616 $ hg --config "fix.work:command=sh $TESTTMP/work.sh {rootpath}" \
590 > --config "fix.work:pattern=hello.txt" \
617 > --config "fix.work:pattern=hello.txt" \
591 > fix --working-dir
618 > fix --working-dir
592 [wdir] work: hello.txt: some
619 [wdir] work: hello.txt: some
593 [wdir] work: error that didn't stop the tool
620 [wdir] work: error that didn't stop the tool
594 $ cat hello.txt
621 $ cat hello.txt
595 HELLO
622 HELLO
596
623
597 $ printf "goodbye\n" > hello.txt
624 $ printf "goodbye\n" > hello.txt
598 $ printf "foo\n" > foo.whole
625 $ printf "foo\n" > foo.whole
599 $ hg add
626 $ hg add
600 adding foo.whole
627 adding foo.whole
601 $ cat > $TESTTMP/fail.sh <<'EOF'
628 $ cat > $TESTTMP/fail.sh <<'EOF'
602 > printf 'GOODBYE\n'
629 > printf 'GOODBYE\n'
603 > printf "$@: some\nerror that did stop the tool\n" >&2
630 > printf "$@: some\nerror that did stop the tool\n" >&2
604 > exit 42 # success despite the stdout output
631 > exit 42 # success despite the stdout output
605 > EOF
632 > EOF
606 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \
633 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \
607 > --config "fix.fail:pattern=hello.txt" \
634 > --config "fix.fail:pattern=hello.txt" \
608 > --config "fix.failure=abort" \
635 > --config "fix.failure=abort" \
609 > fix --working-dir
636 > fix --working-dir
610 [wdir] fail: hello.txt: some
637 [wdir] fail: hello.txt: some
611 [wdir] fail: error that did stop the tool
638 [wdir] fail: error that did stop the tool
612 abort: no fixes will be applied
639 abort: no fixes will be applied
613 (use --config fix.failure=continue to apply any successful fixes anyway)
640 (use --config fix.failure=continue to apply any successful fixes anyway)
614 [255]
641 [255]
615 $ cat hello.txt
642 $ cat hello.txt
616 goodbye
643 goodbye
617 $ cat foo.whole
644 $ cat foo.whole
618 foo
645 foo
619
646
620 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \
647 $ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \
621 > --config "fix.fail:pattern=hello.txt" \
648 > --config "fix.fail:pattern=hello.txt" \
622 > fix --working-dir
649 > fix --working-dir
623 [wdir] fail: hello.txt: some
650 [wdir] fail: hello.txt: some
624 [wdir] fail: error that did stop the tool
651 [wdir] fail: error that did stop the tool
625 $ cat hello.txt
652 $ cat hello.txt
626 goodbye
653 goodbye
627 $ cat foo.whole
654 $ cat foo.whole
628 FOO
655 FOO
629
656
630 $ hg --config "fix.fail:command=exit 42" \
657 $ hg --config "fix.fail:command=exit 42" \
631 > --config "fix.fail:pattern=hello.txt" \
658 > --config "fix.fail:pattern=hello.txt" \
632 > fix --working-dir
659 > fix --working-dir
633 [wdir] fail: exited with status 42
660 [wdir] fail: exited with status 42
634
661
635 $ cd ..
662 $ cd ..
636
663
637 Fixing the working directory and its parent revision at the same time should
664 Fixing the working directory and its parent revision at the same time should
638 check out the replacement revision for the parent. This prevents any new
665 check out the replacement revision for the parent. This prevents any new
639 uncommitted changes from appearing. We test this for a clean working directory
666 uncommitted changes from appearing. We test this for a clean working directory
640 and a dirty one. In both cases, all lines/files changed since the grandparent
667 and a dirty one. In both cases, all lines/files changed since the grandparent
641 will be fixed. The grandparent is the "baserev" for both the parent and the
668 will be fixed. The grandparent is the "baserev" for both the parent and the
642 working copy.
669 working copy.
643
670
644 $ hg init fixdotandcleanwdir
671 $ hg init fixdotandcleanwdir
645 $ cd fixdotandcleanwdir
672 $ cd fixdotandcleanwdir
646
673
647 $ printf "hello\n" > hello.whole
674 $ printf "hello\n" > hello.whole
648 $ printf "world\n" > world.whole
675 $ printf "world\n" > world.whole
649 $ hg commit -Aqm "the parent commit"
676 $ hg commit -Aqm "the parent commit"
650
677
651 $ hg parents --template '{rev} {desc}\n'
678 $ hg parents --template '{rev} {desc}\n'
652 0 the parent commit
679 0 the parent commit
653 $ hg fix --working-dir -r .
680 $ hg fix --working-dir -r .
654 $ hg parents --template '{rev} {desc}\n'
681 $ hg parents --template '{rev} {desc}\n'
655 1 the parent commit
682 1 the parent commit
656 $ hg cat -r . *.whole
683 $ hg cat -r . *.whole
657 HELLO
684 HELLO
658 WORLD
685 WORLD
659 $ cat *.whole
686 $ cat *.whole
660 HELLO
687 HELLO
661 WORLD
688 WORLD
662 $ hg status
689 $ hg status
663
690
664 $ cd ..
691 $ cd ..
665
692
666 Same test with a dirty working copy.
693 Same test with a dirty working copy.
667
694
668 $ hg init fixdotanddirtywdir
695 $ hg init fixdotanddirtywdir
669 $ cd fixdotanddirtywdir
696 $ cd fixdotanddirtywdir
670
697
671 $ printf "hello\n" > hello.whole
698 $ printf "hello\n" > hello.whole
672 $ printf "world\n" > world.whole
699 $ printf "world\n" > world.whole
673 $ hg commit -Aqm "the parent commit"
700 $ hg commit -Aqm "the parent commit"
674
701
675 $ printf "hello,\n" > hello.whole
702 $ printf "hello,\n" > hello.whole
676 $ printf "world!\n" > world.whole
703 $ printf "world!\n" > world.whole
677
704
678 $ hg parents --template '{rev} {desc}\n'
705 $ hg parents --template '{rev} {desc}\n'
679 0 the parent commit
706 0 the parent commit
680 $ hg fix --working-dir -r .
707 $ hg fix --working-dir -r .
681 $ hg parents --template '{rev} {desc}\n'
708 $ hg parents --template '{rev} {desc}\n'
682 1 the parent commit
709 1 the parent commit
683 $ hg cat -r . *.whole
710 $ hg cat -r . *.whole
684 HELLO
711 HELLO
685 WORLD
712 WORLD
686 $ cat *.whole
713 $ cat *.whole
687 HELLO,
714 HELLO,
688 WORLD!
715 WORLD!
689 $ hg status
716 $ hg status
690 M hello.whole
717 M hello.whole
691 M world.whole
718 M world.whole
692
719
693 $ cd ..
720 $ cd ..
694
721
695 When we have a chain of commits that change mutually exclusive lines of code,
722 When we have a chain of commits that change mutually exclusive lines of code,
696 we should be able to do incremental fixing that causes each commit in the chain
723 we should be able to do incremental fixing that causes each commit in the chain
697 to include fixes made to the previous commits. This prevents children from
724 to include fixes made to the previous commits. This prevents children from
698 backing out the fixes made in their parents. A dirty working directory is
725 backing out the fixes made in their parents. A dirty working directory is
699 conceptually similar to another commit in the chain.
726 conceptually similar to another commit in the chain.
700
727
701 $ hg init incrementallyfixchain
728 $ hg init incrementallyfixchain
702 $ cd incrementallyfixchain
729 $ cd incrementallyfixchain
703
730
704 $ cat > file.changed <<EOF
731 $ cat > file.changed <<EOF
705 > first
732 > first
706 > second
733 > second
707 > third
734 > third
708 > fourth
735 > fourth
709 > fifth
736 > fifth
710 > EOF
737 > EOF
711 $ hg commit -Aqm "the common ancestor (the baserev)"
738 $ hg commit -Aqm "the common ancestor (the baserev)"
712 $ cat > file.changed <<EOF
739 $ cat > file.changed <<EOF
713 > first (changed)
740 > first (changed)
714 > second
741 > second
715 > third
742 > third
716 > fourth
743 > fourth
717 > fifth
744 > fifth
718 > EOF
745 > EOF
719 $ hg commit -Aqm "the first commit to fix"
746 $ hg commit -Aqm "the first commit to fix"
720 $ cat > file.changed <<EOF
747 $ cat > file.changed <<EOF
721 > first (changed)
748 > first (changed)
722 > second
749 > second
723 > third (changed)
750 > third (changed)
724 > fourth
751 > fourth
725 > fifth
752 > fifth
726 > EOF
753 > EOF
727 $ hg commit -Aqm "the second commit to fix"
754 $ hg commit -Aqm "the second commit to fix"
728 $ cat > file.changed <<EOF
755 $ cat > file.changed <<EOF
729 > first (changed)
756 > first (changed)
730 > second
757 > second
731 > third (changed)
758 > third (changed)
732 > fourth
759 > fourth
733 > fifth (changed)
760 > fifth (changed)
734 > EOF
761 > EOF
735
762
736 $ hg fix -r . -r '.^' --working-dir
763 $ hg fix -r . -r '.^' --working-dir
737
764
738 $ hg parents --template '{rev}\n'
765 $ hg parents --template '{rev}\n'
739 4
766 4
740 $ hg cat -r '.^^' file.changed
767 $ hg cat -r '.^^' file.changed
741 first
768 first
742 second
769 second
743 third
770 third
744 fourth
771 fourth
745 fifth
772 fifth
746 $ hg cat -r '.^' file.changed
773 $ hg cat -r '.^' file.changed
747 FIRST (CHANGED)
774 FIRST (CHANGED)
748 second
775 second
749 third
776 third
750 fourth
777 fourth
751 fifth
778 fifth
752 $ hg cat -r . file.changed
779 $ hg cat -r . file.changed
753 FIRST (CHANGED)
780 FIRST (CHANGED)
754 second
781 second
755 THIRD (CHANGED)
782 THIRD (CHANGED)
756 fourth
783 fourth
757 fifth
784 fifth
758 $ cat file.changed
785 $ cat file.changed
759 FIRST (CHANGED)
786 FIRST (CHANGED)
760 second
787 second
761 THIRD (CHANGED)
788 THIRD (CHANGED)
762 fourth
789 fourth
763 FIFTH (CHANGED)
790 FIFTH (CHANGED)
764
791
765 $ cd ..
792 $ cd ..
766
793
767 If we incrementally fix a merge commit, we should fix any lines that changed
794 If we incrementally fix a merge commit, we should fix any lines that changed
768 versus either parent. You could imagine only fixing the intersection or some
795 versus either parent. You could imagine only fixing the intersection or some
769 other subset, but this is necessary if either parent is being fixed. It
796 other subset, but this is necessary if either parent is being fixed. It
770 prevents us from forgetting fixes made in either parent.
797 prevents us from forgetting fixes made in either parent.
771
798
772 $ hg init incrementallyfixmergecommit
799 $ hg init incrementallyfixmergecommit
773 $ cd incrementallyfixmergecommit
800 $ cd incrementallyfixmergecommit
774
801
775 $ printf "a\nb\nc\n" > file.changed
802 $ printf "a\nb\nc\n" > file.changed
776 $ hg commit -Aqm "ancestor"
803 $ hg commit -Aqm "ancestor"
777
804
778 $ printf "aa\nb\nc\n" > file.changed
805 $ printf "aa\nb\nc\n" > file.changed
779 $ hg commit -m "change a"
806 $ hg commit -m "change a"
780
807
781 $ hg checkout '.^'
808 $ hg checkout '.^'
782 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
809 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
783 $ printf "a\nb\ncc\n" > file.changed
810 $ printf "a\nb\ncc\n" > file.changed
784 $ hg commit -m "change c"
811 $ hg commit -m "change c"
785 created new head
812 created new head
786
813
787 $ hg merge
814 $ hg merge
788 merging file.changed
815 merging file.changed
789 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
816 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
790 (branch merge, don't forget to commit)
817 (branch merge, don't forget to commit)
791 $ hg commit -m "merge"
818 $ hg commit -m "merge"
792 $ hg cat -r . file.changed
819 $ hg cat -r . file.changed
793 aa
820 aa
794 b
821 b
795 cc
822 cc
796
823
797 $ hg fix -r . --working-dir
824 $ hg fix -r . --working-dir
798 $ hg cat -r . file.changed
825 $ hg cat -r . file.changed
799 AA
826 AA
800 b
827 b
801 CC
828 CC
802
829
803 $ cd ..
830 $ cd ..
804
831
805 Abort fixing revisions if there is an unfinished operation. We don't want to
832 Abort fixing revisions if there is an unfinished operation. We don't want to
806 make things worse by editing files or stripping/obsoleting things. Also abort
833 make things worse by editing files or stripping/obsoleting things. Also abort
807 fixing the working directory if there are unresolved merge conflicts.
834 fixing the working directory if there are unresolved merge conflicts.
808
835
809 $ hg init abortunresolved
836 $ hg init abortunresolved
810 $ cd abortunresolved
837 $ cd abortunresolved
811
838
812 $ echo "foo1" > foo.whole
839 $ echo "foo1" > foo.whole
813 $ hg commit -Aqm "foo 1"
840 $ hg commit -Aqm "foo 1"
814
841
815 $ hg update null
842 $ hg update null
816 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
843 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
817 $ echo "foo2" > foo.whole
844 $ echo "foo2" > foo.whole
818 $ hg commit -Aqm "foo 2"
845 $ hg commit -Aqm "foo 2"
819
846
820 $ hg --config extensions.rebase= rebase -r 1 -d 0
847 $ hg --config extensions.rebase= rebase -r 1 -d 0
821 rebasing 1:c3b6dc0e177a "foo 2" (tip)
848 rebasing 1:c3b6dc0e177a "foo 2" (tip)
822 merging foo.whole
849 merging foo.whole
823 warning: conflicts while merging foo.whole! (edit, then use 'hg resolve --mark')
850 warning: conflicts while merging foo.whole! (edit, then use 'hg resolve --mark')
824 unresolved conflicts (see hg resolve, then hg rebase --continue)
851 unresolved conflicts (see hg resolve, then hg rebase --continue)
825 [1]
852 [1]
826
853
827 $ hg --config extensions.rebase= fix --working-dir
854 $ hg --config extensions.rebase= fix --working-dir
828 abort: unresolved conflicts
855 abort: unresolved conflicts
829 (use 'hg resolve')
856 (use 'hg resolve')
830 [255]
857 [255]
831
858
832 $ hg --config extensions.rebase= fix -r .
859 $ hg --config extensions.rebase= fix -r .
833 abort: rebase in progress
860 abort: rebase in progress
834 (use 'hg rebase --continue' or 'hg rebase --abort')
861 (use 'hg rebase --continue' or 'hg rebase --abort')
835 [255]
862 [255]
836
863
837 $ cd ..
864 $ cd ..
838
865
839 When fixing a file that was renamed, we should diff against the source of the
866 When fixing a file that was renamed, we should diff against the source of the
840 rename for incremental fixing and we should correctly reproduce the rename in
867 rename for incremental fixing and we should correctly reproduce the rename in
841 the replacement revision.
868 the replacement revision.
842
869
843 $ hg init fixrenamecommit
870 $ hg init fixrenamecommit
844 $ cd fixrenamecommit
871 $ cd fixrenamecommit
845
872
846 $ printf "a\nb\nc\n" > source.changed
873 $ printf "a\nb\nc\n" > source.changed
847 $ hg commit -Aqm "source revision"
874 $ hg commit -Aqm "source revision"
848 $ hg move source.changed dest.changed
875 $ hg move source.changed dest.changed
849 $ printf "a\nb\ncc\n" > dest.changed
876 $ printf "a\nb\ncc\n" > dest.changed
850 $ hg commit -m "dest revision"
877 $ hg commit -m "dest revision"
851
878
852 $ hg fix -r .
879 $ hg fix -r .
853 $ hg log -r tip --copies --template "{file_copies}\n"
880 $ hg log -r tip --copies --template "{file_copies}\n"
854 dest.changed (source.changed)
881 dest.changed (source.changed)
855 $ hg cat -r tip dest.changed
882 $ hg cat -r tip dest.changed
856 a
883 a
857 b
884 b
858 CC
885 CC
859
886
860 $ cd ..
887 $ cd ..
861
888
862 When fixing revisions that remove files we must ensure that the replacement
889 When fixing revisions that remove files we must ensure that the replacement
863 actually removes the file, whereas it could accidentally leave it unchanged or
890 actually removes the file, whereas it could accidentally leave it unchanged or
864 write an empty string to it.
891 write an empty string to it.
865
892
866 $ hg init fixremovedfile
893 $ hg init fixremovedfile
867 $ cd fixremovedfile
894 $ cd fixremovedfile
868
895
869 $ printf "foo\n" > foo.whole
896 $ printf "foo\n" > foo.whole
870 $ printf "bar\n" > bar.whole
897 $ printf "bar\n" > bar.whole
871 $ hg commit -Aqm "add files"
898 $ hg commit -Aqm "add files"
872 $ hg remove bar.whole
899 $ hg remove bar.whole
873 $ hg commit -m "remove file"
900 $ hg commit -m "remove file"
874 $ hg status --change .
901 $ hg status --change .
875 R bar.whole
902 R bar.whole
876 $ hg fix -r . foo.whole
903 $ hg fix -r . foo.whole
877 $ hg status --change tip
904 $ hg status --change tip
878 M foo.whole
905 M foo.whole
879 R bar.whole
906 R bar.whole
880
907
881 $ cd ..
908 $ cd ..
882
909
883 If fixing a revision finds no fixes to make, no replacement revision should be
910 If fixing a revision finds no fixes to make, no replacement revision should be
884 created.
911 created.
885
912
886 $ hg init nofixesneeded
913 $ hg init nofixesneeded
887 $ cd nofixesneeded
914 $ cd nofixesneeded
888
915
889 $ printf "FOO\n" > foo.whole
916 $ printf "FOO\n" > foo.whole
890 $ hg commit -Aqm "add file"
917 $ hg commit -Aqm "add file"
891 $ hg log --template '{rev}\n'
918 $ hg log --template '{rev}\n'
892 0
919 0
893 $ hg fix -r .
920 $ hg fix -r .
894 $ hg log --template '{rev}\n'
921 $ hg log --template '{rev}\n'
895 0
922 0
896
923
897 $ cd ..
924 $ cd ..
898
925
899 If fixing a commit reverts all the changes in the commit, we replace it with a
926 If fixing a commit reverts all the changes in the commit, we replace it with a
900 commit that changes no files.
927 commit that changes no files.
901
928
902 $ hg init nochangesleft
929 $ hg init nochangesleft
903 $ cd nochangesleft
930 $ cd nochangesleft
904
931
905 $ printf "FOO\n" > foo.whole
932 $ printf "FOO\n" > foo.whole
906 $ hg commit -Aqm "add file"
933 $ hg commit -Aqm "add file"
907 $ printf "foo\n" > foo.whole
934 $ printf "foo\n" > foo.whole
908 $ hg commit -m "edit file"
935 $ hg commit -m "edit file"
909 $ hg status --change .
936 $ hg status --change .
910 M foo.whole
937 M foo.whole
911 $ hg fix -r .
938 $ hg fix -r .
912 $ hg status --change tip
939 $ hg status --change tip
913
940
914 $ cd ..
941 $ cd ..
915
942
916 If we fix a parent and child revision together, the child revision must be
943 If we fix a parent and child revision together, the child revision must be
917 replaced if the parent is replaced, even if the diffs of the child needed no
944 replaced if the parent is replaced, even if the diffs of the child needed no
918 fixes. However, we're free to not replace revisions that need no fixes and have
945 fixes. However, we're free to not replace revisions that need no fixes and have
919 no ancestors that are replaced.
946 no ancestors that are replaced.
920
947
921 $ hg init mustreplacechild
948 $ hg init mustreplacechild
922 $ cd mustreplacechild
949 $ cd mustreplacechild
923
950
924 $ printf "FOO\n" > foo.whole
951 $ printf "FOO\n" > foo.whole
925 $ hg commit -Aqm "add foo"
952 $ hg commit -Aqm "add foo"
926 $ printf "foo\n" > foo.whole
953 $ printf "foo\n" > foo.whole
927 $ hg commit -m "edit foo"
954 $ hg commit -m "edit foo"
928 $ printf "BAR\n" > bar.whole
955 $ printf "BAR\n" > bar.whole
929 $ hg commit -Aqm "add bar"
956 $ hg commit -Aqm "add bar"
930
957
931 $ hg log --graph --template '{rev} {files}'
958 $ hg log --graph --template '{rev} {files}'
932 @ 2 bar.whole
959 @ 2 bar.whole
933 |
960 |
934 o 1 foo.whole
961 o 1 foo.whole
935 |
962 |
936 o 0 foo.whole
963 o 0 foo.whole
937
964
938 $ hg fix -r 0:2
965 $ hg fix -r 0:2
939 $ hg log --graph --template '{rev} {files}'
966 $ hg log --graph --template '{rev} {files}'
940 o 4 bar.whole
967 o 4 bar.whole
941 |
968 |
942 o 3
969 o 3
943 |
970 |
944 | @ 2 bar.whole
971 | @ 2 bar.whole
945 | |
972 | |
946 | x 1 foo.whole
973 | x 1 foo.whole
947 |/
974 |/
948 o 0 foo.whole
975 o 0 foo.whole
949
976
950
977
951 $ cd ..
978 $ cd ..
952
979
953 It's also possible that the child needs absolutely no changes, but we still
980 It's also possible that the child needs absolutely no changes, but we still
954 need to replace it to update its parent. If we skipped replacing the child
981 need to replace it to update its parent. If we skipped replacing the child
955 because it had no file content changes, it would become an orphan for no good
982 because it had no file content changes, it would become an orphan for no good
956 reason.
983 reason.
957
984
958 $ hg init mustreplacechildevenifnop
985 $ hg init mustreplacechildevenifnop
959 $ cd mustreplacechildevenifnop
986 $ cd mustreplacechildevenifnop
960
987
961 $ printf "Foo\n" > foo.whole
988 $ printf "Foo\n" > foo.whole
962 $ hg commit -Aqm "add a bad foo"
989 $ hg commit -Aqm "add a bad foo"
963 $ printf "FOO\n" > foo.whole
990 $ printf "FOO\n" > foo.whole
964 $ hg commit -m "add a good foo"
991 $ hg commit -m "add a good foo"
965 $ hg fix -r . -r '.^'
992 $ hg fix -r . -r '.^'
966 $ hg log --graph --template '{rev} {desc}'
993 $ hg log --graph --template '{rev} {desc}'
967 o 3 add a good foo
994 o 3 add a good foo
968 |
995 |
969 o 2 add a bad foo
996 o 2 add a bad foo
970
997
971 @ 1 add a good foo
998 @ 1 add a good foo
972 |
999 |
973 x 0 add a bad foo
1000 x 0 add a bad foo
974
1001
975
1002
976 $ cd ..
1003 $ cd ..
977
1004
978 Similar to the case above, the child revision may become empty as a result of
1005 Similar to the case above, the child revision may become empty as a result of
979 fixing its parent. We should still create an empty replacement child.
1006 fixing its parent. We should still create an empty replacement child.
980 TODO: determine how this should interact with ui.allowemptycommit given that
1007 TODO: determine how this should interact with ui.allowemptycommit given that
981 the empty replacement could have children.
1008 the empty replacement could have children.
982
1009
983 $ hg init mustreplacechildevenifempty
1010 $ hg init mustreplacechildevenifempty
984 $ cd mustreplacechildevenifempty
1011 $ cd mustreplacechildevenifempty
985
1012
986 $ printf "foo\n" > foo.whole
1013 $ printf "foo\n" > foo.whole
987 $ hg commit -Aqm "add foo"
1014 $ hg commit -Aqm "add foo"
988 $ printf "Foo\n" > foo.whole
1015 $ printf "Foo\n" > foo.whole
989 $ hg commit -m "edit foo"
1016 $ hg commit -m "edit foo"
990 $ hg fix -r . -r '.^'
1017 $ hg fix -r . -r '.^'
991 $ hg log --graph --template '{rev} {desc}\n' --stat
1018 $ hg log --graph --template '{rev} {desc}\n' --stat
992 o 3 edit foo
1019 o 3 edit foo
993 |
1020 |
994 o 2 add foo
1021 o 2 add foo
995 foo.whole | 1 +
1022 foo.whole | 1 +
996 1 files changed, 1 insertions(+), 0 deletions(-)
1023 1 files changed, 1 insertions(+), 0 deletions(-)
997
1024
998 @ 1 edit foo
1025 @ 1 edit foo
999 | foo.whole | 2 +-
1026 | foo.whole | 2 +-
1000 | 1 files changed, 1 insertions(+), 1 deletions(-)
1027 | 1 files changed, 1 insertions(+), 1 deletions(-)
1001 |
1028 |
1002 x 0 add foo
1029 x 0 add foo
1003 foo.whole | 1 +
1030 foo.whole | 1 +
1004 1 files changed, 1 insertions(+), 0 deletions(-)
1031 1 files changed, 1 insertions(+), 0 deletions(-)
1005
1032
1006
1033
1007 $ cd ..
1034 $ cd ..
1008
1035
1009 Fixing a secret commit should replace it with another secret commit.
1036 Fixing a secret commit should replace it with another secret commit.
1010
1037
1011 $ hg init fixsecretcommit
1038 $ hg init fixsecretcommit
1012 $ cd fixsecretcommit
1039 $ cd fixsecretcommit
1013
1040
1014 $ printf "foo\n" > foo.whole
1041 $ printf "foo\n" > foo.whole
1015 $ hg commit -Aqm "add foo" --secret
1042 $ hg commit -Aqm "add foo" --secret
1016 $ hg fix -r .
1043 $ hg fix -r .
1017 $ hg log --template '{rev} {phase}\n'
1044 $ hg log --template '{rev} {phase}\n'
1018 1 secret
1045 1 secret
1019 0 secret
1046 0 secret
1020
1047
1021 $ cd ..
1048 $ cd ..
1022
1049
1023 We should also preserve phase when fixing a draft commit while the user has
1050 We should also preserve phase when fixing a draft commit while the user has
1024 their default set to secret.
1051 their default set to secret.
1025
1052
1026 $ hg init respectphasesnewcommit
1053 $ hg init respectphasesnewcommit
1027 $ cd respectphasesnewcommit
1054 $ cd respectphasesnewcommit
1028
1055
1029 $ printf "foo\n" > foo.whole
1056 $ printf "foo\n" > foo.whole
1030 $ hg commit -Aqm "add foo"
1057 $ hg commit -Aqm "add foo"
1031 $ hg --config phases.newcommit=secret fix -r .
1058 $ hg --config phases.newcommit=secret fix -r .
1032 $ hg log --template '{rev} {phase}\n'
1059 $ hg log --template '{rev} {phase}\n'
1033 1 draft
1060 1 draft
1034 0 draft
1061 0 draft
1035
1062
1036 $ cd ..
1063 $ cd ..
1037
1064
1038 Debug output should show what fixer commands are being subprocessed, which is
1065 Debug output should show what fixer commands are being subprocessed, which is
1039 useful for anyone trying to set up a new config.
1066 useful for anyone trying to set up a new config.
1040
1067
1041 $ hg init debugoutput
1068 $ hg init debugoutput
1042 $ cd debugoutput
1069 $ cd debugoutput
1043
1070
1044 $ printf "foo\nbar\nbaz\n" > foo.changed
1071 $ printf "foo\nbar\nbaz\n" > foo.changed
1045 $ hg commit -Aqm "foo"
1072 $ hg commit -Aqm "foo"
1046 $ printf "Foo\nbar\nBaz\n" > foo.changed
1073 $ printf "Foo\nbar\nBaz\n" > foo.changed
1047 $ hg --debug fix --working-dir
1074 $ hg --debug fix --working-dir
1048 subprocess: * $TESTTMP/uppercase.py 1-1 3-3 (glob)
1075 subprocess: * $TESTTMP/uppercase.py 1-1 3-3 (glob)
1049
1076
1050 $ cd ..
1077 $ cd ..
1051
1078
1052 Fixing an obsolete revision can cause divergence, so we abort unless the user
1079 Fixing an obsolete revision can cause divergence, so we abort unless the user
1053 configures to allow it. This is not yet smart enough to know whether there is a
1080 configures to allow it. This is not yet smart enough to know whether there is a
1054 successor, but even then it is not likely intentional or idiomatic to fix an
1081 successor, but even then it is not likely intentional or idiomatic to fix an
1055 obsolete revision.
1082 obsolete revision.
1056
1083
1057 $ hg init abortobsoleterev
1084 $ hg init abortobsoleterev
1058 $ cd abortobsoleterev
1085 $ cd abortobsoleterev
1059
1086
1060 $ printf "foo\n" > foo.changed
1087 $ printf "foo\n" > foo.changed
1061 $ hg commit -Aqm "foo"
1088 $ hg commit -Aqm "foo"
1062 $ hg debugobsolete `hg parents --template '{node}'`
1089 $ hg debugobsolete `hg parents --template '{node}'`
1063 obsoleted 1 changesets
1090 obsoleted 1 changesets
1064 $ hg --hidden fix -r 0
1091 $ hg --hidden fix -r 0
1065 abort: fixing obsolete revision could cause divergence
1092 abort: fixing obsolete revision could cause divergence
1066 [255]
1093 [255]
1067
1094
1068 $ hg --hidden fix -r 0 --config experimental.evolution.allowdivergence=true
1095 $ hg --hidden fix -r 0 --config experimental.evolution.allowdivergence=true
1069 $ hg cat -r tip foo.changed
1096 $ hg cat -r tip foo.changed
1070 FOO
1097 FOO
1071
1098
1072 $ cd ..
1099 $ cd ..
1073
1100
1074 Test all of the available substitution values for fixer commands.
1101 Test all of the available substitution values for fixer commands.
1075
1102
1076 $ hg init substitution
1103 $ hg init substitution
1077 $ cd substitution
1104 $ cd substitution
1078
1105
1079 $ mkdir foo
1106 $ mkdir foo
1080 $ printf "hello\ngoodbye\n" > foo/bar
1107 $ printf "hello\ngoodbye\n" > foo/bar
1081 $ hg add
1108 $ hg add
1082 adding foo/bar
1109 adding foo/bar
1083 $ hg --config "fix.fail:command=printf '%s\n' '{rootpath}' '{basename}'" \
1110 $ hg --config "fix.fail:command=printf '%s\n' '{rootpath}' '{basename}'" \
1084 > --config "fix.fail:linerange='{first}' '{last}'" \
1111 > --config "fix.fail:linerange='{first}' '{last}'" \
1085 > --config "fix.fail:pattern=foo/bar" \
1112 > --config "fix.fail:pattern=foo/bar" \
1086 > fix --working-dir
1113 > fix --working-dir
1087 $ cat foo/bar
1114 $ cat foo/bar
1088 foo/bar
1115 foo/bar
1089 bar
1116 bar
1090 1
1117 1
1091 2
1118 2
1092
1119
1093 $ cd ..
1120 $ cd ..
1094
1121
1095 The --base flag should allow picking the revisions to diff against for changed
1122 The --base flag should allow picking the revisions to diff against for changed
1096 files and incremental line formatting.
1123 files and incremental line formatting.
1097
1124
1098 $ hg init baseflag
1125 $ hg init baseflag
1099 $ cd baseflag
1126 $ cd baseflag
1100
1127
1101 $ printf "one\ntwo\n" > foo.changed
1128 $ printf "one\ntwo\n" > foo.changed
1102 $ printf "bar\n" > bar.changed
1129 $ printf "bar\n" > bar.changed
1103 $ hg commit -Aqm "first"
1130 $ hg commit -Aqm "first"
1104 $ printf "one\nTwo\n" > foo.changed
1131 $ printf "one\nTwo\n" > foo.changed
1105 $ hg commit -m "second"
1132 $ hg commit -m "second"
1106 $ hg fix -w --base .
1133 $ hg fix -w --base .
1107 $ hg status
1134 $ hg status
1108 $ hg fix -w --base null
1135 $ hg fix -w --base null
1109 $ cat foo.changed
1136 $ cat foo.changed
1110 ONE
1137 ONE
1111 TWO
1138 TWO
1112 $ cat bar.changed
1139 $ cat bar.changed
1113 BAR
1140 BAR
1114
1141
1115 $ cd ..
1142 $ cd ..
1116
1143
1117 If the user asks to fix the parent of another commit, they are asking to create
1144 If the user asks to fix the parent of another commit, they are asking to create
1118 an orphan. We must respect experimental.evolution.allowunstable.
1145 an orphan. We must respect experimental.evolution.allowunstable.
1119
1146
1120 $ hg init allowunstable
1147 $ hg init allowunstable
1121 $ cd allowunstable
1148 $ cd allowunstable
1122
1149
1123 $ printf "one\n" > foo.whole
1150 $ printf "one\n" > foo.whole
1124 $ hg commit -Aqm "first"
1151 $ hg commit -Aqm "first"
1125 $ printf "two\n" > foo.whole
1152 $ printf "two\n" > foo.whole
1126 $ hg commit -m "second"
1153 $ hg commit -m "second"
1127 $ hg --config experimental.evolution.allowunstable=False fix -r '.^'
1154 $ hg --config experimental.evolution.allowunstable=False fix -r '.^'
1128 abort: can only fix a changeset together with all its descendants
1155 abort: can only fix a changeset together with all its descendants
1129 [255]
1156 [255]
1130 $ hg fix -r '.^'
1157 $ hg fix -r '.^'
1131 1 new orphan changesets
1158 1 new orphan changesets
1132 $ hg cat -r 2 foo.whole
1159 $ hg cat -r 2 foo.whole
1133 ONE
1160 ONE
1134
1161
1135 $ cd ..
1162 $ cd ..
1136
1163
1137 The --base flag affects the set of files being fixed. So while the --whole flag
1164 The --base flag affects the set of files being fixed. So while the --whole flag
1138 makes the base irrelevant for changed line ranges, it still changes the
1165 makes the base irrelevant for changed line ranges, it still changes the
1139 meaning and effect of the command. In this example, no files or lines are fixed
1166 meaning and effect of the command. In this example, no files or lines are fixed
1140 until we specify the base, but then we do fix unchanged lines.
1167 until we specify the base, but then we do fix unchanged lines.
1141
1168
1142 $ hg init basewhole
1169 $ hg init basewhole
1143 $ cd basewhole
1170 $ cd basewhole
1144 $ printf "foo1\n" > foo.changed
1171 $ printf "foo1\n" > foo.changed
1145 $ hg commit -Aqm "first"
1172 $ hg commit -Aqm "first"
1146 $ printf "foo2\n" >> foo.changed
1173 $ printf "foo2\n" >> foo.changed
1147 $ printf "bar\n" > bar.changed
1174 $ printf "bar\n" > bar.changed
1148 $ hg commit -Aqm "second"
1175 $ hg commit -Aqm "second"
1149
1176
1150 $ hg fix --working-dir --whole
1177 $ hg fix --working-dir --whole
1151 $ cat *.changed
1178 $ cat *.changed
1152 bar
1179 bar
1153 foo1
1180 foo1
1154 foo2
1181 foo2
1155
1182
1156 $ hg fix --working-dir --base 0 --whole
1183 $ hg fix --working-dir --base 0 --whole
1157 $ cat *.changed
1184 $ cat *.changed
1158 BAR
1185 BAR
1159 FOO1
1186 FOO1
1160 FOO2
1187 FOO2
1161
1188
1162 $ cd ..
1189 $ cd ..
1163
1190
1164 The execution order of tools can be controlled. This example doesn't work if
1191 The execution order of tools can be controlled. This example doesn't work if
1165 you sort after truncating, but the config defines the correct order while the
1192 you sort after truncating, but the config defines the correct order while the
1166 definitions are out of order (which might imply the incorrect order given the
1193 definitions are out of order (which might imply the incorrect order given the
1167 implementation of fix). The goal is to use multiple tools to select the lowest
1194 implementation of fix). The goal is to use multiple tools to select the lowest
1168 5 numbers in the file.
1195 5 numbers in the file.
1169
1196
1170 $ hg init priorityexample
1197 $ hg init priorityexample
1171 $ cd priorityexample
1198 $ cd priorityexample
1172
1199
1173 $ cat >> .hg/hgrc <<EOF
1200 $ cat >> .hg/hgrc <<EOF
1174 > [fix]
1201 > [fix]
1175 > head:command = head -n 5
1202 > head:command = head -n 5
1176 > head:pattern = numbers.txt
1203 > head:pattern = numbers.txt
1177 > head:priority = 1
1204 > head:priority = 1
1178 > sort:command = sort -n
1205 > sort:command = sort -n
1179 > sort:pattern = numbers.txt
1206 > sort:pattern = numbers.txt
1180 > sort:priority = 2
1207 > sort:priority = 2
1181 > EOF
1208 > EOF
1182
1209
1183 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt
1210 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt
1184 $ hg add -q
1211 $ hg add -q
1185 $ hg fix -w
1212 $ hg fix -w
1186 $ cat numbers.txt
1213 $ cat numbers.txt
1187 0
1214 0
1188 1
1215 1
1189 2
1216 2
1190 3
1217 3
1191 4
1218 4
1192
1219
1193 And of course we should be able to break this by reversing the execution order.
1220 And of course we should be able to break this by reversing the execution order.
1194 Test negative priorities while we're at it.
1221 Test negative priorities while we're at it.
1195
1222
1196 $ cat >> .hg/hgrc <<EOF
1223 $ cat >> .hg/hgrc <<EOF
1197 > [fix]
1224 > [fix]
1198 > head:priority = -1
1225 > head:priority = -1
1199 > sort:priority = -2
1226 > sort:priority = -2
1200 > EOF
1227 > EOF
1201 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt
1228 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt
1202 $ hg fix -w
1229 $ hg fix -w
1203 $ cat numbers.txt
1230 $ cat numbers.txt
1204 2
1231 2
1205 3
1232 3
1206 6
1233 6
1207 7
1234 7
1208 8
1235 8
1209
1236
1210 $ cd ..
1237 $ cd ..
1211
1238
1212 It's possible for repeated applications of a fixer tool to create cycles in the
1239 It's possible for repeated applications of a fixer tool to create cycles in the
1213 generated content of a file. For example, two users with different versions of
1240 generated content of a file. For example, two users with different versions of
1214 a code formatter might fight over the formatting when they run hg fix. In the
1241 a code formatter might fight over the formatting when they run hg fix. In the
1215 absence of other changes, this means we could produce commits with the same
1242 absence of other changes, this means we could produce commits with the same
1216 hash in subsequent runs of hg fix. This is a problem unless we support
1243 hash in subsequent runs of hg fix. This is a problem unless we support
1217 obsolescence cycles well. We avoid this by adding an extra field to the
1244 obsolescence cycles well. We avoid this by adding an extra field to the
1218 successor which forces it to have a new hash. That's why this test creates
1245 successor which forces it to have a new hash. That's why this test creates
1219 three revisions instead of two.
1246 three revisions instead of two.
1220
1247
1221 $ hg init cyclictool
1248 $ hg init cyclictool
1222 $ cd cyclictool
1249 $ cd cyclictool
1223
1250
1224 $ cat >> .hg/hgrc <<EOF
1251 $ cat >> .hg/hgrc <<EOF
1225 > [fix]
1252 > [fix]
1226 > swapletters:command = tr ab ba
1253 > swapletters:command = tr ab ba
1227 > swapletters:pattern = foo
1254 > swapletters:pattern = foo
1228 > EOF
1255 > EOF
1229
1256
1230 $ echo ab > foo
1257 $ echo ab > foo
1231 $ hg commit -Aqm foo
1258 $ hg commit -Aqm foo
1232
1259
1233 $ hg fix -r 0
1260 $ hg fix -r 0
1234 $ hg fix -r 1
1261 $ hg fix -r 1
1235
1262
1236 $ hg cat -r 0 foo --hidden
1263 $ hg cat -r 0 foo --hidden
1237 ab
1264 ab
1238 $ hg cat -r 1 foo --hidden
1265 $ hg cat -r 1 foo --hidden
1239 ba
1266 ba
1240 $ hg cat -r 2 foo
1267 $ hg cat -r 2 foo
1241 ab
1268 ab
1242
1269
1243 $ cd ..
1270 $ cd ..
1244
1271
1245 Tools configured without a pattern are ignored. It would be too dangerous to
1272 Tools configured without a pattern are ignored. It would be too dangerous to
1246 run them on all files, because this might happen while testing a configuration
1273 run them on all files, because this might happen while testing a configuration
1247 that also deletes all of the file content. There is no reasonable subset of the
1274 that also deletes all of the file content. There is no reasonable subset of the
1248 files to use as a default. Users should be explicit about what files are
1275 files to use as a default. Users should be explicit about what files are
1249 affected by a tool. This test also confirms that we don't crash when the
1276 affected by a tool. This test also confirms that we don't crash when the
1250 pattern config is missing, and that we only warn about it once.
1277 pattern config is missing, and that we only warn about it once.
1251
1278
1252 $ hg init nopatternconfigured
1279 $ hg init nopatternconfigured
1253 $ cd nopatternconfigured
1280 $ cd nopatternconfigured
1254
1281
1255 $ printf "foo" > foo
1282 $ printf "foo" > foo
1256 $ printf "bar" > bar
1283 $ printf "bar" > bar
1257 $ hg add -q
1284 $ hg add -q
1258 $ hg fix --debug --working-dir --config "fix.nopattern:command=echo fixed"
1285 $ hg fix --debug --working-dir --config "fix.nopattern:command=echo fixed"
1259 fixer tool has no pattern configuration: nopattern
1286 fixer tool has no pattern configuration: nopattern
1260 $ cat foo bar
1287 $ cat foo bar
1261 foobar (no-eol)
1288 foobar (no-eol)
1262
1289
1263 $ cd ..
1290 $ cd ..
1264
1291
1265 Test that we can configure a fixer to affect all files regardless of the cwd.
1292 Test that we can configure a fixer to affect all files regardless of the cwd.
1266 The way we invoke matching must not prohibit this.
1293 The way we invoke matching must not prohibit this.
1267
1294
1268 $ hg init affectallfiles
1295 $ hg init affectallfiles
1269 $ cd affectallfiles
1296 $ cd affectallfiles
1270
1297
1271 $ mkdir foo bar
1298 $ mkdir foo bar
1272 $ printf "foo" > foo/file
1299 $ printf "foo" > foo/file
1273 $ printf "bar" > bar/file
1300 $ printf "bar" > bar/file
1274 $ printf "baz" > baz_file
1301 $ printf "baz" > baz_file
1275 $ hg add -q
1302 $ hg add -q
1276
1303
1277 $ cd bar
1304 $ cd bar
1278 $ hg fix --working-dir --config "fix.cooltool:command=echo fixed" \
1305 $ hg fix --working-dir --config "fix.cooltool:command=echo fixed" \
1279 > --config "fix.cooltool:pattern=rootglob:**"
1306 > --config "fix.cooltool:pattern=rootglob:**"
1280 $ cd ..
1307 $ cd ..
1281
1308
1282 $ cat foo/file
1309 $ cat foo/file
1283 fixed
1310 fixed
1284 $ cat bar/file
1311 $ cat bar/file
1285 fixed
1312 fixed
1286 $ cat baz_file
1313 $ cat baz_file
1287 fixed
1314 fixed
1288
1315
1289 $ cd ..
1316 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now