From eb38aaaeeeeeddbd59ef8bc895ad098fe69b428f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 4 Jan 2019 00:43:48 +0000 Subject: [PATCH] Merge pull request #463 from Nivl/patch-1 Add index.Clear() to clear the index object (cherry picked from commit c27981c283b5e02fcbbf17cce0a3e6da9339986c) --- index.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.go b/index.go index 5106516..dd13460 100644 --- a/index.go +++ b/index.go @@ -145,6 +145,20 @@ func (v *Index) Path() string { return ret } +// Clear clears the index object in memory; changes must be explicitly +// written to disk for them to take effect persistently +func (v *Index) Clear() error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + err := C.git_index_clear(v.ptr) + runtime.KeepAlive(v) + if err < 0 { + return MakeGitError(err) + } + return nil +} + // Add adds or replaces the given entry to the index, making a copy of // the data func (v *Index) Add(entry *IndexEntry) error {