diff --git a/gtm b/gtm index d813085..69914c9 100755 --- a/gtm +++ b/gtm @@ -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)