Reputation: 1905
I am trying to debug a problem for another person who has julia installed but not git. I would like to know which changes were done to a julia packages, so essentially the command git diff
.
I am wondering if I can use LibGit2 for this? These commands get me petty close:
repo = LibGit2.GitRepo(Pkg.dir("NCDatasets"))
tree = LibGit2.GitTree(repo,"HEAD^{tree}");
diff = LibGit2.diff_tree(repo,tree,"")
They return:
GitDiff:
Number of deltas: 1
GitDiffStats:
Files changed: 1
Insertions: 1
Deletions: 1
Assuming that I want to know the changes in the package NCDatasets.
So I know that one file was changed. How do I know, which one and how were this file changed?
Unfortunately, I do not get any further based on what I understood from here:
https://github.com/JuliaLang/julia/blob/master/stdlib/LibGit2/src/diff.jl
https://github.com/JuliaLang/julia/blob/master/stdlib/LibGit2/test/libgit2.jl
Upvotes: 2
Views: 297
Reputation: 69899
You can use:
julia> for i in 1:count(diff)
d = diff[i];print(d)
println(unsafe_string(d.old_file.path), "\t",
unsafe_string(d.new_file.path),"\n---\n")
end
This will print you each entry of diff
. Unfortunately standard print
for DiffFile
does not print file name so I have added printing it below the standard print.
Notice, however, that this diff
will not contain untracked files. The simplest way to catch them is to use LibGit2.status
function and traverse all files in your repository using walkdir
. This method also has its drawback as it will not detect deleted files which diff
will contain. It should be possible to write a function that catches all cases by combining the both approaches.
Upvotes: 1