From ab013fb934f120e8d313a70504b141766d5413c0 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Fri, 1 Sep 2023 16:08:07 +0200 Subject: [PATCH 01/12] added gitmessage --- .vscode/settings.json | 2 ++ Project.toml | 1 + src/saving_tools.jl | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..7a73a41b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/Project.toml b/Project.toml index 20a08ba9..c22396f3 100644 --- a/Project.toml +++ b/Project.toml @@ -13,6 +13,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Requires = "ae029012-a4dd-5104-9daa-d747884805df" Scratch = "6c6a2e73-6563-6170-7368-637461726353" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" [compat] diff --git a/src/saving_tools.jl b/src/saving_tools.jl index 75f87cea..29265c90 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -128,9 +128,10 @@ function gitpatch(path = projectdir(); try_submodule_diff=true) repo = LibGit2.GitRepoExt(path) gitpath = LibGit2.path(repo) gitdir = joinpath(gitpath,".git") + gitmessage = LibGit2.message() #Add the gitmessage optional_args = String[] try_submodule_diff && push!(optional_args,"--submodule=diff") - result = read_stdout_stderr(`git --git-dir=$gitdir --work-tree=$gitpath diff $(optional_args) HEAD`) + result = read_stdout_stderr(`git --git-dir=$gitdir --work-tree=$gitpath --message=$gitmessage diff $(optional_args) HEAD`) if result.exception === nothing return result.out elseif Sys.which("git") === nothing @@ -200,6 +201,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), + 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 +210,7 @@ function tag!(d::AbstractDict{K,T}; # Get the appropriate keys commitname = keyname(d, :gitcommit) patchname = keyname(d, :gitpatch) + gitmessage = keyname(d, :gitmessage) ### added if haskey(d, commitname) && !force @warn "The dictionary already has a key named `gitcommit`. We won't "* @@ -222,6 +225,12 @@ function tag!(d::AbstractDict{K,T}; d[patchname] = patch end end + if message + mess = LibGit2.message(c) + if (mess !== nothing) && (mess != "") + d[gitmessage] = mess + end ### added + end end # Include source file and line number info if given. From 0c924f57bc1fab412db5928d77c596592f15fc87 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Fri, 1 Sep 2023 16:11:17 +0200 Subject: [PATCH 02/12] removed unecessary package I accidently added --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index c22396f3..20a08ba9 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Requires = "ae029012-a4dd-5104-9daa-d747884805df" Scratch = "6c6a2e73-6563-6170-7368-637461726353" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" [compat] From c8e964339e31f4f96a2fe6928d36bff9cb2c1d04 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Fri, 8 Sep 2023 13:17:43 +0200 Subject: [PATCH 03/12] Installing packages --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 20a08ba9..c22396f3 100644 --- a/Project.toml +++ b/Project.toml @@ -13,6 +13,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Requires = "ae029012-a4dd-5104-9daa-d747884805df" Scratch = "6c6a2e73-6563-6170-7368-637461726353" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" [compat] From 4b7ef1a82cfd01d7f9a537973ae41be47c1fa205 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Mon, 11 Sep 2023 11:22:10 +0200 Subject: [PATCH 04/12] testing the gitmssg function --- src/saving_tools.jl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/saving_tools.jl b/src/saving_tools.jl index 29265c90..0c192253 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -113,8 +113,6 @@ function read_stdout_stderr(cmd::Cmd) end """ - gitpatch(gitpath = projectdir()) - Generates a patch describing the changes of a dirty repository compared to its last commit; i.e. what `git diff HEAD` produces. The `gitpath` needs to point to a directory within a git repository, @@ -128,10 +126,10 @@ function gitpatch(path = projectdir(); try_submodule_diff=true) repo = LibGit2.GitRepoExt(path) gitpath = LibGit2.path(repo) gitdir = joinpath(gitpath,".git") - gitmessage = LibGit2.message() #Add the gitmessage + ###gitmessage = LibGit2.message() #Add the gitmessage optional_args = String[] try_submodule_diff && push!(optional_args,"--submodule=diff") - result = read_stdout_stderr(`git --git-dir=$gitdir --work-tree=$gitpath --message=$gitmessage diff $(optional_args) HEAD`) + result = read_stdout_stderr(`git --git-dir=$gitdir --work-tree=$gitpath diff $(optional_args) HEAD`) if result.exception === nothing return result.out elseif Sys.which("git") === nothing @@ -156,6 +154,7 @@ function gitpatch(path = projectdir(); try_submodule_diff=true) return nothing end + ######################################################################################## # Tagging ######################################################################################## @@ -201,7 +200,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), - message::Bool = false + mssg::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) @@ -210,7 +209,7 @@ function tag!(d::AbstractDict{K,T}; # Get the appropriate keys commitname = keyname(d, :gitcommit) patchname = keyname(d, :gitpatch) - gitmessage = keyname(d, :gitmessage) ### added + mssgname = keyname(d, :gitmessage) ### added if haskey(d, commitname) && !force @warn "The dictionary already has a key named `gitcommit`. We won't "* @@ -225,10 +224,11 @@ function tag!(d::AbstractDict{K,T}; d[patchname] = patch end end - if message - mess = LibGit2.message(c) - if (mess !== nothing) && (mess != "") - d[gitmessage] = mess + if mssg + mssgcommit = LibGit2.GitCommit(gitpath, commitname) + msg = LibGit2.message(mssgcommit) + if (msg !== nothing) && (msg != "") + d[mssgname] = msg end ### added end end @@ -241,6 +241,8 @@ function tag!(d::AbstractDict{K,T}; return d end + + """ keyname(d::AbstractDict{K,T}, key) where {K<:Union{Symbol,String},T} From a69f9a64a114a98612a752ce5a229bf3a122ea35 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Tue, 12 Sep 2023 14:24:53 +0200 Subject: [PATCH 05/12] changed variable in LibGit.2.GitCommit() --- src/saving_tools.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/saving_tools.jl b/src/saving_tools.jl index 0c192253..d590b83b 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -112,8 +112,7 @@ function read_stdout_stderr(cmd::Cmd) return (exception = exception, out=read(out,String), err=read(err,String)) end -""" -Generates a patch describing the changes of a dirty repository +""" Generates a patch describing the changes of a dirty repository compared to its last commit; i.e. what `git diff HEAD` produces. The `gitpath` needs to point to a directory within a git repository, otherwise `nothing` is returned. @@ -225,11 +224,13 @@ function tag!(d::AbstractDict{K,T}; end end if mssg - mssgcommit = LibGit2.GitCommit(gitpath, commitname) + repo = LibGit2.GitRepoExt(gitpath) + @show commitname, repo, mssgname + mssgcommit = LibGit2.GitCommit(repo, "HEAD") msg = LibGit2.message(mssgcommit) if (msg !== nothing) && (msg != "") d[mssgname] = msg - end ### added + end ### added end end From 52a2ba03f7f3e8b11c014ea5d3349b2ad45d7404 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Fri, 15 Sep 2023 16:52:42 +0200 Subject: [PATCH 06/12] Added test for the git commit message? --- .vscode/settings.json | 1 + Project.toml | 1 - src/saving_tools.jl | 12 ++++++------ test/stools_tests.jl | 24 ++++++++++++++++-------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a73a41b..9b9917a5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,2 +1,3 @@ { + "julia.environmentPath": "C:\\Users\\cgowe\\.julia\\environments\\v1.9" } \ No newline at end of file diff --git a/Project.toml b/Project.toml index c22396f3..20a08ba9 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Requires = "ae029012-a4dd-5104-9daa-d747884805df" Scratch = "6c6a2e73-6563-6170-7368-637461726353" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" [compat] diff --git a/src/saving_tools.jl b/src/saving_tools.jl index d590b83b..d4b93c3e 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -112,7 +112,8 @@ function read_stdout_stderr(cmd::Cmd) return (exception = exception, out=read(out,String), err=read(err,String)) end -""" Generates a patch describing the changes of a dirty repository +""" +Generates a patch describing the changes of a dirty repository compared to its last commit; i.e. what `git diff HEAD` produces. The `gitpath` needs to point to a directory within a git repository, otherwise `nothing` is returned. @@ -199,7 +200,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), - mssg::Bool = 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,7 +209,7 @@ function tag!(d::AbstractDict{K,T}; # Get the appropriate keys commitname = keyname(d, :gitcommit) patchname = keyname(d, :gitpatch) - mssgname = keyname(d, :gitmessage) ### added + message_name = keyname(d, :gitmessage) ### added if haskey(d, commitname) && !force @warn "The dictionary already has a key named `gitcommit`. We won't "* @@ -223,13 +224,12 @@ function tag!(d::AbstractDict{K,T}; d[patchname] = patch end end - if mssg + if commit_message repo = LibGit2.GitRepoExt(gitpath) - @show commitname, repo, mssgname mssgcommit = LibGit2.GitCommit(repo, "HEAD") msg = LibGit2.message(mssgcommit) if (msg !== nothing) && (msg != "") - d[mssgname] = msg + d[message_name] = msg end ### added end end diff --git a/test/stools_tests.jl b/test/stools_tests.jl index cddd6827..d9390cb2 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -35,7 +35,7 @@ cpath = _setup_repo(false) # clean @test !endswith(gitdescribe(cpath), "-dirty") # tag! -function _test_tag!(d, path, haspatch, DRWATSON_STOREPATCH) +function _test_tag!(d, path, haspatch, has_message, DRWATSON_STOREPATCH) d = copy(d) withenv("DRWATSON_STOREPATCH" => DRWATSON_STOREPATCH) do d = tag!(d, gitpath=path) @@ -48,6 +48,11 @@ function _test_tag!(d, path, haspatch, DRWATSON_STOREPATCH) @test d[patchname] isa String @test d[patchname] != "" end + if has_message + message_name = keytype(d)(:gitmessage) + @test haskey(d, message_name) + @test d[message_name] isa String + end end end @@ -56,15 +61,18 @@ d2 = Dict("x" => 3, "y" => 4) @testset "tag! ($(keytype(d)))" for d in (d1, d2) @testset "no patch ($(dirty ? "dirty" : "clean"))" for dirty in (true, false) path = dirty ? dpath : cpath - _test_tag!(d, path, false, nothing) # variable unset - _test_tag!(d, path, false, "") # variable set but empty - _test_tag!(d, path, false, "false") # variable parses as false - _test_tag!(d, path, false, "0") # variable parses as false - _test_tag!(d, path, false, "rubbish") # variable not a Bool + _test_tag!(d, path, false, false, nothing) # variable unset + _test_tag!(d, path, false, false, "") # variable set but empty + _test_tag!(d, path, false, false, "false") # variable parses as false + _test_tag!(d, path, false, false, "0") # variable parses as false + _test_tag!(d, path, false, false, "rubbish") # variable not a Bool end @testset "patch" begin - _test_tag!(d, dpath, true, "true") # variable parses as true - _test_tag!(d, dpath, true, "1") # variable parses as true + _test_tag!(d, dpath, true, false, "true") # variable parses as true + _test_tag!(d, dpath, true, false, "1") # variable parses as true + end + @testset "message_name" begin + _test_tag!(d, dpath, true, false, "true") end end From 1bbe585e6bdc4d30459e06dcf16b50d45f045e7b Mon Sep 17 00:00:00 2001 From: Cia15 Date: Fri, 15 Sep 2023 16:54:58 +0200 Subject: [PATCH 07/12] Added one more line to the git message test --- test/stools_tests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/stools_tests.jl b/test/stools_tests.jl index d9390cb2..9f77f39b 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -52,6 +52,7 @@ function _test_tag!(d, path, haspatch, has_message, DRWATSON_STOREPATCH) message_name = keytype(d)(:gitmessage) @test haskey(d, message_name) @test d[message_name] isa String + @test d[message_name] != "" end end end From 664e844d08e563ff5fec52999578486a936e6d04 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Fri, 15 Sep 2023 21:27:11 +0200 Subject: [PATCH 08/12] Revise the gitmessage test --- .vscode/settings.json | 3 --- src/saving_tools.jl | 13 ++++++++----- test/stools_tests.jl | 35 ++++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 23 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 9b9917a5..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "julia.environmentPath": "C:\\Users\\cgowe\\.julia\\environments\\v1.9" -} \ No newline at end of file diff --git a/src/saving_tools.jl b/src/saving_tools.jl index d4b93c3e..d80ccaf1 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -113,6 +113,8 @@ function read_stdout_stderr(cmd::Cmd) end """ +gitpatch(gitpath = projectdir()) + Generates a patch describing the changes of a dirty repository compared to its last commit; i.e. what `git diff HEAD` produces. The `gitpath` needs to point to a directory within a git repository, @@ -126,7 +128,6 @@ function gitpatch(path = projectdir(); try_submodule_diff=true) repo = LibGit2.GitRepoExt(path) gitpath = LibGit2.path(repo) gitdir = joinpath(gitpath,".git") - ###gitmessage = LibGit2.message() #Add the gitmessage optional_args = String[] try_submodule_diff && push!(optional_args,"--submodule=diff") result = read_stdout_stderr(`git --git-dir=$gitdir --work-tree=$gitpath diff $(optional_args) HEAD`) @@ -167,7 +168,8 @@ 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 output will display the commit message. 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 +192,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 ``` @@ -209,7 +212,7 @@ function tag!(d::AbstractDict{K,T}; # Get the appropriate keys commitname = keyname(d, :gitcommit) patchname = keyname(d, :gitpatch) - message_name = keyname(d, :gitmessage) ### added + message_name = keyname(d, :gitmessage) if haskey(d, commitname) && !force @warn "The dictionary already has a key named `gitcommit`. We won't "* @@ -230,7 +233,7 @@ function tag!(d::AbstractDict{K,T}; msg = LibGit2.message(mssgcommit) if (msg !== nothing) && (msg != "") d[message_name] = msg - end ### added + end end end diff --git a/test/stools_tests.jl b/test/stools_tests.jl index 9f77f39b..7c81befd 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -35,7 +35,7 @@ cpath = _setup_repo(false) # clean @test !endswith(gitdescribe(cpath), "-dirty") # tag! -function _test_tag!(d, path, haspatch, has_message, DRWATSON_STOREPATCH) +function _test_tag!(d, path, haspatch, DRWATSON_STOREPATCH) d = copy(d) withenv("DRWATSON_STOREPATCH" => DRWATSON_STOREPATCH) do d = tag!(d, gitpath=path) @@ -48,12 +48,6 @@ function _test_tag!(d, path, haspatch, has_message, DRWATSON_STOREPATCH) @test d[patchname] isa String @test d[patchname] != "" end - if has_message - message_name = keytype(d)(:gitmessage) - @test haskey(d, message_name) - @test d[message_name] isa String - @test d[message_name] != "" - end end end @@ -62,21 +56,32 @@ d2 = Dict("x" => 3, "y" => 4) @testset "tag! ($(keytype(d)))" for d in (d1, d2) @testset "no patch ($(dirty ? "dirty" : "clean"))" for dirty in (true, false) path = dirty ? dpath : cpath - _test_tag!(d, path, false, false, nothing) # variable unset - _test_tag!(d, path, false, false, "") # variable set but empty - _test_tag!(d, path, false, false, "false") # variable parses as false - _test_tag!(d, path, false, false, "0") # variable parses as false - _test_tag!(d, path, false, false, "rubbish") # variable not a Bool + _test_tag!(d, path, false, nothing) # variable unset + _test_tag!(d, path, false, "") # variable set but empty + _test_tag!(d, path, false, "false") # variable parses as false + _test_tag!(d, path, false, "0") # variable parses as false + _test_tag!(d, path, false, "rubbish") # variable not a Bool end @testset "patch" begin - _test_tag!(d, dpath, true, false, "true") # variable parses as true - _test_tag!(d, dpath, true, false, "1") # variable parses as true + _test_tag!(d, dpath, true, "true") # variable parses as true + _test_tag!(d, dpath, true, "1") # variable parses as true end @testset "message_name" begin - _test_tag!(d, dpath, true, false, "true") + path = mktempdir(cleanup=true) # delete path on process exit + repo = LibGit2.init(path) + LibGit2.commit(repo, "tmp repo commit") + message_commit_test = LibGit2.GitCommit(repo, "HEAD") + message_name = LibGit2.message(message_commit_test) + if (message_name !== nothing) && (message_name != "") + print(message_name) + end end end +# Ensure that the correct git message show up +d_new = tag!(d, gitpath=dpath, commit_message = true) + + # Ensure that above tests operated out-of-place. @test d1 == Dict(:x => 3, :y => 4) @test d2 == Dict("x" => 3, "y" => 4) From 440b471d46ec986700afe8f3c13d5201804fc5db Mon Sep 17 00:00:00 2001 From: Cia15 Date: Tue, 26 Sep 2023 12:47:04 +0200 Subject: [PATCH 09/12] Changed some of the test for gitmessage --- src/saving_tools.jl | 6 +++--- test/stools_tests.jl | 41 +++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/saving_tools.jl b/src/saving_tools.jl index d80ccaf1..1c3e61be 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -113,7 +113,7 @@ function read_stdout_stderr(cmd::Cmd) end """ -gitpatch(gitpath = projectdir()) + gitpatch(gitpath = projectdir()) Generates a patch describing the changes of a dirty repository compared to its last commit; i.e. what `git diff HEAD` produces. @@ -168,7 +168,7 @@ 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. If the commit message is set to true, +stored. You can use [`isdirty`](@ref) to check if a repo is dirty. If the `commit message` is set to `true`, then the output will display the commit message. Notice that the key-type of the dictionary must be `String` or `Symbol`. @@ -192,7 +192,7 @@ Dict{Symbol,Int64} with 2 entries: :y => 4 :x => 3 -julia> tag!(d, commit_message=true) +julia> tag!(d; commit_message=true) Dict{Symbol,Any} with 3 entries: :y => 4 :gitmessage => "File set up by DrWatson" diff --git a/test/stools_tests.jl b/test/stools_tests.jl index 7c81befd..3c8f247c 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -35,10 +35,10 @@ cpath = _setup_repo(false) # clean @test !endswith(gitdescribe(cpath), "-dirty") # tag! -function _test_tag!(d, path, haspatch, DRWATSON_STOREPATCH) +function _test_tag!(d, path, haspatch, hasmessage, DRWATSON_STOREPATCH) d = copy(d) withenv("DRWATSON_STOREPATCH" => DRWATSON_STOREPATCH) do - d = tag!(d, gitpath=path) + d = tag!(d, gitpath=path; commit_message = true) commitname = keytype(d)(:gitcommit) @test haskey(d, commitname) @test d[commitname] isa String @@ -48,6 +48,13 @@ function _test_tag!(d, path, haspatch, DRWATSON_STOREPATCH) @test d[patchname] isa String @test d[patchname] != "" end + if hasmessage + message_name = keytype(d)(:gitmessage) + @test haskey(d, message_name) + @test d[message_name] isa String + @test d[message_name] != "" + @test d[message_name] == "tmp repo commit" + end end end @@ -56,32 +63,22 @@ d2 = Dict("x" => 3, "y" => 4) @testset "tag! ($(keytype(d)))" for d in (d1, d2) @testset "no patch ($(dirty ? "dirty" : "clean"))" for dirty in (true, false) path = dirty ? dpath : cpath - _test_tag!(d, path, false, nothing) # variable unset - _test_tag!(d, path, false, "") # variable set but empty - _test_tag!(d, path, false, "false") # variable parses as false - _test_tag!(d, path, false, "0") # variable parses as false - _test_tag!(d, path, false, "rubbish") # variable not a Bool + _test_tag!(d, path, false, false, nothing) # variable unset + _test_tag!(d, path, false, false, "") # variable set but empty + _test_tag!(d, path, false, false, "false") # variable parses as false + _test_tag!(d, path, false, false, "0") # variable parses as false + _test_tag!(d, path, false, false, "rubbish") # variable not a Bool end @testset "patch" begin - _test_tag!(d, dpath, true, "true") # variable parses as true - _test_tag!(d, dpath, true, "1") # variable parses as true + _test_tag!(d, dpath, true, false, "true") # variable parses as true + _test_tag!(d, dpath, true, false, "1") # variable parses as true end - @testset "message_name" begin - path = mktempdir(cleanup=true) # delete path on process exit - repo = LibGit2.init(path) - LibGit2.commit(repo, "tmp repo commit") - message_commit_test = LibGit2.GitCommit(repo, "HEAD") - message_name = LibGit2.message(message_commit_test) - if (message_name !== nothing) && (message_name != "") - print(message_name) - end + @testset "message" begin + _test_tag!(d, dpath, true, false, "true") + _test_tag!(d, dpath, true, true, "true") end end -# Ensure that the correct git message show up -d_new = tag!(d, gitpath=dpath, commit_message = true) - - # Ensure that above tests operated out-of-place. @test d1 == Dict(:x => 3, :y => 4) @test d2 == Dict("x" => 3, "y" => 4) From fe299f6e2db2d622d3f680b9057a500a920ba513 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Wed, 27 Sep 2023 16:29:28 +0200 Subject: [PATCH 10/12] Revision on the commit message test, description --- CHANGELOG.md | 3 +++ Project.toml | 2 +- src/saving_tools.jl | 5 +++-- test/stools_tests.jl | 31 ++++++++++++++----------------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37bbfe76..c253d457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.13.7 +- 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..a070878d 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.7" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/saving_tools.jl b/src/saving_tools.jl index 1c3e61be..6d6c2da0 100644 --- a/src/saving_tools.jl +++ b/src/saving_tools.jl @@ -168,8 +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. If the `commit message` is set to `true`, -then the output will display the commit message. +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 diff --git a/test/stools_tests.jl b/test/stools_tests.jl index 3c8f247c..0a195bb1 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -35,7 +35,7 @@ cpath = _setup_repo(false) # clean @test !endswith(gitdescribe(cpath), "-dirty") # tag! -function _test_tag!(d, path, haspatch, hasmessage, DRWATSON_STOREPATCH) +function _test_tag!(d, path, haspatch, DRWATSON_STOREPATCH) d = copy(d) withenv("DRWATSON_STOREPATCH" => DRWATSON_STOREPATCH) do d = tag!(d, gitpath=path; commit_message = true) @@ -48,13 +48,6 @@ function _test_tag!(d, path, haspatch, hasmessage, DRWATSON_STOREPATCH) @test d[patchname] isa String @test d[patchname] != "" end - if hasmessage - message_name = keytype(d)(:gitmessage) - @test haskey(d, message_name) - @test d[message_name] isa String - @test d[message_name] != "" - @test d[message_name] == "tmp repo commit" - end end end @@ -63,19 +56,23 @@ d2 = Dict("x" => 3, "y" => 4) @testset "tag! ($(keytype(d)))" for d in (d1, d2) @testset "no patch ($(dirty ? "dirty" : "clean"))" for dirty in (true, false) path = dirty ? dpath : cpath - _test_tag!(d, path, false, false, nothing) # variable unset - _test_tag!(d, path, false, false, "") # variable set but empty - _test_tag!(d, path, false, false, "false") # variable parses as false - _test_tag!(d, path, false, false, "0") # variable parses as false - _test_tag!(d, path, false, false, "rubbish") # variable not a Bool + _test_tag!(d, path, false, nothing) # variable unset + _test_tag!(d, path, false, "") # variable set but empty + _test_tag!(d, path, false, "false") # variable parses as false + _test_tag!(d, path, false, "0") # variable parses as false + _test_tag!(d, path, false, "rubbish") # variable not a Bool end @testset "patch" begin - _test_tag!(d, dpath, true, false, "true") # variable parses as true - _test_tag!(d, dpath, true, false, "1") # variable parses as true + _test_tag!(d, dpath, true, "true") # variable parses as true + _test_tag!(d, dpath, true, "1") # variable parses as true end @testset "message" begin - _test_tag!(d, dpath, true, false, "true") - _test_tag!(d, dpath, true, true, "true") + 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 From 486df1acc64d5444025e9760b7ea33fbc4d03dc7 Mon Sep 17 00:00:00 2001 From: Cia15 Date: Wed, 27 Sep 2023 16:32:20 +0200 Subject: [PATCH 11/12] changed back to previous --- test/stools_tests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/stools_tests.jl b/test/stools_tests.jl index 0a195bb1..946d9098 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -38,7 +38,7 @@ cpath = _setup_repo(false) # clean function _test_tag!(d, path, haspatch, DRWATSON_STOREPATCH) d = copy(d) withenv("DRWATSON_STOREPATCH" => DRWATSON_STOREPATCH) do - d = tag!(d, gitpath=path; commit_message = true) + d = tag!(d, gitpath=path) commitname = keytype(d)(:gitcommit) @test haskey(d, commitname) @test d[commitname] isa String From f659ab729358551f095e5d833bf1fa0a900cf1c0 Mon Sep 17 00:00:00 2001 From: George Datseris Date: Thu, 28 Sep 2023 21:22:49 +0100 Subject: [PATCH 12/12] correct version --- CHANGELOG.md | 2 +- Project.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c253d457..f15a16f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 2.13.7 +# 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 diff --git a/Project.toml b/Project.toml index a070878d..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.13.7" +version = "2.13.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"