Skip to content

Commit 7b759d7

Browse files
Automatically upgrade empty manifest files to v2 format (#4091)
1 parent 69c6de0 commit 7b759d7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/manifest.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ function read_manifest(f_or_io::Union{String, IO})
219219
rethrow()
220220
end
221221
if Base.is_v1_format_manifest(raw)
222-
raw = convert_v1_format_manifest(raw)
222+
if isempty(raw) # treat an empty Manifest file as v2 format for convenience
223+
raw["manifest_format"] = "2.0.0"
224+
else
225+
raw = convert_v1_format_manifest(raw)
226+
end
223227
end
224228
return Manifest(raw, f_or_io)
225229
end

test/manifests.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ end
4444
end
4545
end
4646

47+
@testset "Empty manifest file is automatically upgraded to v2" begin
48+
isolate(loaded_depot=true) do
49+
io = IOBuffer()
50+
d = mktempdir()
51+
manifest = joinpath(d, "Manifest.toml")
52+
touch(manifest)
53+
Pkg.activate(d; io=io)
54+
output = String(take!(io))
55+
@test occursin(r"Activating.*project at.*", output)
56+
env_manifest = Pkg.Types.Context().env.manifest_file
57+
@test samefile(env_manifest, manifest)
58+
# an empty manifest is still technically considered to be v1 manifest
59+
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest))
60+
@test Pkg.Types.Context().env.manifest.manifest_format == v"2.0.0"
61+
62+
Pkg.add("Profile"; io=io)
63+
env_manifest = Pkg.Types.Context().env.manifest_file
64+
@test samefile(env_manifest, manifest)
65+
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest)) == false
66+
@test Pkg.Types.Context().env.manifest.manifest_format == v"2.0.0"
67+
68+
# check that having a Project with deps, and an empty manifest file doesn't error
69+
rm(manifest)
70+
touch(manifest)
71+
Pkg.activate(d; io=io)
72+
Pkg.add("Example"; io=io)
73+
end
74+
end
75+
4776
@testset "v1.0: activate, change, maintain manifest format" begin
4877
reference_manifest_isolated_test("v1.0", v1 = true) do env_dir, env_manifest
4978
io = IOBuffer()

0 commit comments

Comments
 (0)