From b1120d3810c3d47a430055945afad4b2f1e0287f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 17 Jan 2022 18:58:12 -0800 Subject: [PATCH] Add EnableFsyncGitDir to enable synchronized writes to the gitdir (#874) (#876) This adds support for the GIT_OPT_ENABLE_FSYNC_GITDIR option in libgit2. Co-authored-by: James Fargher (cherry picked from commit 1fcc9d87430e41cc333ce5b2431df7058e03bbb7) Co-authored-by: James Fargher --- settings.go | 8 ++++++++ settings_test.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/settings.go b/settings.go index 932561818..7f9b5b125 100644 --- a/settings.go +++ b/settings.go @@ -101,6 +101,14 @@ func EnableStrictHashVerification(enabled bool) error { } } +func EnableFsyncGitDir(enabled bool) error { + if enabled { + return setSizet(C.GIT_OPT_ENABLE_FSYNC_GITDIR, 1) + } else { + return setSizet(C.GIT_OPT_ENABLE_FSYNC_GITDIR, 0) + } +} + func CachedMemory() (current int, allowed int, err error) { return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY) } diff --git a/settings_test.go b/settings_test.go index 47eb7116e..e3761d459 100644 --- a/settings_test.go +++ b/settings_test.go @@ -65,6 +65,14 @@ func TestEnableStrictHashVerification(t *testing.T) { checkFatal(t, err) } +func TestEnableFsyncGitDir(t *testing.T) { + err := EnableFsyncGitDir(false) + checkFatal(t, err) + + err = EnableFsyncGitDir(true) + checkFatal(t, err) +} + func TestCachedMemory(t *testing.T) { current, allowed, err := CachedMemory() checkFatal(t, err)