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

Method IsIgnored

git/client.go:791–807  ·  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

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

Calls 3

CommandMethod · 0.95
OutputMethod · 0.65
ExitCodeMethod · 0.65