Skip to content

Commit

Permalink
Add example for iscommit and reset! (JuliaLang#21734)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt authored and ararslan committed May 8, 2017
1 parent 1eef027 commit 310b6dd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions base/libgit2/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ end
Checks if commit `id` (which is a [`GitHash`](@ref) in string form)
is in the repository.
# Example
```julia
julia> repo = LibGit2.GitRepo(repo_path);
julia> LibGit2.add!(repo, test_file);
julia> commit_oid = LibGit2.commit(repo, "add test_file");
julia> LibGit2.iscommit(string(commit_oid), repo)
true
```
"""
function iscommit(id::AbstractString, repo::GitRepo)
res = true
Expand Down Expand Up @@ -573,6 +586,21 @@ set by `mode`:
3. `Consts.RESET_HARD` - move HEAD to `id`, reset the index to `id`, and discard all working changes.
Equivalent to `git reset [--soft | --mixed | --hard] <id>`.
# Example
```julia
repo = LibGit2.GitRepo(repo_path)
head_oid = LibGit2.head_oid(repo)
open(joinpath(repo_path, "file1"), "w") do f
write(f, "111\n")
end
LibGit2.add!(repo, "file1")
mode = LibGit2.Consts.RESET_HARD
# will discard the changes to file1
# and unstage it
new_head = LibGit2.reset!(repo, head_oid, mode)
```
"""
reset!(repo::GitRepo, id::GitHash, mode::Cint = Consts.RESET_MIXED) =
reset!(repo, GitObject(repo, id), mode)
Expand Down

0 comments on commit 310b6dd

Please sign in to comment.