Skip to content

Commit c27981c

Browse files
authored
Merge pull request libgit2#463 from Nivl/patch-1
Add index.Clear() to clear the index object
2 parents c740e1d + dd973b9 commit c27981c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

index.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ func (v *Index) Path() string {
145145
return ret
146146
}
147147

148+
// Clear clears the index object in memory; changes must be explicitly
149+
// written to disk for them to take effect persistently
150+
func (v *Index) Clear() error {
151+
runtime.LockOSThread()
152+
defer runtime.UnlockOSThread()
153+
154+
err := C.git_index_clear(v.ptr)
155+
runtime.KeepAlive(v)
156+
if err < 0 {
157+
return MakeGitError(err)
158+
}
159+
return nil
160+
}
161+
148162
// Add adds or replaces the given entry to the index, making a copy of
149163
// the data
150164
func (v *Index) Add(entry *IndexEntry) error {

0 commit comments

Comments
 (0)