Skip to content

Commit 310b6dd

Browse files
kshyattararslan
authored andcommitted
Add example for iscommit and reset! (#21734)
1 parent 1eef027 commit 310b6dd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

base/libgit2/libgit2.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ end
7272
7373
Checks if commit `id` (which is a [`GitHash`](@ref) in string form)
7474
is in the repository.
75+
76+
# Example
77+
78+
```julia
79+
julia> repo = LibGit2.GitRepo(repo_path);
80+
81+
julia> LibGit2.add!(repo, test_file);
82+
83+
julia> commit_oid = LibGit2.commit(repo, "add test_file");
84+
85+
julia> LibGit2.iscommit(string(commit_oid), repo)
86+
true
87+
```
7588
"""
7689
function iscommit(id::AbstractString, repo::GitRepo)
7790
res = true
@@ -573,6 +586,21 @@ set by `mode`:
573586
3. `Consts.RESET_HARD` - move HEAD to `id`, reset the index to `id`, and discard all working changes.
574587
575588
Equivalent to `git reset [--soft | --mixed | --hard] <id>`.
589+
590+
# Example
591+
592+
```julia
593+
repo = LibGit2.GitRepo(repo_path)
594+
head_oid = LibGit2.head_oid(repo)
595+
open(joinpath(repo_path, "file1"), "w") do f
596+
write(f, "111\n")
597+
end
598+
LibGit2.add!(repo, "file1")
599+
mode = LibGit2.Consts.RESET_HARD
600+
# will discard the changes to file1
601+
# and unstage it
602+
new_head = LibGit2.reset!(repo, head_oid, mode)
603+
```
576604
"""
577605
reset!(repo::GitRepo, id::GitHash, mode::Cint = Consts.RESET_MIXED) =
578606
reset!(repo, GitObject(repo, id), mode)

0 commit comments

Comments
 (0)