Skip to content

Commit cad2a38

Browse files
Cia15Datseris
andauthored
* added gitmessage * removed unecessary package I accidently added * Installing packages * testing the gitmssg function * changed variable in LibGit.2.GitCommit() * Added test for the git commit message? * Added one more line to the git message test * Revise the gitmessage test * Changed some of the test for gitmessage * Revision on the commit message test, description * changed back to previous * correct version --------- Co-authored-by: George Datseris <[email protected]>
1 parent 5667d46 commit cad2a38

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 2.13.0
2+
- Add `commmit_message` option in `tag!`, which add an additional `"gitmessage"` field in dictionary `d` and include the git message associated with the commit.
3+
14
# 2.12.6
25
- 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.
36

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DrWatson"
22
uuid = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
33
repo = "https://github.com/JuliaDynamics/DrWatson.jl.git"
4-
version = "2.12.7"
4+
version = "2.13.0"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/saving_tools.jl

+19-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function read_stdout_stderr(cmd::Cmd)
112112
return (exception = exception, out=read(out,String), err=read(err,String))
113113
end
114114

115-
"""
115+
"""
116116
gitpatch(gitpath = projectdir())
117117
118118
Generates a patch describing the changes of a dirty repository
@@ -155,6 +155,7 @@ function gitpatch(path = projectdir(); try_submodule_diff=true)
155155
return nothing
156156
end
157157

158+
158159
########################################################################################
159160
# Tagging
160161
########################################################################################
@@ -167,7 +168,9 @@ the project's gitpath). Do nothing if a key `gitcommit` already exists
167168
repository is not found. If the git repository is dirty, i.e. there
168169
are un-commited changes, and `storepatch` is true, then the output of `git diff HEAD` is stored
169170
in the field `gitpatch`. Note that patches for binary files are not
170-
stored. You can use [`isdirty`](@ref) to check if a repo is dirty.
171+
stored. You can use [`isdirty`](@ref) to check if a repo is dirty.
172+
If the `commit message` is set to `true`,
173+
then the dictionary `d` will include an additional field `"gitmessage"` and will contain the git message associated with the commit.
171174
172175
Notice that the key-type of the dictionary must be `String` or `Symbol`.
173176
If `String` is a subtype of the _value_ type of the dictionary, this operation is
@@ -190,16 +193,18 @@ Dict{Symbol,Int64} with 2 entries:
190193
:y => 4
191194
:x => 3
192195
193-
julia> tag!(d)
196+
julia> tag!(d; commit_message=true)
194197
Dict{Symbol,Any} with 3 entries:
195198
:y => 4
199+
:gitmessage => "File set up by DrWatson"
196200
:gitcommit => "96df587e45b29e7a46348a3d780db1f85f41de04"
197201
:x => 3
198202
```
199203
"""
200204
function tag!(d::AbstractDict{K,T};
201205
gitpath = projectdir(), force = false, source = nothing,
202206
storepatch::Bool = readenv("DRWATSON_STOREPATCH", false),
207+
commit_message::Bool = false
203208
) where {K,T}
204209
@assert (K <: Union{Symbol,String}) "We only know how to tag dictionaries that have keys that are strings or symbols"
205210
c = gitdescribe(gitpath)
@@ -208,6 +213,7 @@ function tag!(d::AbstractDict{K,T};
208213
# Get the appropriate keys
209214
commitname = keyname(d, :gitcommit)
210215
patchname = keyname(d, :gitpatch)
216+
message_name = keyname(d, :gitmessage)
211217

212218
if haskey(d, commitname) && !force
213219
@warn "The dictionary already has a key named `gitcommit`. We won't "*
@@ -222,6 +228,14 @@ function tag!(d::AbstractDict{K,T};
222228
d[patchname] = patch
223229
end
224230
end
231+
if commit_message
232+
repo = LibGit2.GitRepoExt(gitpath)
233+
mssgcommit = LibGit2.GitCommit(repo, "HEAD")
234+
msg = LibGit2.message(mssgcommit)
235+
if (msg !== nothing) && (msg != "")
236+
d[message_name] = msg
237+
end
238+
end
225239
end
226240

227241
# Include source file and line number info if given.
@@ -232,6 +246,8 @@ function tag!(d::AbstractDict{K,T};
232246
return d
233247
end
234248

249+
250+
235251
"""
236252
keyname(d::AbstractDict{K,T}, key) where {K<:Union{Symbol,String},T}
237253

test/stools_tests.jl

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ d2 = Dict("x" => 3, "y" => 4)
6666
_test_tag!(d, dpath, true, "true") # variable parses as true
6767
_test_tag!(d, dpath, true, "1") # variable parses as true
6868
end
69+
@testset "message" begin
70+
d = copy(d1)
71+
path = cpath
72+
d = tag!(d; gitpath=path, commit_message = true)
73+
message_name = keytype(d)(:gitmessage)
74+
@test haskey(d, message_name)
75+
@test d[message_name] == "tmp repo commit"
76+
end
6977
end
7078

7179
# Ensure that above tests operated out-of-place.

0 commit comments

Comments
 (0)