Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow retrieving/setting repository owner validation #913

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ func SetCacheObjectLimit(objectType ObjectType, size int) error {
return nil
}

func OwnerValidation() (enabled bool, err error) {
val, err := getSizet(C.GIT_OPT_GET_OWNER_VALIDATION)
if val == 1 {
return true, err
}
return false, err
}

func SetOwnerValidation(enabled bool) error {
if enabled {
return setSizet(C.GIT_OPT_SET_OWNER_VALIDATION, 1)
} else {
return setSizet(C.GIT_OPT_SET_OWNER_VALIDATION, 0)
}
}

func getSizet(opt C.int) (int, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
Expand Down
24 changes: 24 additions & 0 deletions settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,27 @@ func TestSetCacheMaxSize(t *testing.T) {
err = SetCacheMaxSize(256 * 1024 * 1024)
checkFatal(t, err)
}

func TestOwnerValidation(t *testing.T) {
enabled, err := OwnerValidation()
checkFatal(t, err)

err = SetOwnerValidation(!enabled)
checkFatal(t, err)

var enabled2 bool
enabled2, err = OwnerValidation()
checkFatal(t, err)

if enabled == enabled2 {
t.Fatal("set owner validation failed")
}
}

func TestSetOwnerValidation(t *testing.T) {
err := SetOwnerValidation(false)
checkFatal(t, err)

err = SetOwnerValidation(true)
checkFatal(t, err)
}