Skip to content

Commit cf0567b

Browse files
authored
Fix drwatson as author for project setup git commits (#299)
* Use keyword author for project setup git commits * Test initialize_project keeps git config * Increment patch version
1 parent 599a9b2 commit cf0567b

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DrWatson"
22
uuid = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
33
repo = "https://github.com/JuliaDynamics/DrWatson.jl.git"
4-
version = "2.7.0"
4+
version = "2.7.1"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/project_setup.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,8 @@ function initialize_project(path, name = default_name_from_path(path);
274274

275275
if git
276276
repo = LibGit2.init(path)
277-
gc = LibGit2.GitConfig(repo)
278-
LibGit2.get(gc, "user.name", LibGit2.getconfig("user.name", false)) ||
279-
LibGit2.set!(gc, "user.name", "DrWatson")
280-
LibGit2.get(gc, "user.email", LibGit2.getconfig("user.email", false)) ||
281-
LibGit2.set!(gc, "user.email", "no@mail")
282-
LibGit2.commit(repo, "Initial commit")
277+
sig = LibGit2.Signature("DrWatson", "no@mail", round(Int, time()), 0)
278+
LibGit2.commit(repo, "Initial commit"; author=sig, committer=sig)
283279
end
284280

285281
Pkg.activate(path)
@@ -293,11 +289,14 @@ function initialize_project(path, name = default_name_from_path(path);
293289
# Instantiate template
294290
folders, ph_files = insert_folders(path, template, placeholder)
295291

296-
git && LibGit2.add!(repo, "Project.toml")
297-
git && LibGit2.add!(repo, "Manifest.toml")
298-
git && LibGit2.add!(repo, folders...)
299-
placeholder && git && LibGit2.add!(repo, ph_files...)
300-
git && LibGit2.commit(repo, "Folder setup by DrWatson")
292+
if git
293+
LibGit2.add!(repo, "Project.toml")
294+
LibGit2.add!(repo, "Manifest.toml")
295+
LibGit2.add!(repo, folders...)
296+
placeholder && LibGit2.add!(repo, ph_files...)
297+
sig = LibGit2.Signature("DrWatson", "no@mail", round(Int, time()), 0)
298+
LibGit2.commit(repo, "Folder setup by DrWatson"; author=sig, committer=sig)
299+
end
301300

302301
# Default files
303302
# chmod is needed, as the file permissions are not set correctly when adding the package with `add`.
@@ -320,8 +319,11 @@ function initialize_project(path, name = default_name_from_path(path);
320319
w *= compat_entry()
321320
write(joinpath(path, "Project.toml"), w, pro)
322321
push!(files, "Project.toml")
323-
git && LibGit2.add!(repo, files...)
324-
git && LibGit2.commit(repo, "File setup by DrWatson")
322+
if git
323+
LibGit2.add!(repo, files...)
324+
sig = LibGit2.Signature("DrWatson", "no@mail", round(Int, time()), 0)
325+
LibGit2.commit(repo, "File setup by DrWatson"; author=sig, committer=sig)
326+
end
325327
return path
326328
end
327329

test/project_tests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Pkg, Test, DrWatson
22
using LibGit2
33
LibGit2.default_signature() = LibGit2.Signature("TEST", "TEST@TEST.COM", round(time(), 0), 0)
4+
global_user_name = LibGit2.getconfig("user.name", "")
5+
global_user_email = LibGit2.getconfig("user.email", "")
46

57
cd(@__DIR__)
68
path = "test project"
@@ -12,6 +14,9 @@ Pkg.activate()
1214
# @test DrWatson.is_standard_julia_project() # we cant test this on CI
1315

1416
initialize_project(path, force = true)
17+
repo = LibGit2.GitRepo(path)
18+
@test LibGit2.getconfig(repo, "user.name", "") == global_user_name
19+
@test LibGit2.getconfig(repo, "user.email", "") == global_user_email
1520

1621
cd(path) do
1722
@test DrWatson.default_name_from_path(".") == path
@@ -45,6 +50,9 @@ end
4550
@test_throws ErrorException initialize_project(path, name)
4651

4752
initialize_project(path, name; force = true, authors = ["George", "Nick"])
53+
repo = LibGit2.GitRepo(path)
54+
@test LibGit2.getconfig(repo, "user.name", "") == global_user_name
55+
@test LibGit2.getconfig(repo, "user.email", "") == global_user_email
4856
# test gitdescribe:
4957
com = gitdescribe(path)
5058
@test !occursin('-', com) # no dashes = no git describe

0 commit comments

Comments
 (0)