jimporter / mike

Manage multiple versions of your MkDocs-powered documentation via Git
BSD 3-Clause "New" or "Revised" License
534 stars 47 forks source link

Use deploy prefix when deleting previous versions during deployment #227

Closed PigeonF closed 1 month ago

PigeonF commented 1 month ago

Currently, when using one deployment with a prefix and one without, the deployment including the prefix will delete versions of the same name in the deployment without a prefix.

The fix is to use the deploy prefix when deleting the previous version and aliases.

Before

$ mike deploy --deploy-prefix prefix 1.0.0
$ mike deploy 1.0.0
$ git ls-tree -d -r --name-only gh-pages
1.0.0
1.0.0/css
1.0.0/img
1.0.0/js
1.0.0/search
1.0.0/webfonts
prefix
prefix/1.0.0
prefix/1.0.0/css
prefix/1.0.0/img
prefix/1.0.0/js
prefix/1.0.0/search
prefix/1.0.0/webfonts
$ : Command below mistakenly deletes the top level 1.0.0/ directory
$ mike deploy --deploy-prefix prefix 1.0.0
$ git ls-tree -d -r --name-only gh-pages
prefix
prefix/1.0.0
prefix/1.0.0/css
prefix/1.0.0/img
prefix/1.0.0/js
prefix/1.0.0/search
prefix/1.0.0/webfonts

After

$ mike deploy --deploy-prefix prefix 1.0.0
$ mike deploy 1.0.0
$ git ls-tree -d -r --name-only gh-pages
1.0.0
1.0.0/css
1.0.0/img
1.0.0/js
1.0.0/search
1.0.0/webfonts
prefix
prefix/1.0.0
prefix/1.0.0/css
prefix/1.0.0/img
prefix/1.0.0/js
prefix/1.0.0/search
prefix/1.0.0/webfonts
$ mike deploy --deploy-prefix prefix 1.0.0
$ git ls-tree -d -r --name-only gh-pages
1.0.0
1.0.0/css
1.0.0/img
1.0.0/js
1.0.0/search
1.0.0/webfonts
prefix
prefix/1.0.0
prefix/1.0.0/css
prefix/1.0.0/img
prefix/1.0.0/js
prefix/1.0.0/search
prefix/1.0.0/webfonts
jimporter commented 1 month ago

Thanks for catching this. I've merged this as dd9826a.

I moved the test from the integration tests into the unit tests, since the latter is about 10x faster. (I also added some similar test cases for the other subcommands.) I had to drop the first commit with the --initial-branch flag though, since older versions of Git don't recognize that option; it'd probably be good to do something along these lines so the tests work everywhere, but that's not strictly necessary since the CI doesn't need it.