| 1 |
#require curses |
| 2 |
|
| 3 |
Set up a repo |
| 4 |
|
| 5 |
$ cp $HGRCPATH $HGRCPATH.pretest |
| 6 |
$ cat <<EOF >> $HGRCPATH |
| 7 |
> [ui] |
| 8 |
> interactive = true |
| 9 |
> interface = curses |
| 10 |
> [experimental] |
| 11 |
> crecordtest = testModeCommands |
| 12 |
> EOF |
| 13 |
|
| 14 |
Record with noeol at eof (issue5268) |
| 15 |
$ hg init noeol |
| 16 |
$ cd noeol |
| 17 |
$ printf '0' > a |
| 18 |
$ printf '0\n' > b |
| 19 |
$ hg ci -Aqm initial |
| 20 |
$ printf '1\n0' > a |
| 21 |
$ printf '1\n0\n' > b |
| 22 |
$ cat <<EOF >testModeCommands |
| 23 |
> c |
| 24 |
> EOF |
| 25 |
$ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -m "add hunks" -d "0 0" |
| 26 |
$ cd .. |
| 27 |
|
| 28 |
Normal repo |
| 29 |
$ hg init a |
| 30 |
$ cd a |
| 31 |
|
| 32 |
Committing some changes but stopping on the way |
| 33 |
|
| 34 |
$ echo "a" > a |
| 35 |
$ hg add a |
| 36 |
$ cat <<EOF >testModeCommands |
| 37 |
> x |
| 38 |
> c |
| 39 |
> EOF |
| 40 |
$ hg commit -i -m "a" -d "0 0" |
| 41 |
no changes to record |
| 42 |
[1] |
| 43 |
$ hg tip |
| 44 |
changeset: -1:000000000000 |
| 45 |
tag: tip |
| 46 |
user: |
| 47 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 48 |
|
| 49 |
|
| 50 |
Committing some changes |
| 51 |
|
| 52 |
$ cat <<EOF >testModeCommands |
| 53 |
> c |
| 54 |
> EOF |
| 55 |
$ hg commit -i -m "a" -d "0 0" |
| 56 |
$ hg tip |
| 57 |
changeset: 0:cb9a9f314b8b |
| 58 |
tag: tip |
| 59 |
user: test |
| 60 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 61 |
summary: a |
| 62 |
|
| 63 |
Check that commit -i works with no changes |
| 64 |
$ hg commit -i |
| 65 |
no changes to record |
| 66 |
[1] |
| 67 |
|
| 68 |
Committing only one file |
| 69 |
|
| 70 |
$ echo "a" >> a |
| 71 |
>>> open('b', 'wb').write(b"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n") and None |
| 72 |
$ hg add b |
| 73 |
$ cat <<EOF >testModeCommands |
| 74 |
> x |
| 75 |
> KEY_DOWN |
| 76 |
> c |
| 77 |
> EOF |
| 78 |
$ hg commit -i -m "one file" -d "0 0" |
| 79 |
$ hg tip |
| 80 |
changeset: 1:fb2705a663ea |
| 81 |
tag: tip |
| 82 |
user: test |
| 83 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 84 |
summary: one file |
| 85 |
|
| 86 |
$ hg cat -r tip a |
| 87 |
a |
| 88 |
$ cat a |
| 89 |
a |
| 90 |
a |
| 91 |
|
| 92 |
Committing only one hunk while aborting edition of hunk |
| 93 |
|
| 94 |
- Untoggle all the hunks, go down to the second file |
| 95 |
- unfold it |
| 96 |
- go down to second hunk (1 for the first hunk, 1 for the first hunkline, 1 for the second hunk, 1 for the second hunklike) |
| 97 |
- toggle the second hunk |
| 98 |
- toggle all lines twice (to check that it does nothing) |
| 99 |
- edit the hunk and quit the editor immediately with non-zero status |
| 100 |
- commit |
| 101 |
|
| 102 |
$ printf "printf 'editor ran\n'; exit 1" > editor.sh |
| 103 |
$ echo "x" > c |
| 104 |
$ cat b >> c |
| 105 |
$ echo "y" >> c |
| 106 |
$ mv c b |
| 107 |
$ cat <<EOF >testModeCommands |
| 108 |
> A |
| 109 |
> KEY_DOWN |
| 110 |
> f |
| 111 |
> KEY_DOWN |
| 112 |
> KEY_DOWN |
| 113 |
> KEY_DOWN |
| 114 |
> KEY_DOWN |
| 115 |
> x |
| 116 |
> a |
| 117 |
> a |
| 118 |
> e |
| 119 |
> c |
| 120 |
> EOF |
| 121 |
$ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -m "one hunk" -d "0 0" |
| 122 |
editor ran |
| 123 |
$ rm editor.sh |
| 124 |
$ hg tip |
| 125 |
changeset: 2:7d10dfe755a8 |
| 126 |
tag: tip |
| 127 |
user: test |
| 128 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 129 |
summary: one hunk |
| 130 |
|
| 131 |
$ hg cat -r tip b |
| 132 |
1 |
| 133 |
2 |
| 134 |
3 |
| 135 |
4 |
| 136 |
5 |
| 137 |
6 |
| 138 |
7 |
| 139 |
8 |
| 140 |
9 |
| 141 |
10 |
| 142 |
y |
| 143 |
$ cat b |
| 144 |
x |
| 145 |
1 |
| 146 |
2 |
| 147 |
3 |
| 148 |
4 |
| 149 |
5 |
| 150 |
6 |
| 151 |
7 |
| 152 |
8 |
| 153 |
9 |
| 154 |
10 |
| 155 |
y |
| 156 |
$ hg commit -m "other hunks" |
| 157 |
$ hg tip |
| 158 |
changeset: 3:a6735021574d |
| 159 |
tag: tip |
| 160 |
user: test |
| 161 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 162 |
summary: other hunks |
| 163 |
|
| 164 |
$ hg cat -r tip b |
| 165 |
x |
| 166 |
1 |
| 167 |
2 |
| 168 |
3 |
| 169 |
4 |
| 170 |
5 |
| 171 |
6 |
| 172 |
7 |
| 173 |
8 |
| 174 |
9 |
| 175 |
10 |
| 176 |
y |
| 177 |
|
| 178 |
Newly added files can be selected with the curses interface |
| 179 |
|
| 180 |
$ hg update -C . |
| 181 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 182 |
$ echo "hello" > x |
| 183 |
$ hg add x |
| 184 |
$ cat <<EOF >testModeCommands |
| 185 |
> x |
| 186 |
> x |
| 187 |
> c |
| 188 |
> EOF |
| 189 |
$ hg st |
| 190 |
A x |
| 191 |
? testModeCommands |
| 192 |
$ hg commit -i -m "newly added file" -d "0 0" |
| 193 |
$ hg st |
| 194 |
? testModeCommands |
| 195 |
|
| 196 |
Test toggling all selections works |
| 197 |
|
| 198 |
- Change one line |
| 199 |
- Add an extra line at the end |
| 200 |
- Unselect all |
| 201 |
- Select the extra line at the end |
| 202 |
- Toggle all selections (so the extra line at the is unselected and the modified line is selected) |
| 203 |
- Commit |
| 204 |
|
| 205 |
$ echo "hello world" > x |
| 206 |
$ echo "goodbye world" >> x |
| 207 |
$ hg diff |
| 208 |
diff -r 2b0e9be4d336 x |
| 209 |
--- a/x Thu Jan 01 00:00:00 1970 +0000 |
| 210 |
+++ b/x Thu Jan 01 00:00:00 1970 +0000 |
| 211 |
@@ -1,1 +1,2 @@ |
| 212 |
-hello |
| 213 |
+hello world |
| 214 |
+goodbye world |
| 215 |
$ cat <<EOF >testModeCommands |
| 216 |
> f |
| 217 |
> j |
| 218 |
> x |
| 219 |
> j |
| 220 |
> j |
| 221 |
> j |
| 222 |
> x |
| 223 |
> a |
| 224 |
> c |
| 225 |
> EOF |
| 226 |
$ hg commit -i --amend -m "newly added file" -d "0 0" x |
| 227 |
saved backup bundle to $TESTTMP/a/.hg/strip-backup/2b0e9be4d336-3cf0bc8c-amend.hg |
| 228 |
$ hg rev x --no-backup |
| 229 |
$ hg diff -c . |
| 230 |
diff -r a6735021574d -r c1d239d165ae x |
| 231 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
| 232 |
+++ b/x Thu Jan 01 00:00:00 1970 +0000 |
| 233 |
@@ -0,0 +1,1 @@ |
| 234 |
+hello world |
| 235 |
|
| 236 |
Make file empty |
| 237 |
$ printf "" > x |
| 238 |
$ cat <<EOF >testModeCommands |
| 239 |
> c |
| 240 |
> EOF |
| 241 |
$ hg ci -i -m emptify -d "0 0" |
| 242 |
$ hg update -C '.^' -q |
| 243 |
|
| 244 |
Editing a hunk puts you back on that hunk when done editing (issue5041) |
| 245 |
To do that, we change two lines in a file, pretend to edit the second line, |
| 246 |
exit, toggle the line selected at the end of the edit and commit. |
| 247 |
The first line should be recorded if we were put on the second line at the end |
| 248 |
of the edit. |
| 249 |
|
| 250 |
$ hg update -C . |
| 251 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 252 |
$ echo "foo" > x |
| 253 |
$ echo "hello world" >> x |
| 254 |
$ echo "bar" >> x |
| 255 |
$ cat <<EOF >testModeCommands |
| 256 |
> f |
| 257 |
> KEY_DOWN |
| 258 |
> KEY_DOWN |
| 259 |
> KEY_DOWN |
| 260 |
> KEY_DOWN |
| 261 |
> e |
| 262 |
> x |
| 263 |
> c |
| 264 |
> EOF |
| 265 |
$ printf "printf 'editor ran\n'; exit 0" > editor.sh |
| 266 |
$ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -m "edit hunk" -d "0 0" -q |
| 267 |
editor ran |
| 268 |
$ hg cat -r . x |
| 269 |
foo |
| 270 |
hello world |
| 271 |
|
| 272 |
Testing the review option. The entire final filtered patch should show |
| 273 |
up in the editor and be editable. We will unselect the second file and |
| 274 |
the first hunk of the third file. During review, we will decide that |
| 275 |
"lower" sounds better than "bottom", and the final commit should |
| 276 |
reflect this edition. |
| 277 |
|
| 278 |
$ hg update -C . |
| 279 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 280 |
$ echo "top" > c |
| 281 |
$ cat x >> c |
| 282 |
$ echo "bottom" >> c |
| 283 |
$ mv c x |
| 284 |
$ echo "third a" >> a |
| 285 |
$ echo "we will unselect this" >> b |
| 286 |
|
| 287 |
$ cat > editor.sh <<EOF |
| 288 |
> cat "\$1" |
| 289 |
> cat "\$1" | sed s/bottom/lower/ > tmp |
| 290 |
> mv tmp "\$1" |
| 291 |
> EOF |
| 292 |
$ cat > testModeCommands <<EOF |
| 293 |
> KEY_DOWN |
| 294 |
> x |
| 295 |
> KEY_DOWN |
| 296 |
> f |
| 297 |
> KEY_DOWN |
| 298 |
> x |
| 299 |
> R |
| 300 |
> EOF |
| 301 |
|
| 302 |
$ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -m "review hunks" -d "0 0" |
| 303 |
# To remove '-' lines, make them ' ' lines (context). |
| 304 |
# To remove '+' lines, delete them. |
| 305 |
# Lines starting with # will be removed from the patch. |
| 306 |
# |
| 307 |
# If the patch applies cleanly, the edited patch will immediately |
| 308 |
# be finalised. If it does not apply cleanly, rejects files will be |
| 309 |
# generated. You can use those when you try again. |
| 310 |
diff --git a/a b/a |
| 311 |
--- a/a |
| 312 |
+++ b/a |
| 313 |
@@ -1,2 +1,3 @@ |
| 314 |
a |
| 315 |
a |
| 316 |
+third a |
| 317 |
diff --git a/x b/x |
| 318 |
--- a/x |
| 319 |
+++ b/x |
| 320 |
@@ -1,2 +1,3 @@ |
| 321 |
foo |
| 322 |
hello world |
| 323 |
+bottom |
| 324 |
|
| 325 |
$ hg cat -r . a |
| 326 |
a |
| 327 |
a |
| 328 |
third a |
| 329 |
|
| 330 |
$ hg cat -r . b |
| 331 |
x |
| 332 |
1 |
| 333 |
2 |
| 334 |
3 |
| 335 |
4 |
| 336 |
5 |
| 337 |
6 |
| 338 |
7 |
| 339 |
8 |
| 340 |
9 |
| 341 |
10 |
| 342 |
y |
| 343 |
|
| 344 |
$ hg cat -r . x |
| 345 |
foo |
| 346 |
hello world |
| 347 |
lower |
| 348 |
|
| 349 |
Test range select: unselect 3, 5, and 6, reselect 5, then go back up to 2 and |
| 350 |
press 'X', unselecting (because 2 is currently selected) 5 (because it's the |
| 351 |
start of the range) and 4, leaving 3 unselected. |
| 352 |
|
| 353 |
$ hg init $TESTTMP/range_select |
| 354 |
$ cd $TESTTMP/range_select |
| 355 |
>>> open('range_select', 'wb').write(b"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n") and None |
| 356 |
$ hg add range_select |
| 357 |
$ cat <<EOF >testModeCommands |
| 358 |
> KEY_RIGHT |
| 359 |
> KEY_RIGHT |
| 360 |
> KEY_DOWN |
| 361 |
> KEY_DOWN |
| 362 |
> KEY_ENTER |
| 363 |
> KEY_DOWN |
| 364 |
> KEY_ENTER |
| 365 |
> x |
| 366 |
> KEY_UP |
| 367 |
> x |
| 368 |
> KEY_UP |
| 369 |
> KEY_UP |
| 370 |
> KEY_UP |
| 371 |
> X |
| 372 |
> c |
| 373 |
> EOF |
| 374 |
$ hg commit -i -m "range_select" -d "0 0" |
| 375 |
$ hg cat -r tip range_select |
| 376 |
1 |
| 377 |
7 |
| 378 |
8 |
| 379 |
9 |
| 380 |
10 |
| 381 |
$ cat range_select |
| 382 |
1 |
| 383 |
2 |
| 384 |
3 |
| 385 |
4 |
| 386 |
5 |
| 387 |
6 |
| 388 |
7 |
| 389 |
8 |
| 390 |
9 |
| 391 |
10 |
| 392 |
|
| 393 |
Check ui.interface logic for the chunkselector |
| 394 |
|
| 395 |
The default interface is text |
| 396 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 397 |
$ chunkselectorinterface() { |
| 398 |
> "$PYTHON" <<EOF |
| 399 |
> from mercurial import pycompat, ui;\ |
| 400 |
> from mercurial.repo import factory |
| 401 |
> repo = factory.repository(ui.ui.load(), b".");\ |
| 402 |
> print(pycompat.sysstr(repo.ui.interface(b"chunkselector"))) |
| 403 |
> EOF |
| 404 |
> } |
| 405 |
$ chunkselectorinterface |
| 406 |
text |
| 407 |
|
| 408 |
If only the default is set, we'll use that for the feature, too |
| 409 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 410 |
$ cat <<EOF >> $HGRCPATH |
| 411 |
> [ui] |
| 412 |
> interface = curses |
| 413 |
> EOF |
| 414 |
$ chunkselectorinterface |
| 415 |
curses |
| 416 |
|
| 417 |
If TERM=dumb, we use text, even if the config says curses |
| 418 |
$ chunkselectorinterface |
| 419 |
curses |
| 420 |
$ TERM=dumb chunkselectorinterface |
| 421 |
text |
| 422 |
(Something is keeping TERM=dumb in the environment unless I do this, it's not |
| 423 |
scoped to just that previous command like in many shells) |
| 424 |
$ TERM=xterm chunkselectorinterface |
| 425 |
curses |
| 426 |
|
| 427 |
It is possible to override the default interface with a feature specific |
| 428 |
interface |
| 429 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 430 |
$ cat <<EOF >> $HGRCPATH |
| 431 |
> [ui] |
| 432 |
> interface = text |
| 433 |
> interface.chunkselector = curses |
| 434 |
> EOF |
| 435 |
|
| 436 |
$ chunkselectorinterface |
| 437 |
curses |
| 438 |
|
| 439 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 440 |
$ cat <<EOF >> $HGRCPATH |
| 441 |
> [ui] |
| 442 |
> interface = curses |
| 443 |
> interface.chunkselector = text |
| 444 |
> EOF |
| 445 |
|
| 446 |
$ chunkselectorinterface |
| 447 |
text |
| 448 |
|
| 449 |
If a bad interface name is given, we use the default value (with a nice |
| 450 |
error message to suggest that the configuration needs to be fixed) |
| 451 |
|
| 452 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 453 |
$ cat <<EOF >> $HGRCPATH |
| 454 |
> [ui] |
| 455 |
> interface = blah |
| 456 |
> EOF |
| 457 |
$ chunkselectorinterface |
| 458 |
invalid value for ui.interface: blah (using text) |
| 459 |
text |
| 460 |
|
| 461 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 462 |
$ cat <<EOF >> $HGRCPATH |
| 463 |
> [ui] |
| 464 |
> interface = curses |
| 465 |
> interface.chunkselector = blah |
| 466 |
> EOF |
| 467 |
$ chunkselectorinterface |
| 468 |
invalid value for ui.interface.chunkselector: blah (using curses) |
| 469 |
curses |
| 470 |
|
| 471 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 472 |
$ cat <<EOF >> $HGRCPATH |
| 473 |
> [ui] |
| 474 |
> interface = blah |
| 475 |
> interface.chunkselector = curses |
| 476 |
> EOF |
| 477 |
$ chunkselectorinterface |
| 478 |
invalid value for ui.interface: blah |
| 479 |
curses |
| 480 |
|
| 481 |
$ cp $HGRCPATH.pretest $HGRCPATH |
| 482 |
$ cat <<EOF >> $HGRCPATH |
| 483 |
> [ui] |
| 484 |
> interface = blah |
| 485 |
> interface.chunkselector = blah |
| 486 |
> EOF |
| 487 |
$ chunkselectorinterface |
| 488 |
invalid value for ui.interface: blah |
| 489 |
invalid value for ui.interface.chunkselector: blah (using text) |
| 490 |
text |