| 1 |
test for old histedit issue #6: |
| 2 |
editing a changeset without any actual change would corrupt the repository |
| 3 |
|
| 4 |
$ . "$TESTDIR/histedit-helpers.sh" |
| 5 |
|
| 6 |
$ cat >> $HGRCPATH <<EOF |
| 7 |
> [extensions] |
| 8 |
> histedit= |
| 9 |
> EOF |
| 10 |
|
| 11 |
$ initrepo () |
| 12 |
> { |
| 13 |
> dir="$1" |
| 14 |
> comment="$2" |
| 15 |
> if [ -n "${comment}" ]; then |
| 16 |
> echo % ${comment} |
| 17 |
> echo % ${comment} | sed 's:.:-:g' |
| 18 |
> fi |
| 19 |
> hg init ${dir} |
| 20 |
> cd ${dir} |
| 21 |
> for x in a b c d e f ; do |
| 22 |
> echo $x > $x |
| 23 |
> hg add $x |
| 24 |
> hg ci -m $x |
| 25 |
> done |
| 26 |
> cd .. |
| 27 |
> } |
| 28 |
|
| 29 |
$ geneditor () |
| 30 |
> { |
| 31 |
> # generate an editor script for selecting changesets to be edited |
| 32 |
> choice=$1 # changesets that should be edited (using sed line ranges) |
| 33 |
> cat <<EOF | sed 's:^....::' |
| 34 |
> # editing the rules, replacing 'pick' with 'edit' for the chosen lines |
| 35 |
> sed '${choice}s:^pick:edit:' "\$1" > "\${1}.tmp" |
| 36 |
> mv "\${1}.tmp" "\$1" |
| 37 |
> # displaying the resulting rules, minus comments and empty lines |
| 38 |
> sed '/^#/d;/^$/d;s:^:| :' "\$1" >&2 |
| 39 |
> EOF |
| 40 |
> } |
| 41 |
|
| 42 |
$ startediting () |
| 43 |
> { |
| 44 |
> # begin an editing session |
| 45 |
> choice="$1" # changesets that should be edited |
| 46 |
> number="$2" # number of changesets considered (from tip) |
| 47 |
> comment="$3" |
| 48 |
> geneditor "${choice}" > edit.sh |
| 49 |
> echo % start editing the history ${comment} |
| 50 |
> HGEDITOR="sh ./edit.sh" hg histedit -- -${number} 2>&1 | fixbundle |
| 51 |
> } |
| 52 |
|
| 53 |
$ continueediting () |
| 54 |
> { |
| 55 |
> # continue an edit already in progress |
| 56 |
> editor="$1" # message editor when finalizing editing |
| 57 |
> comment="$2" |
| 58 |
> echo % finalize changeset editing ${comment} |
| 59 |
> HGEDITOR=${editor} hg histedit --continue 2>&1 | fixbundle |
| 60 |
> } |
| 61 |
|
| 62 |
$ graphlog () |
| 63 |
> { |
| 64 |
> comment="${1:-log}" |
| 65 |
> echo % "${comment}" |
| 66 |
> hg log -G --template '{rev} {node} \"{desc|firstline}\"\n' |
| 67 |
> } |
| 68 |
|
| 69 |
|
| 70 |
$ initrepo r1 "test editing with no change" |
| 71 |
% test editing with no change |
| 72 |
----------------------------- |
| 73 |
$ cd r1 |
| 74 |
$ graphlog "log before editing" |
| 75 |
% log before editing |
| 76 |
@ 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" |
| 77 |
| |
| 78 |
o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" |
| 79 |
| |
| 80 |
o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" |
| 81 |
| |
| 82 |
o 2 177f92b773850b59254aa5e923436f921b55483b "c" |
| 83 |
| |
| 84 |
o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" |
| 85 |
| |
| 86 |
o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" |
| 87 |
|
| 88 |
$ startediting 2 3 "(not changing anything)" # edit the 2nd of 3 changesets |
| 89 |
% start editing the history (not changing anything) |
| 90 |
| pick 055a42cdd887 3 d |
| 91 |
| edit e860deea161a 4 e |
| 92 |
| pick 652413bf663e 5 f |
| 93 |
0 files updated, 0 files merged, 2 files removed, 0 files unresolved |
| 94 |
Editing (e860deea161a), commit as needed now to split the change |
| 95 |
(to edit e860deea161a, `hg histedit --continue` after making changes) |
| 96 |
$ continueediting true "(leaving commit message unaltered)" |
| 97 |
% finalize changeset editing (leaving commit message unaltered) |
| 98 |
|
| 99 |
|
| 100 |
check state of working copy |
| 101 |
$ hg id |
| 102 |
794fe033d0a0 tip |
| 103 |
|
| 104 |
$ graphlog "log after history editing" |
| 105 |
% log after history editing |
| 106 |
@ 5 794fe033d0a030f8df77c5de945fca35c9181c30 "f" |
| 107 |
| |
| 108 |
o 4 04d2fab980779f332dec458cc944f28de8b43435 "e" |
| 109 |
| |
| 110 |
o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" |
| 111 |
| |
| 112 |
o 2 177f92b773850b59254aa5e923436f921b55483b "c" |
| 113 |
| |
| 114 |
o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" |
| 115 |
| |
| 116 |
o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" |
| 117 |
|
| 118 |
|
| 119 |
$ cd .. |
| 120 |
|
| 121 |
$ initrepo r2 "test editing with no change, then abort" |
| 122 |
% test editing with no change, then abort |
| 123 |
----------------------------------------- |
| 124 |
$ cd r2 |
| 125 |
$ graphlog "log before editing" |
| 126 |
% log before editing |
| 127 |
@ 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" |
| 128 |
| |
| 129 |
o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" |
| 130 |
| |
| 131 |
o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" |
| 132 |
| |
| 133 |
o 2 177f92b773850b59254aa5e923436f921b55483b "c" |
| 134 |
| |
| 135 |
o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" |
| 136 |
| |
| 137 |
o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" |
| 138 |
|
| 139 |
$ startediting 1,2 3 "(not changing anything)" # edit the 1st two of 3 changesets |
| 140 |
% start editing the history (not changing anything) |
| 141 |
| edit 055a42cdd887 3 d |
| 142 |
| edit e860deea161a 4 e |
| 143 |
| pick 652413bf663e 5 f |
| 144 |
0 files updated, 0 files merged, 3 files removed, 0 files unresolved |
| 145 |
Editing (055a42cdd887), commit as needed now to split the change |
| 146 |
(to edit 055a42cdd887, `hg histedit --continue` after making changes) |
| 147 |
$ continueediting true "(leaving commit message unaltered)" |
| 148 |
% finalize changeset editing (leaving commit message unaltered) |
| 149 |
Editing (e860deea161a), commit as needed now to split the change |
| 150 |
(to edit e860deea161a, `hg histedit --continue` after making changes) |
| 151 |
$ graphlog "log after first edit" |
| 152 |
% log after first edit |
| 153 |
@ 6 e5ae3ca2f1ffdbd89ec41ebc273a231f7c3022f2 "d" |
| 154 |
| |
| 155 |
| o 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" |
| 156 |
| | |
| 157 |
| o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" |
| 158 |
| | |
| 159 |
| o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" |
| 160 |
|/ |
| 161 |
o 2 177f92b773850b59254aa5e923436f921b55483b "c" |
| 162 |
| |
| 163 |
o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" |
| 164 |
| |
| 165 |
o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" |
| 166 |
|
| 167 |
|
| 168 |
abort editing session, after first forcibly updating away |
| 169 |
$ hg up 0 |
| 170 |
abort: histedit in progress |
| 171 |
(use 'hg histedit --continue' or 'hg histedit --abort') |
| 172 |
[20] |
| 173 |
$ mv .hg/histedit-state .hg/histedit-state-ignore |
| 174 |
$ hg up 0 |
| 175 |
0 files updated, 0 files merged, 3 files removed, 0 files unresolved |
| 176 |
$ mv .hg/histedit-state-ignore .hg/histedit-state |
| 177 |
$ hg sum |
| 178 |
parent: 0:cb9a9f314b8b |
| 179 |
a |
| 180 |
branch: default |
| 181 |
commit: 1 added, 1 unknown (new branch head) |
| 182 |
update: 6 new changesets (update) |
| 183 |
phases: 7 draft |
| 184 |
hist: 2 remaining (histedit --continue) |
| 185 |
|
| 186 |
$ hg histedit --abort 2>&1 | fixbundle |
| 187 |
|
| 188 |
modified files should survive the abort when we've moved away already |
| 189 |
$ hg st |
| 190 |
A e |
| 191 |
? edit.sh |
| 192 |
|
| 193 |
$ graphlog "log after abort" |
| 194 |
% log after abort |
| 195 |
o 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" |
| 196 |
| |
| 197 |
o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" |
| 198 |
| |
| 199 |
o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" |
| 200 |
| |
| 201 |
o 2 177f92b773850b59254aa5e923436f921b55483b "c" |
| 202 |
| |
| 203 |
o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" |
| 204 |
| |
| 205 |
@ 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" |
| 206 |
|
| 207 |
aborting and not changing files can skip mentioning updating (no) files |
| 208 |
$ hg up |
| 209 |
5 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 210 |
$ hg commit --close-branch -m 'closebranch' |
| 211 |
$ startediting 1 1 "(not changing anything)" # edit the 3rd of 3 changesets |
| 212 |
% start editing the history (not changing anything) |
| 213 |
| edit 292aec348d9e 6 closebranch |
| 214 |
Editing (292aec348d9e), commit as needed now to split the change |
| 215 |
(to edit 292aec348d9e, `hg histedit --continue` after making changes) |
| 216 |
$ hg histedit --abort |
| 217 |
|
| 218 |
$ cd .. |