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)
| 729 | // IsIgnored reports whether the given path is ignored by .gitignore rules. |
| 730 | // Returns an error for fatal git failures (e.g. path outside repository). |
| 731 | func (c *Client) IsIgnored(ctx context.Context, path string) (bool, error) { |
| 732 | cmd, err := c.Command(ctx, "check-ignore", "-q", "--", path) |
| 733 | if err != nil { |
| 734 | return false, err |
| 735 | } |
| 736 | _, err = cmd.Output() |
| 737 | if err == nil { |
| 738 | return true, nil |
| 739 | } |
| 740 | // Exit 1 here means we can confirm the path is not ignored. |
| 741 | // Any other error is a real git error. |
| 742 | var exitErr *exec.ExitError |
| 743 | if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 { |
| 744 | return false, nil |
| 745 | } |
| 746 | return false, err |
| 747 | } |
| 748 | |
| 749 | // ShortSHA returns the first 8 characters of a SHA hash for display purposes. |
| 750 | func ShortSHA(sha string) string { |