#!/usr/bin/python import subprocess import sys import os from os import path # Find the git root directory cwd = os.getcwd() while (".git" not in os.listdir(cwd)) and cwd != "/": cwd = path.dirname(cwd) if cwd == "/": print("Could not find the git repository root") sys.exit(1) # Run the metalinter commands from the root directory os.chdir(cwd) files = subprocess.check_output(["git", "diff", "--name-only"]) files_list = files.splitlines() if len(files_list) == 0: sys.exit(0) dirs_list = map(path.dirname, files_list) dirs_list = set(dirs_list) for dir in dirs_list: subprocess.call(["gometalinter", dir])