diff --git a/CHANGELOG.md b/CHANGELOG.md index 37bbfe76..f15a16f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.13.0 +- Add `commmit_message` option in `tag!`, which add an additional `"gitmessage"` field in dictionary `d` and include the git message associated with the commit. + # 2.12.6 - Crucial bugfix to `produce_or_load`. When used with a prefix, it attached double prefix to the file (one coming as a duplicate from `savename`). This is now fixed, but it means that some files produced with prefix and `produce_or_load` in v2.12 may be re-produced after this update. diff --git a/Project.toml b/Project.toml index 20a08ba9..b79ab7b3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DrWatson" uuid = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1" repo = "https://github.com/JuliaDynamics/DrWatson.jl.git" -version = "2.12.7" +version = "2.13.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/saving_tools.jl b/src/saving_tools.jl index 75f87cea..6d6c2da0 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -112,7 +112,7 @@ function read_stdout_stderr(cmd::Cmd) return (exception = exception, out=read(out,String), err=read(err,String)) end -""" +""" gitpatch(gitpath = projectdir()) Generates a patch describing the changes of a dirty repository @@ -155,6 +155,7 @@ function gitpatch(path = projectdir(); try_submodule_diff=true) return nothing end + ######################################################################################## # Tagging ######################################################################################## @@ -167,7 +168,9 @@ the project's gitpath). Do nothing if a key `gitcommit` already exists repository is not found. If the git repository is dirty, i.e. there are un-commited changes, and `storepatch` is true, then the output of `git diff HEAD` is stored in the field `gitpatch`. Note that patches for binary files are not -stored. You can use [`isdirty`](@ref) to check if a repo is dirty. +stored. You can use [`isdirty`](@ref) to check if a repo is dirty. +If the `commit message` is set to `true`, +then the dictionary `d` will include an additional field `"gitmessage"` and will contain the git message associated with the commit. Notice that the key-type of the dictionary must be `String` or `Symbol`. If `String` is a subtype of the _value_ type of the dictionary, this operation is @@ -190,9 +193,10 @@ Dict{Symbol,Int64} with 2 entries: :y => 4 :x => 3 -julia> tag!(d) +julia> tag!(d; commit_message=true) Dict{Symbol,Any} with 3 entries: :y => 4 + :gitmessage => "File set up by DrWatson" :gitcommit => "96df587e45b29e7a46348a3d780db1f85f41de04" :x => 3 ``` @@ -200,6 +204,7 @@ Dict{Symbol,Any} with 3 entries: function tag!(d::AbstractDict{K,T}; gitpath = projectdir(), force = false, source = nothing, storepatch::Bool = readenv("DRWATSON_STOREPATCH", false), + commit_message::Bool = false ) where {K,T} @assert (K <: Union{Symbol,String}) "We only know how to tag dictionaries that have keys that are strings or symbols" c = gitdescribe(gitpath) @@ -208,6 +213,7 @@ function tag!(d::AbstractDict{K,T}; # Get the appropriate keys commitname = keyname(d, :gitcommit) patchname = keyname(d, :gitpatch) + message_name = keyname(d, :gitmessage) if haskey(d, commitname) && !force @warn "The dictionary already has a key named `gitcommit`. We won't "* @@ -222,6 +228,14 @@ function tag!(d::AbstractDict{K,T}; d[patchname] = patch end end + if commit_message + repo = LibGit2.GitRepoExt(gitpath) + mssgcommit = LibGit2.GitCommit(repo, "HEAD") + msg = LibGit2.message(mssgcommit) + if (msg !== nothing) && (msg != "") + d[message_name] = msg + end + end end # Include source file and line number info if given. @@ -232,6 +246,8 @@ function tag!(d::AbstractDict{K,T}; return d end + + """ keyname(d::AbstractDict{K,T}, key) where {K<:Union{Symbol,String},T} diff --git a/test/stools_tests.jl b/test/stools_tests.jl index cddd6827..946d9098 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -66,6 +66,14 @@ d2 = Dict("x" => 3, "y" => 4) _test_tag!(d, dpath, true, "true") # variable parses as true _test_tag!(d, dpath, true, "1") # variable parses as true end + @testset "message" begin + d = copy(d1) + path = cpath + d = tag!(d; gitpath=path, commit_message = true) + message_name = keytype(d)(:gitmessage) + @test haskey(d, message_name) + @test d[message_name] == "tmp repo commit" + end end # Ensure that above tests operated out-of-place.