Skip to content

Commit 29ffcb6

Browse files
mauro3Datseris
authored andcommitted
Replace GitRepo -> GitRepoExt to get repo also when using sub-dirs (#81)
* Replace GitRepo -> GitRepoExt to get repo also when using sub-dirs * Update CHANGELOG (also for PR#80) [ci skip] * merge changelogs
1 parent aebb2c1 commit 29ffcb6

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# 0.8.0
2+
* **[BREAKING]** : The `gitpath` argument used among many functions
3+
can now also point to a subdirectory within a git repository.
4+
Previously it had to be the top directory (i.e. the one containing
5+
`.git/`).
26
* **[BREAKING]** : Slightly changed how `produce_or_load` uses `path` and interacts with `savename`, to better incorporate the changes done in version 0.6.0. `prefix` is now also supported.
3-
* `tag!` and co now also store the git diff patch if the repo is dirty (#80).
7+
* `tag!` and co now also store the git diff patch if the repo is dirty, see `gitpatch` (#80).
48
* **[BREAKING]** : `tag!` now saves the commit information into a field `gitcommit` instead of just `commit`.
59

610
# 0.7.1

src/saving_tools.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ in `gitpath`, which by default is the currently active project. If the repositor
1010
is dirty when this function is called the string will end
1111
with `"_dirty"`.
1212
13-
Return `nothing` if `gitpath` is not a Git repository.
13+
Return `nothing` if `gitpath` is not a Git repository, i.e. a directory within a git
14+
repository.
1415
1516
The format of the `git describe` output in general is
1617
@@ -41,7 +42,7 @@ julia> gitdescribe(path_to_a_dirty_repo)
4142
function gitdescribe(gitpath = projectdir())
4243
# Here we test if the gitpath is a git repository.
4344
try
44-
repo = LibGit2.GitRepo(gitpath)
45+
repo = LibGit2.GitRepoExt(gitpath)
4546
catch er
4647
@warn "The directory ('$gitpath') is not a Git repository, "*
4748
"returning `nothing` instead of the commit ID."
@@ -54,7 +55,7 @@ function gitdescribe(gitpath = projectdir())
5455
end
5556
# then we return the output of `git describe` or the latest commit hash
5657
# if no annotated tags are available
57-
repo = LibGit2.GitRepo(gitpath)
58+
repo = LibGit2.GitRepoExt(gitpath)
5859
c = try
5960
gdr = LibGit2.GitDescribeResult(repo)
6061
fopt = LibGit2.DescribeFormatOptions(dirty_suffix=pointer(suffix))
@@ -70,10 +71,12 @@ end
7071
7172
Generates a patch describing the changes of a dirty repository
7273
compared to its last commit; i.e. what `git diff HEAD` produces.
74+
The `gitpath` needs to point to a directory within a git repository,
75+
otherwise `nothing` is returned.
7376
"""
7477
function gitpatch(gitpath = projectdir())
7578
try
76-
repo = LibGit2.GitRepo(gitpath)
79+
repo = LibGit2.GitRepoExt(gitpath)
7780
catch er
7881
@warn "The directory ('$gitpath') is not a Git repository, "*
7982
"returning `nothing` instead of a patch."
@@ -83,7 +86,7 @@ function gitpatch(gitpath = projectdir())
8386
# diff = LibGit2.diff_tree(repo, tree)
8487
# now there is no way to generate the patch with LibGit2.jl.
8588
# Instead use commands:
86-
patch = read(`git --git-dir=$(gitpath)/.git diff HEAD`, String)
89+
patch = read(`git -C $(gitpath) diff HEAD`, String)
8790
return patch
8891
end
8992

test/stools_tests.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using DrWatson, Test
22

33
# Test commit function
44
com = gitdescribe(@__DIR__)
5-
@test com === nothing
5+
@test com isa String
66

77
com = gitdescribe(dirname(@__DIR__))
88
@test com !== nothing
@@ -12,7 +12,7 @@ com = gitdescribe(dirname(@__DIR__))
1212
d1 = Dict(:x => 3, :y => 4)
1313
d2 = Dict("x" => 3, "y" => 4)
1414
for d in (d1, d2)
15-
d = tag!(d, dirname(@__DIR__))
15+
d = tag!(d, @__DIR__)
1616

1717
@test haskey(d, keytype(d)(:gitcommit))
1818
@test d[keytype(d)(:gitcommit)] |> typeof <: String
@@ -21,11 +21,9 @@ end
2121
# @tag!
2222
for d in (d1, d2)
2323
d = @tag!(d, @__DIR__)
24-
@test !haskey(d, keytype(d)(:gitcommit))
25-
26-
d = @tag!(d, dirname(@__DIR__))
24+
@test haskey(d, keytype(d)(:gitcommit))
2725
@test d[keytype(d)(:gitcommit)] |> typeof <: String
28-
@test d[keytype(d)(:script)][1:4] == "test"
26+
@test split(d[keytype(d)(:script)], '#')[1] == basename(@__FILE__)
2927
end
3028

3129
# Test dictionary expansion

0 commit comments

Comments
 (0)