Fossil SCM
Retain renames in local checkout when running fossil update.
Commit
7c284a8c62fba14da686d363856a903d0178b4026c77388cd237f133292f9c53
Parent
e5bcfd1efe9b638…
2 files changed
+17
-2
+19
-2
+17
-2
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -272,15 +272,17 @@ | ||
| 272 | 272 | " fnt TEXT %s" /* Filename of same file on target version */ |
| 273 | 273 | ");", |
| 274 | 274 | filename_collation(), filename_collation() |
| 275 | 275 | ); |
| 276 | 276 | |
| 277 | - /* Add files found in the current version | |
| 277 | + /* Add files found in the current version. If a file is renamed locally, | |
| 278 | + ** use origname to compare with the original pathname in the target. | |
| 278 | 279 | */ |
| 279 | 280 | db_multi_exec( |
| 280 | 281 | "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)" |
| 281 | - " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged, deleted" | |
| 282 | + " SELECT pathname, COALESCE(origname,pathname), id, 0, rid, 0," | |
| 283 | + " isexe, chnged, deleted" | |
| 282 | 284 | " FROM vfile WHERE vid=%d", |
| 283 | 285 | vid |
| 284 | 286 | ); |
| 285 | 287 | |
| 286 | 288 | /* Compute file name changes on V->T. Record name changes in files that |
| @@ -628,10 +630,23 @@ | ||
| 628 | 630 | "SELECT rmdir(%Q||name) FROM dir_to_delete" |
| 629 | 631 | " WHERE (%Q||name)<>%Q ORDER BY name DESC", |
| 630 | 632 | g.zLocalRoot, g.zLocalRoot, zPwd |
| 631 | 633 | ); |
| 632 | 634 | fossil_free(zPwd); |
| 635 | + /* Before deleting the old vid, transfer renames from the current vid. */ | |
| 636 | + db_multi_exec( | |
| 637 | + "WITH mv AS (" | |
| 638 | + " SELECT pathname AS path, origname AS orig" | |
| 639 | + " FROM vfile" | |
| 640 | + " WHERE vid=%i AND origname IS NOT NULL AND pathname!=origname" | |
| 641 | + ")" | |
| 642 | + " UPDATE vfile" | |
| 643 | + " SET pathname=path, origname=orig" | |
| 644 | + " FROM mv" | |
| 645 | + " WHERE vid=%i AND pathname=orig", | |
| 646 | + vid, tid | |
| 647 | + ); | |
| 633 | 648 | if( g.argc<=3 ){ |
| 634 | 649 | /* All files updated. Shift the current check-out to the target. */ |
| 635 | 650 | db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); |
| 636 | 651 | checkout_set_all_exe(tid); |
| 637 | 652 | manifest_to_disk(tid); |
| 638 | 653 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -272,15 +272,17 @@ | |
| 272 | " fnt TEXT %s" /* Filename of same file on target version */ |
| 273 | ");", |
| 274 | filename_collation(), filename_collation() |
| 275 | ); |
| 276 | |
| 277 | /* Add files found in the current version |
| 278 | */ |
| 279 | db_multi_exec( |
| 280 | "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)" |
| 281 | " SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged, deleted" |
| 282 | " FROM vfile WHERE vid=%d", |
| 283 | vid |
| 284 | ); |
| 285 | |
| 286 | /* Compute file name changes on V->T. Record name changes in files that |
| @@ -628,10 +630,23 @@ | |
| 628 | "SELECT rmdir(%Q||name) FROM dir_to_delete" |
| 629 | " WHERE (%Q||name)<>%Q ORDER BY name DESC", |
| 630 | g.zLocalRoot, g.zLocalRoot, zPwd |
| 631 | ); |
| 632 | fossil_free(zPwd); |
| 633 | if( g.argc<=3 ){ |
| 634 | /* All files updated. Shift the current check-out to the target. */ |
| 635 | db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); |
| 636 | checkout_set_all_exe(tid); |
| 637 | manifest_to_disk(tid); |
| 638 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -272,15 +272,17 @@ | |
| 272 | " fnt TEXT %s" /* Filename of same file on target version */ |
| 273 | ");", |
| 274 | filename_collation(), filename_collation() |
| 275 | ); |
| 276 | |
| 277 | /* Add files found in the current version. If a file is renamed locally, |
| 278 | ** use origname to compare with the original pathname in the target. |
| 279 | */ |
| 280 | db_multi_exec( |
| 281 | "INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)" |
| 282 | " SELECT pathname, COALESCE(origname,pathname), id, 0, rid, 0," |
| 283 | " isexe, chnged, deleted" |
| 284 | " FROM vfile WHERE vid=%d", |
| 285 | vid |
| 286 | ); |
| 287 | |
| 288 | /* Compute file name changes on V->T. Record name changes in files that |
| @@ -628,10 +630,23 @@ | |
| 630 | "SELECT rmdir(%Q||name) FROM dir_to_delete" |
| 631 | " WHERE (%Q||name)<>%Q ORDER BY name DESC", |
| 632 | g.zLocalRoot, g.zLocalRoot, zPwd |
| 633 | ); |
| 634 | fossil_free(zPwd); |
| 635 | /* Before deleting the old vid, transfer renames from the current vid. */ |
| 636 | db_multi_exec( |
| 637 | "WITH mv AS (" |
| 638 | " SELECT pathname AS path, origname AS orig" |
| 639 | " FROM vfile" |
| 640 | " WHERE vid=%i AND origname IS NOT NULL AND pathname!=origname" |
| 641 | ")" |
| 642 | " UPDATE vfile" |
| 643 | " SET pathname=path, origname=orig" |
| 644 | " FROM mv" |
| 645 | " WHERE vid=%i AND pathname=orig", |
| 646 | vid, tid |
| 647 | ); |
| 648 | if( g.argc<=3 ){ |
| 649 | /* All files updated. Shift the current check-out to the target. */ |
| 650 | db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); |
| 651 | checkout_set_all_exe(tid); |
| 652 | manifest_to_disk(tid); |
| 653 |
+19
-2
| --- test/update.test | ||
| +++ test/update.test | ||
| @@ -24,10 +24,11 @@ | ||
| 24 | 24 | |
| 25 | 25 | proc test_update_setup {desc} { |
| 26 | 26 | global UPDATE_TEST |
| 27 | 27 | incr UPDATE_TEST |
| 28 | 28 | fossil revert |
| 29 | + fossil clean | |
| 29 | 30 | fossil update |
| 30 | 31 | return [format "test-%02u-%s.txt" $UPDATE_TEST $desc] |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | 34 | # The output is in file name order, so massage $RESULT to remove initial UNCHANGED |
| @@ -38,11 +39,11 @@ | ||
| 38 | 39 | regsub {^(?:UNCHANGED [-a-z0-9.]+\n)*} $test_result {} test_result |
| 39 | 40 | } else { |
| 40 | 41 | set test_result $::RESULT |
| 41 | 42 | } |
| 42 | 43 | test "update-message-$testname" {$message == $test_result} |
| 43 | - fossil changes | |
| 44 | + fossil changes --differ | |
| 44 | 45 | test "update-changes-$testname" {$changes == $::RESULT} |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | # Use a sequence number for file content that is not important for the test. |
| 48 | 49 | set UPDATE_SEQ_NO 0 |
| @@ -88,11 +89,11 @@ | ||
| 88 | 89 | test_update $testname $message $changes -expectError |
| 89 | 90 | |
| 90 | 91 | set testname "add-overwrites" |
| 91 | 92 | set fname [test_update_setup $testname] |
| 92 | 93 | set message "ADD $fname - overwrites an unmanaged file, original copy backed up locally" |
| 93 | -set changes "" | |
| 94 | +set changes "EXTRA $fname-original" | |
| 94 | 95 | write_seq_to_file $fname |
| 95 | 96 | fossil add $fname |
| 96 | 97 | fossil commit -m "Add $fname" |
| 97 | 98 | fossil up previous |
| 98 | 99 | write_seq_to_file $fname |
| @@ -182,10 +183,26 @@ | ||
| 182 | 183 | fossil mv --hard $fname "$fname.renamed" |
| 183 | 184 | fossil commit -m "Update and rename $fname" |
| 184 | 185 | fossil up previous |
| 185 | 186 | write_file $fname "center\nbelow\n" |
| 186 | 187 | test_update $testname $message $changes |
| 188 | + | |
| 189 | +# Rename in current checkout with extra files in target. | |
| 190 | +# Based on https://fossil-scm.org/forum/forumpost/2753239f00 | |
| 191 | +set testname "merge-renamed-current" | |
| 192 | +set fname [test_update_setup $testname] | |
| 193 | +set warning "UPDATE $fname.extra\nUNCHANGED $fname.renamed" | |
| 194 | +set changes "RENAMED $fname -> $fname.renamed" | |
| 195 | +write_seq_to_file $fname | |
| 196 | +write_seq_to_file "$fname.extra" | |
| 197 | +fossil add $fname "$fname.extra" | |
| 198 | +fossil commit -m "Add $fname and $fname.extra" | |
| 199 | +write_seq_to_file "$fname.extra" | |
| 200 | +fossil commit -m "Update $fname.extra" | |
| 201 | +fossil up previous | |
| 202 | +fossil mv --hard $fname "$fname.renamed" | |
| 203 | +test_update $testname $warning $changes | |
| 187 | 204 | |
| 188 | 205 | set testname "merge-standard" |
| 189 | 206 | set fname [test_update_setup $testname] |
| 190 | 207 | set message "MERGE $fname" |
| 191 | 208 | set changes "EDITED $fname" |
| 192 | 209 |
| --- test/update.test | |
| +++ test/update.test | |
| @@ -24,10 +24,11 @@ | |
| 24 | |
| 25 | proc test_update_setup {desc} { |
| 26 | global UPDATE_TEST |
| 27 | incr UPDATE_TEST |
| 28 | fossil revert |
| 29 | fossil update |
| 30 | return [format "test-%02u-%s.txt" $UPDATE_TEST $desc] |
| 31 | } |
| 32 | |
| 33 | # The output is in file name order, so massage $RESULT to remove initial UNCHANGED |
| @@ -38,11 +39,11 @@ | |
| 38 | regsub {^(?:UNCHANGED [-a-z0-9.]+\n)*} $test_result {} test_result |
| 39 | } else { |
| 40 | set test_result $::RESULT |
| 41 | } |
| 42 | test "update-message-$testname" {$message == $test_result} |
| 43 | fossil changes |
| 44 | test "update-changes-$testname" {$changes == $::RESULT} |
| 45 | } |
| 46 | |
| 47 | # Use a sequence number for file content that is not important for the test. |
| 48 | set UPDATE_SEQ_NO 0 |
| @@ -88,11 +89,11 @@ | |
| 88 | test_update $testname $message $changes -expectError |
| 89 | |
| 90 | set testname "add-overwrites" |
| 91 | set fname [test_update_setup $testname] |
| 92 | set message "ADD $fname - overwrites an unmanaged file, original copy backed up locally" |
| 93 | set changes "" |
| 94 | write_seq_to_file $fname |
| 95 | fossil add $fname |
| 96 | fossil commit -m "Add $fname" |
| 97 | fossil up previous |
| 98 | write_seq_to_file $fname |
| @@ -182,10 +183,26 @@ | |
| 182 | fossil mv --hard $fname "$fname.renamed" |
| 183 | fossil commit -m "Update and rename $fname" |
| 184 | fossil up previous |
| 185 | write_file $fname "center\nbelow\n" |
| 186 | test_update $testname $message $changes |
| 187 | |
| 188 | set testname "merge-standard" |
| 189 | set fname [test_update_setup $testname] |
| 190 | set message "MERGE $fname" |
| 191 | set changes "EDITED $fname" |
| 192 |
| --- test/update.test | |
| +++ test/update.test | |
| @@ -24,10 +24,11 @@ | |
| 24 | |
| 25 | proc test_update_setup {desc} { |
| 26 | global UPDATE_TEST |
| 27 | incr UPDATE_TEST |
| 28 | fossil revert |
| 29 | fossil clean |
| 30 | fossil update |
| 31 | return [format "test-%02u-%s.txt" $UPDATE_TEST $desc] |
| 32 | } |
| 33 | |
| 34 | # The output is in file name order, so massage $RESULT to remove initial UNCHANGED |
| @@ -38,11 +39,11 @@ | |
| 39 | regsub {^(?:UNCHANGED [-a-z0-9.]+\n)*} $test_result {} test_result |
| 40 | } else { |
| 41 | set test_result $::RESULT |
| 42 | } |
| 43 | test "update-message-$testname" {$message == $test_result} |
| 44 | fossil changes --differ |
| 45 | test "update-changes-$testname" {$changes == $::RESULT} |
| 46 | } |
| 47 | |
| 48 | # Use a sequence number for file content that is not important for the test. |
| 49 | set UPDATE_SEQ_NO 0 |
| @@ -88,11 +89,11 @@ | |
| 89 | test_update $testname $message $changes -expectError |
| 90 | |
| 91 | set testname "add-overwrites" |
| 92 | set fname [test_update_setup $testname] |
| 93 | set message "ADD $fname - overwrites an unmanaged file, original copy backed up locally" |
| 94 | set changes "EXTRA $fname-original" |
| 95 | write_seq_to_file $fname |
| 96 | fossil add $fname |
| 97 | fossil commit -m "Add $fname" |
| 98 | fossil up previous |
| 99 | write_seq_to_file $fname |
| @@ -182,10 +183,26 @@ | |
| 183 | fossil mv --hard $fname "$fname.renamed" |
| 184 | fossil commit -m "Update and rename $fname" |
| 185 | fossil up previous |
| 186 | write_file $fname "center\nbelow\n" |
| 187 | test_update $testname $message $changes |
| 188 | |
| 189 | # Rename in current checkout with extra files in target. |
| 190 | # Based on https://fossil-scm.org/forum/forumpost/2753239f00 |
| 191 | set testname "merge-renamed-current" |
| 192 | set fname [test_update_setup $testname] |
| 193 | set warning "UPDATE $fname.extra\nUNCHANGED $fname.renamed" |
| 194 | set changes "RENAMED $fname -> $fname.renamed" |
| 195 | write_seq_to_file $fname |
| 196 | write_seq_to_file "$fname.extra" |
| 197 | fossil add $fname "$fname.extra" |
| 198 | fossil commit -m "Add $fname and $fname.extra" |
| 199 | write_seq_to_file "$fname.extra" |
| 200 | fossil commit -m "Update $fname.extra" |
| 201 | fossil up previous |
| 202 | fossil mv --hard $fname "$fname.renamed" |
| 203 | test_update $testname $warning $changes |
| 204 | |
| 205 | set testname "merge-standard" |
| 206 | set fname [test_update_setup $testname] |
| 207 | set message "MERGE $fname" |
| 208 | set changes "EDITED $fname" |
| 209 |