Skip to content

Commit

Permalink
Wrap reading of project status in HEAD in try-catch, fixes #1180.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 21, 2019
1 parent a6c05b5 commit eae6598
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Display.jl
Expand Up @@ -64,13 +64,17 @@ function status(ctx::Context, pkgs::Vector{PackageSpec}=PackageSpec[];
println(pkg.name, " v", pkg.version)
end
end
if env.git != nothing
LibGit2.with(LibGit2.GitRepo(env.git)) do repo
git_path = LibGit2.path(repo)
project_path = relpath(env.project_file, git_path)
manifest_path = relpath(env.manifest_file, git_path)
project₀ = read_project(git_file_stream(repo, "HEAD:$project_path", fakeit=true))
manifest₀ = read_manifest(git_file_stream(repo, "HEAD:$manifest_path", fakeit=true))
if env.git !== nothing
try
LibGit2.with(LibGit2.GitRepo(env.git)) do repo
git_path = LibGit2.path(repo)
project_path = relpath(env.project_file, git_path)
manifest_path = relpath(env.manifest_file, git_path)
project₀ = read_project(git_file_stream(repo, "HEAD:$project_path", fakeit=true))
manifest₀ = read_manifest(git_file_stream(repo, "HEAD:$manifest_path", fakeit=true))
end
catch
@warn "Could not read project from HEAD, displaying absolute status instead."

This comment has been minimized.

Copy link
@oxinabox

oxinabox May 22, 2019

Contributor

You should really post the exception in the logger.

end
end
if mode == PKGMODE_PROJECT || mode == PKGMODE_COMBINED
Expand Down
13 changes: 13 additions & 0 deletions test/pkg.jl
Expand Up @@ -728,6 +728,19 @@ end
end end
end

@testset "issue #1180: broken toml-files in HEAD" begin
temp_pkg_dir() do dir; cd(dir) do
write("Project.toml", "[deps]\nExample = \n")
LibGit2.with(LibGit2.init(dir)) do repo
LibGit2.add!(repo, "*")
LibGit2.commit(repo, "initial commit"; author=TEST_SIG, committer=TEST_SIG)
end
write("Project.toml", "[deps]\nExample = \"7876af07-990d-54b4-ab0e-23690620f79a\"\n")
Pkg.activate(dir)
@test_logs (:warn, r"Could not read project from HEAD") Pkg.status()
end end
end

import Markdown
@testset "REPL command doc generation" begin
# test that the way doc building extracts
Expand Down

0 comments on commit eae6598

Please sign in to comment.