diff --git a/src/dependencies.jl b/src/dependencies.jl index 599f76e6..4554d2f1 100644 --- a/src/dependencies.jl +++ b/src/dependencies.jl @@ -1,28 +1,19 @@ const LOCAL_REPO_NAME = "REPO" -function get_project_deps( - api::Forge, - ci::CIService, - repo::Union{GitHub.Repo,GitLab.Project}; - options::Options, - subdir::AbstractString, +function get_local_clone( + api::Forge, ci::CIService, repo::Union{GitHub.Repo,GitLab.Project}; options ) - mktempdir() do f - url_with_auth = get_url_with_auth(api, ci, repo) - local_path = joinpath(f, LOCAL_REPO_NAME) - @mock git_clone(url_with_auth, local_path) - - @mock cd(local_path) do - master_branch = @mock git_get_master_branch(options.master_branch) - @mock git_checkout(master_branch) - end - - # Get all the compat dependencies from the local Project.toml file - project_file = @mock joinpath(local_path, subdir, "Project.toml") - deps = get_project_deps(project_file; include_jll=options.include_jll) - - return deps + f = mktempdir() + url_with_auth = get_url_with_auth(api, ci, repo) + local_path = joinpath(f, LOCAL_REPO_NAME) + @mock git_clone(url_with_auth, local_path) + + @mock cd(local_path) do + master_branch = @mock git_get_master_branch(options.master_branch) + @mock git_checkout(master_branch) end + + return local_path end function get_project_deps(project_file::AbstractString; include_jll::Bool=false) diff --git a/src/main.jl b/src/main.jl index 54314dd6..e08a0a6e 100644 --- a/src/main.jl +++ b/src/main.jl @@ -47,8 +47,11 @@ function main( api, repo = get_api_and_repo(ci_cfg) + local_path = get_local_clone(api, ci_cfg, repo; options) + for subdir in options.subdirs - deps = get_project_deps(api, ci_cfg, repo; options, subdir) + project_file = @mock joinpath(local_path, subdir, "Project.toml") + deps = get_project_deps(project_file; include_jll=options.include_jll) if options.use_existing_registries get_existing_registries!(deps, options.depot; options) diff --git a/test/dependencies.jl b/test/dependencies.jl index 3fae1a38..73b160dd 100644 --- a/test/dependencies.jl +++ b/test/dependencies.jl @@ -1,35 +1,23 @@ -@testset "get_project_deps" begin - @testset "no jll" begin - apply([git_clone_patch, project_toml_patch, cd_patch]) do - options = CompatHelper.Options() - subdir = only(options.subdirs) - deps = CompatHelper.get_project_deps( - GitForge.GitHub.GitHubAPI(; token=GitHub.Token("token")), - GitHubActions(), - GitHub.Repo(; full_name="foobar"); - options=options, - subdir=subdir, - ) - - @test length(deps) == 1 - end +@testset "get_local_clone" begin + apply([git_clone_patch, cd_patch]) do + options = CompatHelper.Options() + local_path = CompatHelper.get_local_clone( + GitForge.GitHub.GitHubAPI(; token=GitHub.Token("token")), + GitHubActions(), + GitHub.Repo(; full_name="foobar"); + options, + ) + @test local_path isa String end +end - @testset "include_jll" begin - apply([git_clone_patch, project_toml_patch, cd_patch]) do - options = CompatHelper.Options(; include_jll=true) - subdir = only(options.subdirs) - deps = CompatHelper.get_project_deps( - GitForge.GitHub.GitHubAPI(; token=GitHub.Token("token")), - GitHubActions(), - GitHub.Repo(; full_name="foobar"); - options=options, - subdir=subdir, - ) - - @test length(deps) == 2 - end - end +@testset "get_project_deps" begin + project = joinpath(@__DIR__, "deps", "Project.toml") + + deps = CompatHelper.get_project_deps(project; include_jll=true) + @test length(deps) == 2 + deps = CompatHelper.get_project_deps(project; include_jll=false) + @test length(deps) == 1 end @testset "clone_all_registries" begin diff --git a/test/utilities/git.jl b/test/utilities/git.jl index 2607b59c..100f1167 100644 --- a/test/utilities/git.jl +++ b/test/utilities/git.jl @@ -22,7 +22,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc @testset "git_push" begin function create_local_remote(dir::AbstractString) remote_path = joinpath(dir, "localremote.git") - run(`git init --bare $remote_path`) + run(`git init --initial-branch=master --bare $remote_path`) return remote_path end @@ -35,7 +35,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc local_remote_path = create_local_remote(local_remote_dir) cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`git remote add origin $local_remote_path`) run(`touch foobar.txt`) @@ -60,7 +60,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc local_remote_path = create_local_remote(local_remote_dir) cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`git remote add origin $local_remote_path`) run(`touch foobar.txt`) @@ -104,7 +104,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc local_remote_path = create_local_remote(local_remote_dir) cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`git remote add origin $local_remote_path`) run(`touch foobar.txt`) @@ -127,7 +127,7 @@ end @testset "git_reset" begin mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) @test !isfile("foobar.txt") @@ -163,7 +163,7 @@ end @testset "success" begin mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`touch foobar.txt`) CompatHelper.git_add() @@ -175,7 +175,7 @@ end @testset "failure" begin mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`touch foobar.txt`) CompatHelper.git_add() @@ -194,7 +194,7 @@ end @testset "no checkout" begin mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`touch foobar.txt`) CompatHelper.git_add() CompatHelper.git_commit("Message") @@ -218,7 +218,7 @@ end @testset "with checkout" begin mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`touch foobar.txt`) CompatHelper.git_add() CompatHelper.git_commit("Message") @@ -241,7 +241,7 @@ end mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`touch foo.txt`) run(`touch bar.txt`) @@ -314,7 +314,7 @@ end mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) # Need to create a commit before hand, see below # https://stackoverflow.com/a/63480330/1327636 run(`touch foobar.txt`) @@ -334,7 +334,7 @@ end branch = "master" mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=$(branch)`) run(`touch foobar.txt`) CompatHelper.git_add() CompatHelper.git_commit("Message") @@ -350,7 +350,7 @@ end branch = "main" mktempdir() do f cd(f) do - run(`git init`) + run(`git init --initial-branch=master`) run(`git branch -m $branch`) run(`touch foobar.txt`) CompatHelper.git_add()