Skip to content

Commit 91701a5

Browse files
authored
Make relpath_from_repo_root, repo_commit throw when file doesn't exists (#1923)
1 parent 2d02013 commit 91701a5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Utilities/Utilities.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,15 @@ Returns the path of `file`, relative to the root of the Git repository, or `noth
420420
file is not in a Git repository.
421421
"""
422422
function relpath_from_repo_root(file)
423+
isfile(file) || error("relpath_from_repo_root called with nonexistent file: $file")
423424
cd(dirname(file)) do
424425
root = repo_root(file)
425426
root !== nothing && startswith(file, root) ? relpath(file, root) : nothing
426427
end
427428
end
428429

429430
function repo_commit(file)
431+
isfile(file) || error("repo_commit called with nonexistent file: $file")
430432
cd(dirname(file)) do
431433
readchomp(`$(git()) rev-parse HEAD`)
432434
end

test/utilities.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ end
192192
@test Documenter.Utilities.relpath_from_repo_root(filepath) == joinpath("src", "SourceFile.jl")
193193
# We assume that a temporary file is not in a repo
194194
@test Documenter.Utilities.repo_root(tempname()) == nothing
195-
@test Documenter.Utilities.relpath_from_repo_root(tempname()) == nothing
195+
@test_throws ErrorException Documenter.Utilities.relpath_from_repo_root(tempname())
196196
end
197197

198198
# Test worktree
@@ -214,7 +214,7 @@ end
214214
@test Documenter.Utilities.relpath_from_repo_root(filepath) == joinpath("src", "SourceFile.jl")
215215
# We assume that a temporary file is not in a repo
216216
@test Documenter.Utilities.repo_root(tempname()) == nothing
217-
@test Documenter.Utilities.relpath_from_repo_root(tempname()) == nothing
217+
@test_throws ErrorException Documenter.Utilities.relpath_from_repo_root(tempname())
218218
end
219219

220220
# Test submodule
@@ -249,7 +249,7 @@ end
249249
@test Documenter.Utilities.relpath_from_repo_root(filepath) == joinpath("src", "SourceFile.jl")
250250
# We assume that a temporary file is not in a repo
251251
@test Documenter.Utilities.repo_root(tempname()) == nothing
252-
@test Documenter.Utilities.relpath_from_repo_root(tempname()) == nothing
252+
@test_throws ErrorException Documenter.Utilities.relpath_from_repo_root(tempname())
253253
end
254254

255255
# This tests the case where the origin.url is some unrecognised Git hosting service, in which case we are unable

0 commit comments

Comments
 (0)