File: ignore.go

package info (click to toggle)
golang-github-libgit2-git2go 34.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 920 kB
  • sloc: ansic: 471; sh: 85; makefile: 39
file content (54 lines) | stat: -rw-r--r-- 998 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package git

/*
#include <git2.h>
*/
import "C"
import (
	"runtime"
	"unsafe"
)

func (v *Repository) AddIgnoreRule(rules string) error {
	crules := C.CString(rules)
	defer C.free(unsafe.Pointer(crules))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_ignore_add_rule(v.ptr, crules)
	runtime.KeepAlive(v)
	if ret < 0 {
		return MakeGitError(ret)
	}
	return nil
}

func (v *Repository) ClearInternalIgnoreRules() error {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_ignore_clear_internal_rules(v.ptr)
	runtime.KeepAlive(v)
	if ret < 0 {
		return MakeGitError(ret)
	}
	return nil
}

func (v *Repository) IsPathIgnored(path string) (bool, error) {
	var ignored C.int

	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_ignore_path_is_ignored(&ignored, v.ptr, cpath)
	runtime.KeepAlive(v)
	if ret < 0 {
		return false, MakeGitError(ret)
	}
	return ignored == 1, nil
}