diff --git a/gtm b/gtm index 177e9a9..fffd13e 100755 --- a/gtm +++ b/gtm @@ -20,7 +20,7 @@ def is_file_tracked_by_git(filename): return result.returncode == 0 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:%ad %s', '--date=format:%Y-%m-%d %H:%M', '--', filename] result = subprocess.run(cmd, capture_output=True, text=True) return result.stdout.splitlines() @@ -272,12 +272,19 @@ def load_commit_content(state: AppState) -> AppState: if state.right_scroll_offset < len(state.file_lines): reference_line = state.file_lines[state.right_scroll_offset] - commit_hash = state.commits[state.selected_commit_idx].split()[0] + # Get the commit hash using git log with the same format but including hash + cmd = ['git', 'log', '--pretty=format:%h', '--date=format:%Y-%m-%d %H:%M', '--skip=' + str(state.selected_commit_idx), '-n', '1', '--', state.filename] + result = subprocess.run(cmd, capture_output=True, text=True) + commit_hash = result.stdout.strip() + file_lines = get_file_at_commit(commit_hash, state.filename) prev_commit_hash = None if state.selected_commit_idx < len(state.commits) - 1: - prev_commit_hash = state.commits[state.selected_commit_idx + 1].split()[0] + # Get the previous commit hash + cmd = ['git', 'log', '--pretty=format:%h', '--date=format:%Y-%m-%d %H:%M', '--skip=' + str(state.selected_commit_idx + 1), '-n', '1', '--', state.filename] + result = subprocess.run(cmd, capture_output=True, text=True) + prev_commit_hash = result.stdout.strip() if state.show_additions or state.show_deletions: added_lines, deleted_lines = get_diff_info(commit_hash, prev_commit_hash, state.filename) @@ -289,8 +296,8 @@ def load_commit_content(state: AppState) -> AppState: # Get commit message from the commit line commit_line = state.commits[state.selected_commit_idx] - parts = commit_line.split(' ', 3) # Split into hash, date, time, message - short_message = parts[3] if len(parts) >= 4 else "" + parts = commit_line.split(' ', 3) # Split into date, time, message + short_message = parts[2] if len(parts) >= 3 else "" # If commit_details['message'] is empty, use short_message as fallback if not commit_details['message'].strip():