feat: Add git tracking check for untracked files with helpful error message
This commit is contained in:
parent
ed75b6fd37
commit
49bc53d16d
14
gtm
14
gtm
|
|
@ -13,6 +13,12 @@ VERSION = "2025-06-07.3"
|
||||||
|
|
||||||
# --- Data Fetching & Utility Functions (Pure) ---
|
# --- 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):
|
def get_commits(filename):
|
||||||
cmd = ['git', 'log', '--pretty=format:%h %ad %s', '--date=format:%Y-%m-%d %H:%M', '--', 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)
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
|
|
@ -765,5 +771,13 @@ if __name__ == "__main__":
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
print(f"Error: File '{filename}' does not exist")
|
print(f"Error: File '{filename}' does not exist")
|
||||||
sys.exit(1)
|
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)
|
curses.wrapper(main, filename, args.diff, args.diff_additions, args.diff_deletions, not args.no_mouse, not args.no_wrap)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue