Skip to content
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

do checkout before changing HEAD #20916

Merged
merged 4 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions base/libgit2/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,15 @@ function checkout!(repo::GitRepo, commit::AbstractString = "";
# search for commit to get a commit object
obj = GitObject(repo, GitHash(commit))
peeled = peel(GitCommit, obj)

opts = force ? CheckoutOptions(checkout_strategy = Consts.CHECKOUT_FORCE) : CheckoutOptions()
# detach commit
obj_oid = GitHash(peeled)
ref = GitReference(repo, obj_oid, force=force,
msg="libgit2.checkout: moving from $head_name to $(string(obj_oid))")

# checkout commit
checkout_tree(repo, peeled, options = opts)
checkout_tree(repo, peeled, options = force ? CheckoutOptions(checkout_strategy = Consts.CHECKOUT_FORCE) : CheckoutOptions())

GitReference(repo, obj_oid, force=force,
msg="libgit2.checkout: moving from $head_name to $(obj_oid))")

return nothing
end

"""
Expand Down
28 changes: 28 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,34 @@ mktempdir() do dir
end
end


if is_unix()
@testset "checkout/proptest" begin
repo = LibGit2.GitRepo(test_repo)
try
cp(joinpath(test_repo, test_file), joinpath(test_repo, "proptest"))
LibGit2.add!(repo, "proptest")
id1 = LibGit2.commit(repo, "test property change 1")
# change in file permissions (#17610)
chmod(joinpath(test_repo, "proptest"),0o744)
LibGit2.add!(repo, "proptest")
id2 = LibGit2.commit(repo, "test property change 2")
LibGit2.checkout!(repo, string(id1))
@test !LibGit2.isdirty(repo)
# change file to symlink (#18420)
mv(joinpath(test_repo, "proptest"), joinpath(test_repo, "proptest2"))
symlink(joinpath(test_repo, "proptest2"), joinpath(test_repo, "proptest"))
LibGit2.add!(repo, "proptest", "proptest2")
id3 = LibGit2.commit(repo, "test symlink change")
LibGit2.checkout!(repo, string(id1))
@test !LibGit2.isdirty(repo)
finally
close(repo)
end
end
end


@testset "Credentials" begin
creds_user = "USER"
creds_pass = "PASS"
Expand Down