Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Base.BinaryPlatforms
import ...Pkg
import ...Pkg: pkg_server, Registry, pathrepr, can_fancyprint, printpkgstyle, stderr_f, OFFLINE_MODE
import ...Pkg: UPDATED_REGISTRY_THIS_SESSION, RESPECT_SYSIMAGE_VERSIONS, should_autoprecompile
import ...Pkg: usable_io
import ...Pkg: usable_io, discover_repo

#########
# Utils #
Expand Down Expand Up @@ -2988,10 +2988,11 @@ function status(env::EnvCache, registries::Vector{Registry.RegistryInstance}, pk
old_env = nothing
if git_diff
project_dir = dirname(env.project_file)
if !ispath(joinpath(project_dir, ".git"))
git_repo_dir = discover_repo(project_dir)
if git_repo_dir == nothing
@warn "diff option only available for environments in git repositories, ignoring."
else
old_env = git_head_env(env, project_dir)
old_env = git_head_env(env, git_repo_dir)
if old_env === nothing
@warn "could not read project from HEAD, displaying absolute status instead."
end
Expand Down
16 changes: 16 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,19 @@ end
if VERSION < v"1.2.0-DEV.269" # Defined in Base as of #30947
Base.isless(a::UUID, b::UUID) = a.value < b.value
end

function discover_repo(path::AbstractString)
dir = abspath(path)
stop_dir = homedir()

while true
gitdir = joinpath(dir, ".git")
if isdir(gitdir) || isfile(gitdir)
return dir
end
dir == stop_dir && return nothing
parent = dirname(dir)
parent == dir && return nothing
dir = parent
end
end
15 changes: 15 additions & 0 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,21 @@ end
end
end

@testset "status diff non-root" begin
isolate(loaded_depot=true) do
cd_tempdir() do dir
Pkg.generate("A")
git_init_and_commit(".")
Pkg.activate("A")
Pkg.add("Example")
io = IOBuffer()
Pkg.status(; io, diff=true)
str = String(take!(io))
@test occursin("+ Example", str)
end
end
end

@testset "test instantiate with sources with only rev" begin
isolate() do
mktempdir() do dir
Expand Down