Esempio n. 1
0
// uses the --check option in git-diff to check for invalid whitespace
func (f *fileToCheck) GitDiffCheck() error {
	out, err := git.Command("diff", "--check", "--cached", "--color=always", "--", f.Path)
	if err != nil {
		return fmt.Errorf("git-diff --check failed:\n%s", indentLines(out, 1))
	}

	return nil
}
Esempio n. 2
0
// verifies certain keywords aren't being added
func (f *fileToCheck) VerifyNoUncommittables() error {
	out, err := git.Command("diff", "--exit-code", "--cached", "--color=always", "--", f.Path)
	if err == nil {
		return nil
	}

	for _, line := range bytes.Split(out, []byte("\n")) {
		if uncommitablesRegexp.Match(line) {
			return fmt.Errorf("forbidden string found:\n%s", indentLines(out, 1))
		}
	}

	return nil
}
Esempio n. 3
0
// Assemble list of files to check. Ask git which files have changes and weren't deleted
func changedFiles(results chan<- *fileToCheck) {
	defer close(results)

	out, err := git.Command("diff-index", "HEAD", "--cached", "--name-only", "-z", "--diff-filter=ACRMT")
	if err != nil {
		fmt.Printf("ERROR: git-diff-index: %s\n%s\n", err, out)
		os.Exit(2)
		// FIXME: This explodes for first commit
	}

	for _, chunk := range bytes.Split(out, []byte{'\x00'}) {
		if len(chunk) == 0 {
			continue
		}

		results <- &fileToCheck{Path: string(chunk)}
	}
}