1 #!/bin/sh |
|
2 |
|
3 # test for issue #6: |
|
4 # editing a changeset without any actual change would corrupt the repository |
|
5 |
|
6 . "$TESTDIR/histedit-helpers.sh" |
|
7 |
|
8 cat >> $HGRCPATH <<EOF |
|
9 [extensions] |
|
10 graphlog= |
|
11 histedit= |
|
12 EOF |
|
13 |
|
14 initrepo () |
|
15 { |
|
16 dir="$1" |
|
17 comment="$2" |
|
18 |
|
19 if [ -n "${comment}" ]; then |
|
20 echo % ${comment} |
|
21 echo % ${comment} | sed 's:.:-:g' |
|
22 fi |
|
23 |
|
24 hg init ${dir} |
|
25 cd ${dir} |
|
26 for x in a b c d e f ; do |
|
27 echo $x > $x |
|
28 hg add $x |
|
29 hg ci -m $x |
|
30 done |
|
31 } |
|
32 |
|
33 geneditor () |
|
34 { |
|
35 # generate an editor script for selecting changesets to be edited |
|
36 |
|
37 choice=$1 # changesets that should be edited (using sed line ranges) |
|
38 |
|
39 cat <<EOF | sed 's:^....::' |
|
40 #!/bin/sh |
|
41 |
|
42 # editing the rules, replacing 'pick' with 'edit' for the chosen lines |
|
43 sed '${choice}s:^pick:edit:' \$1 > \${1}.tmp |
|
44 mv \${1}.tmp \$1 |
|
45 |
|
46 # displaying the resulting rules, minus comments and empty lines |
|
47 sed '/^#/d;/^$/d;s:^:| :' \$1 >&2 |
|
48 EOF |
|
49 } |
|
50 |
|
51 startediting () |
|
52 { |
|
53 # begin an editing session |
|
54 |
|
55 choice="$1" # changesets that should be edited |
|
56 number="$2" # number of changesets considered (from tip) |
|
57 comment="$3" |
|
58 |
|
59 geneditor "${choice}" > edit.sh |
|
60 chmod +x edit.sh |
|
61 |
|
62 echo % start editing the history ${comment} |
|
63 HGEDITOR=./edit.sh hg histedit -- -${number} 2>&1 | fixbundle |
|
64 } |
|
65 |
|
66 continueediting () |
|
67 { |
|
68 # continue an edit already in progress |
|
69 |
|
70 editor="$1" # message editor when finalizing editing |
|
71 comment="$2" |
|
72 |
|
73 echo % finalize changeset editing ${comment} |
|
74 HGEDITOR=${editor} hg histedit --continue 2>&1 | fixbundle |
|
75 } |
|
76 |
|
77 graphlog () |
|
78 { |
|
79 comment="${1:-log}" |
|
80 |
|
81 echo % "${comment}" |
|
82 hg glog --template '{rev} {node} \"{desc|firstline}\"\n' |
|
83 } |
|
84 |
|
85 |
|
86 |
|
87 initrepo r1 "test editing with no change" |
|
88 graphlog "log before editing" |
|
89 startediting 2 3 "(not changing anything)" # edit the 2nd of 3 changesets |
|
90 continueediting true "(leaving commit message unaltered)" |
|
91 |
|
92 echo "% check state of working copy" |
|
93 hg id |
|
94 |
|
95 graphlog "log after history editing" |
|
96 |
|
97 |
|
98 cd .. |
|
99 initrepo r2 "test editing with no change, then abort" |
|
100 graphlog "log before editing" |
|
101 startediting 1,2 3 "(not changing anything)" # edit the 1st two of 3 changesets |
|
102 continueediting true "(leaving commit message unaltered)" |
|
103 graphlog "log after first edit" |
|
104 |
|
105 echo % abort editing session |
|
106 hg histedit --abort 2>&1 | fixbundle |
|
107 |
|
108 graphlog "log after abort" |
|
109 |
|
110 echo % EOF |
|