diff --git a/stdlib/LibGit2/src/config.jl b/stdlib/LibGit2/src/config.jl index 46b826d1ae04a..c0fe4d17aeba8 100644 --- a/stdlib/LibGit2/src/config.jl +++ b/stdlib/LibGit2/src/config.jl @@ -3,19 +3,19 @@ """ GitConfig(path::AbstractString, level::Consts.GIT_CONFIG=Consts.CONFIG_LEVEL_APP, force::Bool=false) -Create a new `GitConfig` by loading configuration information from the file at -`path`. See [`addfile`](@ref) for more information about the `level` and `force` -options. +Create a new `GitConfig` by loading configuration information from the file at `path`. See +[`addfile`](@ref) for more information about the `level`, `repo` and `force` options. """ function GitConfig(path::AbstractString, level::Consts.GIT_CONFIG = Consts.CONFIG_LEVEL_APP, + repo::Union{GitRepo, Nothing}=nothing, force::Bool=false) # create new config object cfg_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL) @check ccall((:git_config_new, :libgit2), Cint, (Ptr{Ptr{Cvoid}},), cfg_ptr_ptr) cfg = GitConfig(cfg_ptr_ptr[]) try - addfile(cfg, path, level, force) + addfile(cfg, path, level, repo, force) catch ex close(cfg) rethrow(ex) @@ -65,22 +65,36 @@ function GitConfig(level::Consts.GIT_CONFIG = Consts.CONFIG_LEVEL_DEFAULT) end """ - addfile(cfg::GitConfig, path::AbstractString, level::Consts.GIT_CONFIG=Consts.CONFIG_LEVEL_APP, force::Bool=false) + addfile(cfg::GitConfig, path::AbstractString, + level::Consts.GIT_CONFIG=Consts.CONFIG_LEVEL_APP, + repo::Union{GitRepo, Nothing} = nothing, + force::Bool=false) Add an existing git configuration file located at `path` to the current `GitConfig` `cfg`. If the file does not exist, it will be created. -`level` sets the git configuration priority level and is determined by -[`Consts.GIT_CONFIG`](@ref). If `force` is `false` and a configuration for -the given priority level already exists, `addfile` will error. If `force` is -`true`, the existing configuration will be replaced by the one in the file at -`path`. + + - `level` sets the git configuration priority level and is determined by +[`Consts.GIT_CONFIG`](@ref). + - `repo` is an optional repository to allow parsing of conditional includes. + - If `force` is `false` and a configuration for the given priority level already exists, +`addfile` will error. If `force` is `true`, the existing configuration will be replaced by +the one in the file at `path`. + """ function addfile(cfg::GitConfig, path::AbstractString, level::Consts.GIT_CONFIG = Consts.CONFIG_LEVEL_APP, + repo::Union{GitRepo, Nothing} = nothing, force::Bool=false) - @check ccall((:git_config_add_file_ondisk, :libgit2), Cint, - (Ptr{Ptr{Cvoid}}, Cstring, Cint, Cint), - cfg.ptr, path, Cint(level), Cint(force)) + @static if LibGit2.VERSION >= v"0.27.0" + @check ccall((:git_config_add_file_ondisk, :libgit2), Cint, + (Ptr{Ptr{Cvoid}}, Cstring, Cint, Ptr{Cvoid}, Cint), + cfg.ptr, path, Cint(level), isa(repo, GitRepo) ? repo.ptr : C_NULL, Cint(force)) + else + repo === nothing || error("repo argument is not supported in this version of LibGit2") + @check ccall((:git_config_add_file_ondisk, :libgit2), Cint, + (Ptr{Ptr{Cvoid}}, Cstring, Cint, Cint), + cfg.ptr, path, Cint(level), Cint(force)) + end end function get(::Type{<:AbstractString}, c::GitConfig, name::AbstractString) diff --git a/stdlib/LibGit2/src/types.jl b/stdlib/LibGit2/src/types.jl index f4de1601036a7..d33e663691714 100644 --- a/stdlib/LibGit2/src/types.jl +++ b/stdlib/LibGit2/src/types.jl @@ -45,6 +45,9 @@ Matches the [`git_time`](https://libgit2.github.com/libgit2/#HEAD/type/git_time) struct TimeStruct time::Int64 # time in seconds from epoch offset::Cint # timezone offset in minutes + @static if LibGit2.VERSION >= v"0.27.0" + sign::Cchar + end end """ @@ -830,6 +833,8 @@ The fields represent: * `flags`: flags for controlling any callbacks used in a status call. * `pathspec`: an array of paths to use for path-matching. The behavior of the path-matching will vary depending on the values of `show` and `flags`. + * The `baseline` is the tree to be used for comparison to the working directory and + index; defaults to HEAD. """ @kwdef struct StatusOptions version::Cuint = 1 @@ -839,6 +844,9 @@ The fields represent: Consts.STATUS_OPT_RENAMES_HEAD_TO_INDEX | Consts.STATUS_OPT_SORT_CASE_SENSITIVELY pathspec::StrArrayStruct + @static if LibGit2.VERSION >= v"0.27.0" + baseline::Ptr{Cvoid} + end end """