From 310b6ddbdceab9c0d7bf3c8a8790d6dabc8c23ba Mon Sep 17 00:00:00 2001 From: Katharine Hyatt <kshyatt@users.noreply.github.com> Date: Mon, 8 May 2017 10:10:37 -0700 Subject: [PATCH] Add example for iscommit and reset! (#21734) --- base/libgit2/libgit2.jl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index 6b704768be3f2..c8ba346ec52f1 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -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 @@ -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)