Skip to content

Commit

Permalink
Add --use-git-ignore option (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiokuless authored Aug 10, 2023
1 parent 4fcbb1b commit af5bf14
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions norminette/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import _thread
from threading import Event
import time
import subprocess


has_err = False
Expand Down Expand Up @@ -71,6 +72,11 @@ def main():
action="store",
help="Stores filename if --cfile or --hfile is passed",
)
parser.add_argument(
"--use-gitignore",
action="store_true",
help="Parse only source files not match to .gitignore",
)
parser.add_argument("-R", nargs=1, help="compatibility for norminette 2")
args = parser.parse_args()
registry = Registry()
Expand Down Expand Up @@ -99,6 +105,27 @@ def main():
targets.extend(glob.glob(arg + "**/*.[ch]", recursive=True))
elif os.path.isfile(arg):
targets.append(arg)

if args.use_gitignore:
tmp_targets = []
for target in targets:
command = ["git", "check-ignore", "-q", target]
exit_code = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode
"""
see: $ man git-check-ignore
EXIT STATUS
0: One or more of the provided paths is ignored.
1: None of the provided paths are ignored.
128: A fatal error was encountered.
"""
if exit_code == 0:
pass
elif exit_code == 1:
tmp_targets.append(target)
elif exit_code == 128:
print(f'Error: something wrong with --use-gitignore option {target}')
sys.exit(0)
targets = tmp_targets
event = []
for target in filter(os.path.isfile, targets):
if target[-2:] not in [".c", ".h"]:
Expand Down

0 comments on commit af5bf14

Please sign in to comment.