Skip to content

Commit f7e24a4

Browse files
authored
Add a method for registration_branch(pkg::String; url::AbstractString) (#89)
* Add a method for `registration_branch(pkg::Project; url::AbstractString)` * Loosen a constructor's type signature from `String` to `AbstractString` * Bump the patch version number * Add test coverage for `register()` where `pkg::String` * Fix a typo in a test * Gitignore the `/Manifest.toml` file * If a test has error metadata, print that metadata to the log * Fix a test
1 parent 0b08dcc commit f7e24a4

File tree

5 files changed

+47
-35
lines changed

5 files changed

+47
-35
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ docs/Manifest.toml
1414
test/jl_*
1515
test/jl_*/
1616
test/registries/
17+
18+
Manifest.toml

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RegistryTools"
22
uuid = "d1eb7eb1-105f-429d-abf5-b0f65cb9e2c4"
33
authors = ["Stefan Karpinski <stefan@karpinski.org>"]
4-
version = "2.2.0"
4+
version = "2.2.1"
55

66
[deps]
77
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"

src/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Project
3838
extras::Dict{String, String}
3939
end
4040

41-
Project(project_file::String) = Project(isfile(project_file) ? TOML.parsefile(project_file) : Dict())
41+
Project(project_file::AbstractString) = Project(isfile(project_file) ? TOML.parsefile(project_file) : Dict())
4242
function Project(d::Dict)
4343
name = get(d, "name", nothing)
4444
uuid = get(d, "uuid", nothing)

src/utils.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function gitcmd(path::AbstractString, gitconfig::Dict)
1212
end
1313

1414
"""
15+
registration_branch(pkg::AbstractString; url::AbstractString) -> String
1516
registration_branch(pkg::RegistryTools.Project; url::AbstractString) -> String
1617
1718
Generate the name for the registry branch used to register the package version.
@@ -21,3 +22,7 @@ function registration_branch(pkg::Project; url::AbstractString)
2122
url_hash_trunc = url_hash[1:10]
2223
return "registrator-$(lowercase(pkg.name))-$(string(pkg.uuid)[1:8])-v$(pkg.version)-$(url_hash_trunc)"
2324
end
25+
function registration_branch(project_file::AbstractString; url::AbstractString)
26+
proj = Project(project_file)
27+
return registration_branch(proj; url = url)
28+
end

test/regedit.jl

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -622,41 +622,46 @@ end
622622
# version of one of the packages with a dependency to the other
623623
# package. The registration is pushed to a new branch via a file URL.
624624
@testset "register" begin
625-
mktempdir(@__DIR__) do temp_dir
626-
registry1_path = joinpath(temp_dir, "Registry1")
627-
status = create_and_populate_registry(registry1_path, "Registry1",
628-
"7e1d4fce-5fe6-405e-8bac-078d4138e9a2",
629-
"Example1")
630-
@test !haserror(status)
631-
632-
registry2_path = joinpath(@__DIR__, temp_dir, "Registry2")
633-
status = create_and_populate_registry(registry2_path, "Registry2",
634-
"a5a8be26-c942-4674-beee-533a0e81ac1d",
635-
"Dep1")
636-
@test !haserror(status)
625+
for pkg_f in [identity, Project]
626+
mktempdir(@__DIR__) do temp_dir
627+
registry1_path = joinpath(temp_dir, "Registry1")
628+
status = create_and_populate_registry(registry1_path, "Registry1",
629+
"7e1d4fce-5fe6-405e-8bac-078d4138e9a2",
630+
"Example1")
631+
@test !haserror(status)
632+
633+
registry2_path = joinpath(@__DIR__, temp_dir, "Registry2")
634+
status = create_and_populate_registry(registry2_path, "Registry2",
635+
"a5a8be26-c942-4674-beee-533a0e81ac1d",
636+
"Dep1")
637+
@test !haserror(status)
638+
639+
projects_path = joinpath(@__DIR__, "project_files")
640+
project_file = joinpath(projects_path, "Example18.toml")
641+
pkg = pkg_f(project_file)
642+
package_repo = "http://example.com/Example.git"
643+
tree_hash = repeat("0", 40)
644+
registry_repo = "file://$(registry1_path)"
645+
deps_repo = "file://$(registry2_path)"
646+
regbr = register(package_repo, pkg, tree_hash, registry = registry_repo,
647+
registry_deps = [deps_repo], push = true,
648+
gitconfig = TEST_GITCONFIG)
649+
if haskey(regbr.metadata, "error") || haskey(regbr.metadata, "warning")
650+
@info "" get(regbr.metadata, "error", nothing) get(regbr.metadata, "warning", nothing)
651+
end
652+
@test !haskey(regbr.metadata, "error") && !haskey(regbr.metadata, "warning")
653+
git = gitcmd(registry1_path, TEST_GITCONFIG)
654+
branches = readlines(`$git branch`)
655+
@test length(branches) == 2
656+
end
637657

638-
projects_path = joinpath(@__DIR__, "project_files")
639-
project_file = joinpath(projects_path, "Example18.toml")
640-
pkg = Project(project_file)
641-
package_repo = "http://example.com/$(pkg.name).git"
642-
tree_hash = repeat("0", 40)
643-
registry_repo = "file://$(registry1_path)"
644-
deps_repo = "file://$(registry2_path)"
645-
regbr = register(package_repo, pkg, tree_hash, registry = registry_repo,
646-
registry_deps = [deps_repo], push = true,
647-
gitconfig = TEST_GITCONFIG)
648-
@test !haskey(regbr.metadata, "error") && !haskey(regbr.metadata, "warning")
649-
git = gitcmd(registry1_path, TEST_GITCONFIG)
650-
branches = readlines(`$git branch`)
651-
@test length(branches) == 2
658+
# Clean up the registry cache created by `register`.
659+
rm(joinpath(@__DIR__, "registries", "7e1d4fce-5fe6-405e-8bac-078d4138e9a2"),
660+
recursive = true)
661+
rm(joinpath(@__DIR__, "registries", "a5a8be26-c942-4674-beee-533a0e81ac1d"),
662+
recursive = true)
663+
rm(joinpath(@__DIR__, "registries"))
652664
end
653-
654-
# Clean up the registry cache created by `register`.
655-
rm(joinpath(@__DIR__, "registries", "7e1d4fce-5fe6-405e-8bac-078d4138e9a2"),
656-
recursive = true)
657-
rm(joinpath(@__DIR__, "registries", "a5a8be26-c942-4674-beee-533a0e81ac1d"),
658-
recursive = true)
659-
rm(joinpath(@__DIR__, "registries"))
660665
end
661666

662667
@testset "find_registered_version" begin

0 commit comments

Comments
 (0)