From 4647e3da5b15c6d49c9a7d15107132b7c8f1ab55 Mon Sep 17 00:00:00 2001 From: Gavin Ray Date: Sun, 2 Jul 2023 18:22:39 -0400 Subject: [PATCH] Add negated-pattern support for .gptignore --- gpt_repository_loader.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gpt_repository_loader.py b/gpt_repository_loader.py index 57279f5..bd25747 100755 --- a/gpt_repository_loader.py +++ b/gpt_repository_loader.py @@ -15,7 +15,11 @@ def get_ignore_list(ignore_file_path): def should_ignore(file_path, ignore_list): for pattern in ignore_list: - if fnmatch.fnmatch(file_path, pattern): + if pattern.startswith("!"): + negated_pattern = pattern[1:] # Remove the negation prefix '!' + if fnmatch.fnmatch(file_path, negated_pattern): + return False + elif fnmatch.fnmatch(file_path, pattern): return True return False @@ -71,4 +75,4 @@ def process_repository(repo_path, ignore_list, output_file): with open(output_file_path, 'a') as output_file: output_file.write("--END--") print(f"Repository contents written to {output_file_path}.") - \ No newline at end of file +