From 800edc61bf1616f10c5182ddea7c752dee07a6d4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2020 18:44:37 -0800 Subject: [PATCH] feat: Implement an option to control hash verification (#671) (#673) Add a binding to enable/disable hash verification using the `GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION` option. Change type: #minor (cherry picked from commit c3664193f3c05bd6ae48f153c6c41cd7d7a3d98b) Co-authored-by: Suhaib Mujahid --- settings.go | 8 ++++++++ settings_test.go | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/settings.go b/settings.go index 2472908..f278e7b 100644 --- a/settings.go +++ b/settings.go @@ -93,6 +93,14 @@ func EnableCaching(enabled bool) error { } } +func EnableStrictHashVerification(enabled bool) error { + if enabled { + return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1) + } else { + return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 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 150ee7c..47eb711 100644 --- a/settings_test.go +++ b/settings_test.go @@ -57,6 +57,14 @@ func TestEnableCaching(t *testing.T) { checkFatal(t, err) } +func TestEnableStrictHashVerification(t *testing.T) { + err := EnableStrictHashVerification(false) + checkFatal(t, err) + + err = EnableStrictHashVerification(true) + checkFatal(t, err) +} + func TestCachedMemory(t *testing.T) { current, allowed, err := CachedMemory() checkFatal(t, err) @@ -80,4 +88,4 @@ func TestSetCacheMaxSize(t *testing.T) { // revert to default 256MB err = SetCacheMaxSize(256 * 1024 * 1024) checkFatal(t, err) -} \ No newline at end of file +}