Skip to content

Commit

Permalink
Add Rogue.status
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 25, 2019
1 parent c5ad01d commit 9d5d7fa
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
43 changes: 43 additions & 0 deletions src/api.jl
Expand Up @@ -227,3 +227,46 @@ addin(
package::AbstractString = ".";
kwargs...,
) = add(package, project=project; kwargs...)

"""
Rogue.status()
Rogue.status(project::String)
"""
function status(
project::Union{Nothing, AbstractString} = nothing,
)

if project === nothing
project = dirname(Base.active_project())
end
manifest = TOML.parsefile(manifesttomlpath(project))
foreach(private_projects_in_manifest(), manifest) do (name, entry)
haskey(entry, "git-tree-sha1") || return # possible?

url = entry["repo-url"]
treesha1 = entry["git-tree-sha1"]
uuid = entry["uuid"]

spec = Pkg.PackageSpec(
name = name,
uuid = uuid,
url = url,
)
path = Pkg.Types.fresh_clone(spec)
try
open(git_cmd(`log --format=format:'%H %T'`, path)) do stream
while !eof(stream)
ln = readline(stream)
logcommit, logtree = split(ln, " ", limit=2)
if logtree == treesha1
run(git_cmd(`log --max-count=1 --oneline $logcommit`, path))
return
end
end
@warn "Tree SHA `$treesha1` not found for package `$name` [$uuid]"
end
finally
rm(path; force=true, recursive=true)
end
end
end
16 changes: 8 additions & 8 deletions src/manifests.jl
Expand Up @@ -156,18 +156,18 @@ function _add_private_project!(added::Set, private_projects::Dict, name::String)
return
end

private_projects_in_manifest() =
MapCat() do (name, entries)
tuple.(name, entries)
end |> Filter() do (name, entry)
haskey(entry, "repo-url")
end

function add_private_projects_from(deps, manifestfile::AbstractString)
manifest = TOML.parsefile(manifestfile)

# Extract all private projects:
private_projects = Dict(eduction(
MapCat() do (name, entries)
tuple.(name, entries)
end |> Filter() do (name, entry)
haskey(entry, "repo-url")
end,
manifest,
))
private_projects = Dict(eduction(private_projects_in_manifest(), manifest))
# TODO: make sure that there is no duplicated names (but is it possible?)
private_deps = intersect(deps, keys(private_projects))
_add_private_projects(private_deps, private_projects)
Expand Down

0 comments on commit 9d5d7fa

Please sign in to comment.