-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#387 #398
#387 #398
Changes from 8 commits
ab013fb
0c924f5
c8e9643
4b7ef1a
a69f9a6
52a2ba0
1bbe585
664e844
440b471
fe299f6
486df1a
f659ab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -112,8 +112,8 @@ function read_stdout_stderr(cmd::Cmd) | |||||
return (exception = exception, out=read(out,String), err=read(err,String)) | ||||||
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. | ||||||
|
@@ -155,6 +155,7 @@ function gitpatch(path = projectdir(); try_submodule_diff=true) | |||||
return nothing | ||||||
end | ||||||
|
||||||
|
||||||
######################################################################################## | ||||||
# Tagging | ||||||
######################################################################################## | ||||||
|
@@ -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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When referring to code, don't use english words. Use code, formatted as monotype font. Don't write "If the commit message is ...". Write instead "If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sentence "then the output will display the commit message." should be imporved. What is correct is that "the dinctionary |
||||||
|
||||||
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,16 +192,18 @@ Dict{Symbol,Int64} with 2 entries: | |||||
:y => 4 | ||||||
:x => 3 | ||||||
|
||||||
julia> tag!(d) | ||||||
julia> tag!(d, commit_message=true) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
it is better syntax to separate keywords by |
||||||
Dict{Symbol,Any} with 3 entries: | ||||||
:y => 4 | ||||||
:gitmessage => "File set up by DrWatson" | ||||||
:gitcommit => "96df587e45b29e7a46348a3d780db1f85f41de04" | ||||||
:x => 3 | ||||||
``` | ||||||
""" | ||||||
function tag!(d::AbstractDict{K,T}; | ||||||
gitpath = projectdir(), force = false, source = nothing, | ||||||
storepatch::Bool = readenv("DRWATSON_STOREPATCH", false), | ||||||
commit_message::Bool = false | ||||||
Datseris marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
) 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 +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) | ||||||
|
||||||
if haskey(d, commitname) && !force | ||||||
@warn "The dictionary already has a key named `gitcommit`. We won't "* | ||||||
|
@@ -222,6 +227,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 +245,8 @@ function tag!(d::AbstractDict{K,T}; | |||||
return d | ||||||
end | ||||||
|
||||||
|
||||||
|
||||||
""" | ||||||
keyname(d::AbstractDict{K,T}, key) where {K<:Union{Symbol,String},T} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,18 +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, nothing) # variable unset | ||
_test_tag!(d, path, false, "") # variable set but empty | ||
_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, "0") # variable parses as false | ||
_test_tag!(d, path, 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, "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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test block is wrong unfortunately. You need to test the Please call the
Not calling the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't alter any of the previous code. It is simply not worth it. Why not just add this new test code block, that just has 5 lines of code, and does the test? Simpler = better. (Sure, there could be ways to alter the previous code, but why do it though? just make a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow it didn't work for me............. |
||
end | ||
end | ||
|
||
# Ensure that the correct git message show up | ||
d_new = tag!(d, gitpath=dpath, commit_message = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't test anything, see above. |
||
|
||
|
||
# Ensure that above tests operated out-of-place. | ||
@test d1 == Dict(:x => 3, :y => 4) | ||
@test d2 == Dict("x" => 3, "y" => 4) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect. Restore the 4 spaces of identation, otherwise the documentation string will not register correctly.