-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix some LibGit2 errors #20155
fix some LibGit2 errors #20155
Changes from 2 commits
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 |
---|---|---|
|
@@ -75,18 +75,22 @@ end | |
isdirty(repo::GitRepo, paths::AbstractString=""; cached::Bool=false) = | ||
isdiff(repo, Consts.HEAD_FILE, paths, cached=cached) | ||
|
||
""" git diff-index <treeish> [-- <path>]""" | ||
""" | ||
LibGit2.isdiff(repo::GitRepo, treeish[, paths]; [cached=false]) | ||
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. I don't think we typically put keyword arguments in brackets in docstrings? |
||
|
||
Checks if there are any differences between the tree specified by `treeish` and working tree (if `cached=false`) or the index (if `cached=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. Would be nice to break onto multiple lines to keep the line length down. |
||
|
||
See `git diff-index <treeish> [-- <path>]` | ||
""" | ||
function isdiff(repo::GitRepo, treeish::AbstractString, paths::AbstractString=""; cached::Bool=false) | ||
tree_oid = revparseid(repo, "$treeish^{tree}") | ||
iszero(tree_oid) && return true | ||
iszero(tree_oid) && return error("invalid treeish $treeish") # this can be removed by #20104 | ||
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. Perhaps just 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 is a stopgap, will get removed after we merge #20104 |
||
result = false | ||
tree = get(GitTree, repo, tree_oid) | ||
try | ||
diff = diff_tree(repo, tree, paths) | ||
diff = diff_tree(repo, tree, paths, cached=cached) | ||
result = count(diff) > 0 | ||
close(diff) | ||
catch err | ||
result = true | ||
finally | ||
close(tree) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -452,6 +452,36 @@ mktempdir() do dir | |
close(repo) | ||
end | ||
end | ||
|
||
@testset "diff" begin | ||
repo = LibGit2.GitRepo(cache_repo) | ||
try | ||
@test !LibGit2.isdirty(repo) | ||
@test !LibGit2.isdiff(repo, "HEAD") | ||
@test !LibGit2.isdirty(repo, cached=true) | ||
@test !LibGit2.isdiff(repo, "HEAD", cached=true) | ||
open(joinpath(cache_repo,test_file), "a") do f | ||
println(f, "zzzz") | ||
end | ||
@test LibGit2.isdirty(repo) | ||
@test LibGit2.isdiff(repo, "HEAD") | ||
@test !LibGit2.isdirty(repo, cached=true) | ||
@test !LibGit2.isdiff(repo, "HEAD", cached=true) | ||
LibGit2.add!(repo, test_file) | ||
@test LibGit2.isdirty(repo) | ||
@test LibGit2.isdiff(repo, "HEAD") | ||
@test LibGit2.isdirty(repo, cached=true) | ||
@test LibGit2.isdiff(repo, "HEAD", cached=true) | ||
LibGit2.commit(repo, "zzz") | ||
@test !LibGit2.isdirty(repo) | ||
@test !LibGit2.isdiff(repo, "HEAD") | ||
@test !LibGit2.isdirty(repo, cached=true) | ||
@test !LibGit2.isdiff(repo, "HEAD", cached=true) | ||
finally | ||
close(repo) | ||
end | ||
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. I think typically we don't put line breaks between |
||
end | ||
|
||
@testset "Fetch from cache repository" begin | ||
|
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.
boundserror doesn't take a string, does it?
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.
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.
Fixed.