I'm looking for a function (or macro) that returns the root directory of a git repo when run from a file inside the repo (sort of how @__DIR__
does it, but then should return the git root dir). Has anybody implemented this?
I came up with this approach:
function gitrootdir(currdir)
while true
currdir == homedir() && return nothing
currdir == "/" && return nothing
".git" in readdir(currdir) && return currdir
currdir = dirname(currdir)
end
end
gitrootdir(@__DIR__)
If someone has a better approach or an improvement for this one, please let me know.
There's probably someting in LibGit2
for this
Thanks! There is indeed LibGit2.path(repo::GitRepo)
.
Last updated: Oct 02 2023 at 04:34 UTC