feat: Add git tracking check for untracked files with helpful error message

This commit is contained in:
n loewen (aider) 2025-06-08 01:53:10 +01:00
parent ed75b6fd37
commit 49bc53d16d
1 changed files with 14 additions and 0 deletions

14
gtm
View File

@ -13,6 +13,12 @@ VERSION = "2025-06-07.3"
# --- Data Fetching & Utility Functions (Pure) ---
def is_file_tracked_by_git(filename):
"""Check if a file is tracked by git."""
cmd = ['git', 'ls-files', '--error-unmatch', filename]
result = subprocess.run(cmd, capture_output=True, text=True)
return result.returncode == 0
def get_commits(filename):
cmd = ['git', 'log', '--pretty=format:%h %ad %s', '--date=format:%Y-%m-%d %H:%M', '--', filename]
result = subprocess.run(cmd, capture_output=True, text=True)
@ -765,5 +771,13 @@ if __name__ == "__main__":
if not os.path.isfile(filename):
print(f"Error: File '{filename}' does not exist")
sys.exit(1)
if not is_file_tracked_by_git(filename):
print(f"Error: File '{filename}' is not tracked by git")
print("Only files that are tracked in the git repository can be viewed.")
print("Try adding and committing the file first:")
print(f" git add {filename}")
print(f" git commit -m 'Add {os.path.basename(filename)}'")
sys.exit(1)
curses.wrapper(main, filename, args.diff, args.diff_additions, args.diff_deletions, not args.no_mouse, not args.no_wrap)