Commit 659a41a
authored
feat(extensions): add --force flag to extension add for overwrite reinstall (#2530)
* feat(extensions): add --force flag to extension add for overwrite reinstall
Add --force support to `specify extension add` that allows overwriting
an already-installed extension without manually removing it first.
- install_from_directory() and install_from_zip() accept force=True,
automatically calling remove() before installation
- The --force CLI flag works with all install modes (--dev, --from URL,
bundled, and catalog)
- Config files (*-config.yml) are preserved across force reinstall
- Error message suggests --force when extension is already installed
- 6 new tests covering unit and CLI force reinstall flows
* fix: address PR review feedback on --force implementation
- Remove unused `backup_config_dir` variable assignment (Ruff F841)
- Defer `remove()` until after `_validate_install_conflicts()` to prevent
data loss if validation fails mid-reinstall
- Use `TemporaryDirectory` instead of `NamedTemporaryFile` in ZIP test
to avoid Windows file-locking failures
* fix: only restore config backup when --force actually triggers a remove
When --force is used but the extension is not already installed, the
backup restore/cleanup should not run. Previously it could resurrect
stale config files from a previous removal and delete the backup
directory unnecessarily.
* fix: address Copilot review feedback on --force implementation
- Clear stale backup dir before remove() so only fresh backups are restored
- Restore only config files (*-config.yml, *-config.local.yml) from backup
- Remove trailing \n from --force console message (console.print adds newline)
* fix: handle non-directory paths in backup cleanup/restore
- Use is_dir() before rmtree/iterdir on backup path to avoid crashes
when .backup/<id> exists as a file or symlink
- Remove unused manifest1 variable in test_install_force_reinstall
* fix: handle symlinks in backup cleanup/restore and correct CLI message
- Check is_symlink() before is_dir() in backup cleanup and restore:
Path.is_dir() follows symlinks (returns True for symlink-to-dir) but
shutil.rmtree() raises OSError on symlinks. Handle symlinks by
unlinking them instead.
- Skip symlink entries during config file restore.
- Change --force dev-install message from "Reinstalling" to
"Installing [...] (will overwrite if already installed)" because
--force also works for first-time installs.1 parent df09fd4 commit 659a41a
3 files changed
Lines changed: 232 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1611 | 1611 | | |
1612 | 1612 | | |
1613 | 1613 | | |
| 1614 | + | |
1614 | 1615 | | |
1615 | 1616 | | |
1616 | 1617 | | |
| |||
1625 | 1626 | | |
1626 | 1627 | | |
1627 | 1628 | | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
1628 | 1632 | | |
1629 | 1633 | | |
1630 | 1634 | | |
| |||
1675 | 1679 | | |
1676 | 1680 | | |
1677 | 1681 | | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
1678 | 1685 | | |
1679 | 1686 | | |
1680 | 1687 | | |
1681 | 1688 | | |
1682 | 1689 | | |
| 1690 | + | |
1683 | 1691 | | |
1684 | 1692 | | |
1685 | 1693 | | |
| |||
1701 | 1709 | | |
1702 | 1710 | | |
1703 | 1711 | | |
1704 | | - | |
| 1712 | + | |
1705 | 1713 | | |
1706 | 1714 | | |
1707 | 1715 | | |
| |||
1714 | 1722 | | |
1715 | 1723 | | |
1716 | 1724 | | |
1717 | | - | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
1718 | 1728 | | |
1719 | 1729 | | |
1720 | 1730 | | |
| |||
1735 | 1745 | | |
1736 | 1746 | | |
1737 | 1747 | | |
1738 | | - | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
1739 | 1751 | | |
1740 | 1752 | | |
1741 | 1753 | | |
| |||
1771 | 1783 | | |
1772 | 1784 | | |
1773 | 1785 | | |
1774 | | - | |
| 1786 | + | |
1775 | 1787 | | |
1776 | 1788 | | |
1777 | 1789 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1173 | 1173 | | |
1174 | 1174 | | |
1175 | 1175 | | |
| 1176 | + | |
1176 | 1177 | | |
1177 | 1178 | | |
1178 | 1179 | | |
| |||
1183 | 1184 | | |
1184 | 1185 | | |
1185 | 1186 | | |
| 1187 | + | |
| 1188 | + | |
1186 | 1189 | | |
1187 | 1190 | | |
1188 | 1191 | | |
| |||
1204 | 1207 | | |
1205 | 1208 | | |
1206 | 1209 | | |
1207 | | - | |
1208 | | - | |
1209 | | - | |
1210 | | - | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
1211 | 1216 | | |
1212 | 1217 | | |
1213 | 1218 | | |
1214 | 1219 | | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
1215 | 1238 | | |
1216 | 1239 | | |
1217 | 1240 | | |
| |||
1239 | 1262 | | |
1240 | 1263 | | |
1241 | 1264 | | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
1242 | 1285 | | |
1243 | 1286 | | |
1244 | 1287 | | |
| |||
1257 | 1300 | | |
1258 | 1301 | | |
1259 | 1302 | | |
| 1303 | + | |
1260 | 1304 | | |
1261 | 1305 | | |
1262 | 1306 | | |
1263 | 1307 | | |
1264 | 1308 | | |
1265 | 1309 | | |
1266 | 1310 | | |
| 1311 | + | |
| 1312 | + | |
1267 | 1313 | | |
1268 | 1314 | | |
1269 | 1315 | | |
| |||
1310 | 1356 | | |
1311 | 1357 | | |
1312 | 1358 | | |
1313 | | - | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
1314 | 1362 | | |
1315 | 1363 | | |
1316 | 1364 | | |
| |||
2742 | 2790 | | |
2743 | 2791 | | |
2744 | 2792 | | |
2745 | | - | |
| 2793 | + | |
2746 | 2794 | | |
2747 | 2795 | | |
2748 | 2796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
796 | 892 | | |
797 | 893 | | |
798 | 894 | | |
| |||
5114 | 5210 | | |
5115 | 5211 | | |
5116 | 5212 | | |
| 5213 | + | |
| 5214 | + | |
| 5215 | + | |
| 5216 | + | |
| 5217 | + | |
| 5218 | + | |
| 5219 | + | |
| 5220 | + | |
| 5221 | + | |
| 5222 | + | |
| 5223 | + | |
| 5224 | + | |
| 5225 | + | |
| 5226 | + | |
| 5227 | + | |
| 5228 | + | |
| 5229 | + | |
| 5230 | + | |
| 5231 | + | |
| 5232 | + | |
| 5233 | + | |
| 5234 | + | |
| 5235 | + | |
| 5236 | + | |
| 5237 | + | |
| 5238 | + | |
| 5239 | + | |
| 5240 | + | |
| 5241 | + | |
| 5242 | + | |
| 5243 | + | |
| 5244 | + | |
| 5245 | + | |
| 5246 | + | |
| 5247 | + | |
| 5248 | + | |
| 5249 | + | |
| 5250 | + | |
| 5251 | + | |
| 5252 | + | |
| 5253 | + | |
| 5254 | + | |
| 5255 | + | |
| 5256 | + | |
| 5257 | + | |
| 5258 | + | |
| 5259 | + | |
| 5260 | + | |
| 5261 | + | |
| 5262 | + | |
| 5263 | + | |
| 5264 | + | |
| 5265 | + | |
| 5266 | + | |
| 5267 | + | |
| 5268 | + | |
| 5269 | + | |
| 5270 | + | |
| 5271 | + | |
| 5272 | + | |
| 5273 | + | |
| 5274 | + | |
| 5275 | + | |
| 5276 | + | |
| 5277 | + | |
| 5278 | + | |
0 commit comments