| | @@ -23,11 +23,10 @@ |
| 23 | 23 | # Test 'fossil revert' against expected results from 'fossil changes' and |
| 24 | 24 | # 'fossil addremove -n', as well as by verifying the existence of files |
| 25 | 25 | # on the file system. 'fossil undo' is called after each test |
| 26 | 26 | # |
| 27 | 27 | proc revert-test {testid revertArgs expectedRevertOutput args} { |
| 28 | | - global RESULT |
| 29 | 28 | set passed 1 |
| 30 | 29 | |
| 31 | 30 | set args [dict merge { |
| 32 | 31 | -changes {} -addremove {} -exists {} -notexists {} |
| 33 | 32 | } $args] |
| | @@ -42,10 +41,11 @@ |
| 42 | 41 | test_status_list revert-$testid$key $result $expected |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | 44 | set fileExistsTests [list -exists 1 does -notexists 0 should] |
| 46 | 45 | foreach {key expected verb} $fileExistsTests { |
| 46 | + set passed 1 |
| 47 | 47 | foreach path [dict get $args $key] { |
| 48 | 48 | if {[file exists $path] != $expected} { |
| 49 | 49 | set passed 0 |
| 50 | 50 | protOut " Failure: File $verb not exist: $path" |
| 51 | 51 | } |
| | @@ -53,21 +53,34 @@ |
| 53 | 53 | test revert-$testid$key $passed |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | fossil undo |
| 57 | 57 | } |
| 58 | + |
| 59 | +# Test that a 'fossil revert' call is a no-op. |
| 60 | +proc noop-revert-test {testid revertArgs} { |
| 61 | + set changes [fossil changes] |
| 62 | + set undo [fossil undo -n] |
| 63 | + test revert-$testid {[fossil revert {*}$revertArgs] eq ""} |
| 64 | + test revert-$testid-changes {[fossil changes] eq $changes} |
| 65 | + test revert-$testid-undo {[fossil undo -n] eq $undo} |
| 66 | +} |
| 58 | 67 | |
| 59 | 68 | require_no_open_checkout |
| 60 | 69 | test_setup |
| 61 | 70 | |
| 62 | 71 | # Prepare first commit |
| 63 | 72 | # |
| 64 | 73 | write_file f1 "f1" |
| 65 | 74 | write_file f2 "f2" |
| 66 | 75 | write_file f3 "f3" |
| 67 | | -fossil add f1 f2 f3 |
| 68 | | -fossil commit -m "c1" |
| 76 | +write_file f4 "f4" |
| 77 | +fossil add f1 f2 f3 f4 |
| 78 | +fossil commit -m "c1" --tag c1 |
| 79 | + |
| 80 | +write_file f4 "f4.1" |
| 81 | +fossil commit -m "c2" --tag c2 |
| 69 | 82 | |
| 70 | 83 | # Make changes to be reverted |
| 71 | 84 | # |
| 72 | 85 | # Add f0 |
| 73 | 86 | write_file f0 "f0" |
| | @@ -89,11 +102,11 @@ |
| 89 | 102 | REVERT f2 |
| 90 | 103 | REVERT f3 |
| 91 | 104 | DELETE f3n |
| 92 | 105 | } -addremove { |
| 93 | 106 | ADDED f0 |
| 94 | | -} -exists {f0 f1 f2 f3} -notexists f3n |
| 107 | +} -exists {f0 f1 f2 f3 f4} -notexists f3n |
| 95 | 108 | |
| 96 | 109 | # Test with a single filename argument |
| 97 | 110 | # |
| 98 | 111 | revert-test 1-2 f0 { |
| 99 | 112 | UNMANAGE f0 |
| | @@ -101,27 +114,27 @@ |
| 101 | 114 | DELETED f1 |
| 102 | 115 | EDITED f2 |
| 103 | 116 | RENAMED f3n |
| 104 | 117 | } -addremove { |
| 105 | 118 | ADDED f0 |
| 106 | | -} -exists {f0 f2 f3n} -notexists f3 |
| 119 | +} -exists {f0 f2 f3n f4} -notexists {f1 f3} |
| 107 | 120 | |
| 108 | 121 | revert-test 1-3 f1 { |
| 109 | 122 | REVERT f1 |
| 110 | 123 | } -changes { |
| 111 | 124 | ADDED f0 |
| 112 | 125 | EDITED f2 |
| 113 | 126 | RENAMED f3n |
| 114 | | -} -exists {f0 f1 f2 f3n} -notexists f3 |
| 127 | +} -exists {f0 f1 f2 f3n f4} -notexists f3 |
| 115 | 128 | |
| 116 | 129 | revert-test 1-4 f2 { |
| 117 | 130 | REVERT f2 |
| 118 | 131 | } -changes { |
| 119 | 132 | ADDED f0 |
| 120 | 133 | DELETED f1 |
| 121 | 134 | RENAMED f3n |
| 122 | | -} -exists {f0 f2 f3n} -notexists {f1 f3} |
| 135 | +} -exists {f0 f2 f3n f4} -notexists {f1 f3} |
| 123 | 136 | |
| 124 | 137 | # Both files involved in a rename are reverted regardless of which filename |
| 125 | 138 | # is used as an argument to 'fossil revert' |
| 126 | 139 | # |
| 127 | 140 | revert-test 1-5 f3 { |
| | @@ -129,20 +142,20 @@ |
| 129 | 142 | DELETE f3n |
| 130 | 143 | } -changes { |
| 131 | 144 | ADDED f0 |
| 132 | 145 | DELETED f1 |
| 133 | 146 | EDITED f2 |
| 134 | | -} -exists {f0 f2 f3} -notexists {f1 f3n} |
| 147 | +} -exists {f0 f2 f3 f4} -notexists {f1 f3n} |
| 135 | 148 | |
| 136 | 149 | revert-test 1-6 f3n { |
| 137 | 150 | REVERT f3 |
| 138 | 151 | DELETE f3n |
| 139 | 152 | } -changes { |
| 140 | 153 | ADDED f0 |
| 141 | 154 | DELETED f1 |
| 142 | 155 | EDITED f2 |
| 143 | | -} -exists {f0 f2 f3} -notexists {f1 f3n} |
| 156 | +} -exists {f0 f2 f3 f4} -notexists {f1 f3n} |
| 144 | 157 | |
| 145 | 158 | # Test with multiple filename arguments |
| 146 | 159 | # |
| 147 | 160 | revert-test 1-7 {f0 f2 f3n} { |
| 148 | 161 | UNMANAGE f0 |
| | @@ -151,11 +164,59 @@ |
| 151 | 164 | DELETE f3n |
| 152 | 165 | } -changes { |
| 153 | 166 | DELETED f1 |
| 154 | 167 | } -addremove { |
| 155 | 168 | ADDED f0 |
| 156 | | -} -exists {f0 f2 f3} -notexists {f1 f3n} |
| 169 | +} -exists {f0 f2 f3 f4} -notexists {f1 f3n} |
| 170 | + |
| 171 | +# Test with a revision specified |
| 172 | +# |
| 173 | +revert-test 1-8 {-r c1 f4} { |
| 174 | + REVERT f4 |
| 175 | +} -changes { |
| 176 | + ADDED f0 |
| 177 | + DELETED f1 |
| 178 | + EDITED f2 |
| 179 | + RENAMED f3n |
| 180 | + EDITED f4 |
| 181 | +} -exists {f0 f2 f3n f4} -notexists {f1 f3} |
| 182 | + |
| 183 | +# Revision specified, no-op revert |
| 184 | +# |
| 185 | +noop-revert-test 1-9 {-r c2 f4 z1} |
| 186 | + |
| 187 | +# Invalid revision |
| 188 | +# |
| 189 | +fossil revert -r turnk f4 |
| 190 | +test revert-1-10 {$RESULT eq "not found: turnk"} |
| 191 | + |
| 192 | +# Test case-sensitivity |
| 193 | +# |
| 194 | +fossil set case-sensitive 0 |
| 195 | +revert-test 1-11 F3 { |
| 196 | + REVERT f3 |
| 197 | + DELETE f3n |
| 198 | +} -changes { |
| 199 | + ADDED f0 |
| 200 | + DELETED f1 |
| 201 | + EDITED f2 |
| 202 | +} -exists {f0 f2 f3 f4} -notexists {f1 f3n} |
| 203 | + |
| 204 | +fossil set case-sensitive 1 |
| 205 | +noop-revert-test 1-12 {F1 f4} |
| 206 | +fossil unset case-sensitive |
| 207 | + |
| 208 | +# No-op revert, no files or revision specified |
| 209 | +# |
| 210 | +fossil revert |
| 211 | +fossil clean -f |
| 212 | +noop-revert-test 1-13 {} |
| 213 | + |
| 214 | +# Reverting a no-op merge is not a no-op revert |
| 215 | +# |
| 216 | +fossil merge -f c1 |
| 217 | +revert-test 1-14 {} {} |
| 157 | 218 | |
| 158 | 219 | |
| 159 | 220 | # Test reverting the combination of a renamed file and an added file that |
| 160 | 221 | # uses the renamed file's original filename. |
| 161 | 222 | # |
| | @@ -167,14 +228,19 @@ |
| 167 | 228 | write_file f1n "f1n" |
| 168 | 229 | fossil mv f1 f1n |
| 169 | 230 | write_file f1 "f1b" |
| 170 | 231 | fossil add f1 |
| 171 | 232 | |
| 172 | | -revert-test 2-1 {} { |
| 173 | | - REVERT f1 |
| 174 | | - DELETE f1n |
| 175 | | -} -exists {f1} -notexists {f1n} |
| 233 | +foreach {testnum args} {1 {} 2 f1 3 {f1 f1n}} { |
| 234 | + revert-test 2-$testnum $args { |
| 235 | + REVERT f1 |
| 236 | + DELETE f1n |
| 237 | + } -exists {f1} -notexists {f1n} |
| 238 | +} |
| 239 | + |
| 240 | +fossil revert f1n |
| 241 | +test revert-2-2 {$RESULT eq "cannot revert 'f1n' without 'f1'"} |
| 176 | 242 | |
| 177 | 243 | |
| 178 | 244 | # Test reverting a rename in the repo but not completed in the file |
| 179 | 245 | # system |
| 180 | 246 | test_setup |
| | @@ -187,8 +253,33 @@ |
| 187 | 253 | revert-test 3-1 {} { |
| 188 | 254 | REVERT f1 |
| 189 | 255 | DELETE f1new |
| 190 | 256 | } -exists {f1} -notexists {f1n} |
| 191 | 257 | |
| 258 | + |
| 259 | +# Test chained renames |
| 260 | +# |
| 261 | +test_setup |
| 262 | +write_file f1 "f1" |
| 263 | +write_file f2 "f2" |
| 264 | +write_file f3 "f3" |
| 265 | +fossil add f1 f2 f3 |
| 266 | +fossil commit -m "add files" |
| 267 | + |
| 268 | +fossil mv --hard f1 f0 |
| 269 | +fossil mv --hard f2 f1 |
| 270 | +fossil mv --hard f3 f2 |
| 271 | + |
| 272 | +revert-test 4-1 f2 { |
| 273 | + DELETE f1 |
| 274 | + REVERT f2 |
| 275 | + REVERT f3 |
| 276 | +} -changes { |
| 277 | + RENAMED f0 |
| 278 | +} -exists {f0 f2 f3} -notexists {f1} |
| 279 | + |
| 280 | +fossil revert f1 |
| 281 | +test revert-4-2 {$RESULT eq "cannot revert 'f1' without 'f2'"} |
| 282 | + |
| 192 | 283 | ############################################################################### |
| 193 | 284 | |
| 194 | 285 | test_cleanup |
| 195 | 286 | |