-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an apply function and change generate
BestieTemplate.generate only works for new folders now. BestieTemplate.apply was created to handle existing folders. Closes #301 Breaking change: generate stops working for existing packages and apply should be used instead.
- Loading branch information
1 parent
56ef2bb
commit f6c48c1
Showing
8 changed files
with
201 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,10 +114,11 @@ To apply the template to an existing package, you can do the following: | |
|
||
!!! warning "git" | ||
This assumes that you already use git on that package and the your working directory is clean. | ||
It will fail otherwise. | ||
|
||
```julia-repl | ||
julia> using BestieTemplate | ||
julia> BestieTemplate.generate("full/path/to/YourPackage.jl") | ||
julia> BestieTemplate.apply("full/path/to/YourPackage.jl") | ||
``` | ||
|
||
This will look for a file `Project.toml` at the root of the given path and use the information there to guess some of the answers. | ||
|
@@ -126,14 +127,14 @@ Currently, we guess the `PackageName`, `PackageUUID` from the `name` and `uuid` | |
!!! tip "Overwrite" | ||
You will be asked whether to overwrite existing files or not. Since you are using `git`, you can try it out and reset if you don't like the result. | ||
|
||
If you don't like the result, or want to override the answers, you can run the `generate` function with additional arguments: | ||
If you don't like the result, or want to override the answers, you can run the `apply` function with additional arguments: | ||
|
||
```julia-repl | ||
julia> data = Dict("AuthorName" => "Bob", "AuthorEmail" => "[email protected]") | ||
julia> BestieTemplate.generate("full/path/to/YourPackage.jl", data) | ||
julia> BestieTemplate.apply("full/path/to/YourPackage.jl", data) | ||
``` | ||
|
||
See the full docstring for [`BestieTemplate.generate`](@ref) for more information. | ||
See the full docstring for [`BestieTemplate.apply`](@ref) for more information. | ||
|
||
You will most likely have conflicts when you apply the template. | ||
Whenever a conflict appears, you will need to decide on whether to accept or reject the new changes. | ||
|
@@ -268,7 +269,7 @@ The next time that the tests are run, the coverage page will be updated, and the | |
|
||
!!! warning "Copier.yml is work in progress" | ||
This option is not selected by default because it is a work in progress. | ||
If you want to use it, you have to pass the key `"AddCopierCI" => true` to the `data` argument of `generate`, or select "Ask me" when deciding how to answer the optional questions. | ||
If you want to use it, you have to pass the key `"AddCopierCI" => true` to the `data` argument of `generate` or `apply`, or select "Ask me" when deciding how to answer the optional questions. | ||
|
||
You can reapply the template in the future. This is normally a manual job, specially because normally there are conflicts. | ||
That being said, we are experimenting with having a workflow that automatically checks whether there are updates to the template and reapplies it. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,14 @@ template_options = Dict( | |
"AddCopierCI" => false, | ||
) | ||
|
||
function _git_setup() | ||
run(`git init`) | ||
run(`git add .`) | ||
run(`git config user.name "Test"`) | ||
run(`git config user.email "[email protected]"`) | ||
run(`git commit -q -m "First commit"`) | ||
end | ||
|
||
function test_diff_dir(dir1, dir2) | ||
ignore(line) = startswith("_commit")(line) || startswith("_src_path")(line) | ||
@testset "$(basename(dir1)) vs $(basename(dir2))" begin | ||
|
@@ -115,22 +123,14 @@ end | |
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli | ||
run(`copier copy --defaults --quiet $min_bash_args $template_url $dir_copier_cli`) | ||
cd(dir_copier_cli) do | ||
run(`git init`) | ||
run(`git add .`) | ||
run(`git config user.name "Test"`) | ||
run(`git config user.email "[email protected]"`) | ||
run(`git commit -q -m "First commit"`) | ||
_git_setup() | ||
end | ||
run(`copier update --defaults --quiet $bash_args $dir_copier_cli`) | ||
|
||
mktempdir(TMPDIR; prefix = "update_") do tmpdir | ||
BestieTemplate.generate(tmpdir, template_minimum_options; defaults = true, quiet = true) | ||
cd(tmpdir) do | ||
run(`git init`) | ||
run(`git add .`) | ||
run(`git config user.name "Test"`) | ||
run(`git config user.email "[email protected]"`) | ||
run(`git commit -q -m "First commit"`) | ||
_git_setup() | ||
BestieTemplate.update(template_options; defaults = true, quiet = true) | ||
end | ||
|
||
|
@@ -142,8 +142,51 @@ end | |
@testset "Test that BestieTemplate.generate warns and exits for existing copy" begin | ||
mktempdir(TMPDIR; prefix = "cli_") do dir_copier_cli | ||
run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_url $dir_copier_cli`) | ||
cd(dir_copier_cli) do | ||
_git_setup() | ||
end | ||
|
||
@test_logs (:warn,) BestieTemplate.generate(dir_copier_cli; quiet = true) | ||
@test_logs (:warn,) BestieTemplate.apply(dir_copier_cli; quiet = true) | ||
end | ||
end | ||
|
||
@testset "Test that generate fails for existing non-empty paths" begin | ||
mktempdir(TMPDIR) do dir | ||
cd(dir) do | ||
@testset "It fails if the dst_path exists and is non-empty" begin | ||
mkdir("some_folder1") | ||
open(joinpath("some_folder1", "README.md"), "w") do io | ||
println(io, "Hi") | ||
end | ||
@test_throws Exception BestieTemplate.generate("some_folder1") | ||
end | ||
|
||
@testset "It works if the dst_path is ." begin | ||
mkdir("some_folder2") | ||
cd("some_folder2") do | ||
# Should not throw | ||
BestieTemplate.generate( | ||
template_path, | ||
".", | ||
template_options; | ||
quiet = true, | ||
vcs_ref = "HEAD", | ||
) | ||
end | ||
end | ||
|
||
@testset "It works if the dst_path exists but is empty" begin | ||
mkdir("some_folder3") | ||
# Should not throw | ||
BestieTemplate.generate( | ||
template_path, | ||
"some_folder3", | ||
template_options; | ||
quiet = true, | ||
vcs_ref = "HEAD", | ||
) | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
@@ -195,11 +238,14 @@ end | |
end | ||
end | ||
|
||
@testset "Test generating the template on an existing project" begin | ||
@testset "Test applying the template on an existing project" begin | ||
mktempdir(TMPDIR; prefix = "existing_") do dir_existing | ||
cd(dir_existing) do | ||
Pkg.generate("NewPkg") | ||
BestieTemplate.generate( | ||
cd("NewPkg") do | ||
_git_setup() | ||
end | ||
BestieTemplate.apply( | ||
template_path, | ||
"NewPkg/", | ||
Dict("AuthorName" => "T. Esther", "PackageOwner" => "test"); | ||
|
@@ -241,4 +287,19 @@ end | |
end | ||
end | ||
end | ||
|
||
@testset "Test input validation of apply" begin | ||
mktempdir(TMPDIR) do dir | ||
cd(dir) do | ||
@testset "It fails if the dst_path does not exist" begin | ||
@test_throws Exception BestieTemplate.apply("some_folder1") | ||
end | ||
|
||
@testset "It fails if the dst_path exists but does not contains .git" begin | ||
mkdir("some_folder2") | ||
@test_throws Exception BestieTemplate.apply("some_folder2") | ||
end | ||
end | ||
end | ||
end | ||
end |