MCPcopy Create free account
hub / github.com/cli/cli / IsIgnored

Method IsIgnored

git/client.go:793–809  ·  view source on GitHub ↗

IsIgnored reports whether the given path is ignored by .gitignore rules. Returns an error for fatal git failures (e.g. path outside repository).

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

791// IsIgnored reports whether the given path is ignored by .gitignore rules.
792// Returns an error for fatal git failures (e.g. path outside repository).
793func (c *Client) IsIgnored(ctx context.Context, path string) (bool, error) {
794 cmd, err := c.Command(ctx, "check-ignore", "-q", "--", path)
795 if err != nil {
796 return false, err
797 }
798 _, err = cmd.Output()
799 if err == nil {
800 return true, nil
801 }
802 // Exit 1 here means we can confirm the path is not ignored.
803 // Any other error is a real git error.
804 var exitErr *exec.ExitError
805 if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {
806 return false, nil
807 }
808 return false, err
809}
810
811// ShortSHA returns the first 8 characters of a SHA hash for display purposes.
812func ShortSHA(sha string) string {

Callers 2

TestClientIsIgnoredFunction · 0.95
checkInstalledSkillDirsFunction · 0.80

Calls 3

CommandMethod · 0.95
OutputMethod · 0.65
ExitCodeMethod · 0.65

Tested by 1

TestClientIsIgnoredFunction · 0.76