Skip to content

Commit 8619307

Browse files
simonbyrnetkelman
authored andcommitted
do checkout before changing HEAD (#20916)
* do checkout before changing HEAD 541d94b * add test for change to file permissions 42493ae * add test for symlinks a3fab6b * add issue numbers to comments 1b7d47a change close(repo) to finalize(repo) for release-0.5
1 parent 468974c commit 8619307

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

base/libgit2/libgit2.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ function checkout!(repo::GitRepo, commit::AbstractString = "";
292292
opts = force ? CheckoutOptions(checkout_strategy = Consts.CHECKOUT_FORCE) :
293293
CheckoutOptions()
294294
try
295+
# checkout commit
296+
checkout_tree(repo, peeled, options = opts)
297+
295298
# detach commit
296299
obj_oid = Oid(peeled)
297300
ref = GitReference(repo, obj_oid, force=force,
298301
msg="libgit2.checkout: moving from $head_name to $(string(obj_oid))")
299302
finalize(ref)
300-
301-
# checkout commit
302-
checkout_tree(repo, peeled, options = opts)
303303
finally
304304
finalize(peeled)
305305
end

test/libgit2.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,33 @@ mktempdir() do dir
653653
end
654654
#end
655655

656+
657+
if is_unix()
658+
#@testset "checkout/proptest" begin
659+
repo = LibGit2.GitRepo(test_repo)
660+
try
661+
cp(joinpath(test_repo, test_file), joinpath(test_repo, "proptest"))
662+
LibGit2.add!(repo, "proptest")
663+
id1 = LibGit2.commit(repo, "test property change 1")
664+
# change in file permissions (#17610)
665+
chmod(joinpath(test_repo, "proptest"),0o744)
666+
LibGit2.add!(repo, "proptest")
667+
id2 = LibGit2.commit(repo, "test property change 2")
668+
LibGit2.checkout!(repo, string(id1))
669+
@test !LibGit2.isdirty(repo)
670+
# change file to symlink (#18420)
671+
mv(joinpath(test_repo, "proptest"), joinpath(test_repo, "proptest2"))
672+
symlink(joinpath(test_repo, "proptest2"), joinpath(test_repo, "proptest"))
673+
LibGit2.add!(repo, "proptest", "proptest2")
674+
id3 = LibGit2.commit(repo, "test symlink change")
675+
LibGit2.checkout!(repo, string(id1))
676+
@test !LibGit2.isdirty(repo)
677+
finally
678+
finalize(repo)
679+
end
680+
#end
681+
end
682+
656683
#@testset "Credentials" begin
657684
creds_user = "USER"
658685
creds_pass = "PASS"

0 commit comments

Comments
 (0)