git-visual-timeline 0.2.4__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {git_visual_timeline-0.2.4/src/git_visual_timeline.egg-info → git_visual_timeline-0.2.5}/PKG-INFO +1 -1
  2. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/pyproject.toml +1 -1
  3. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5/src/git_visual_timeline.egg-info}/PKG-INFO +1 -1
  4. git_visual_timeline-0.2.5/src/gvt/__init__.py +1 -0
  5. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/app.py +5 -4
  6. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/git/repo.py +16 -4
  7. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/changed_files.py +4 -1
  8. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/file_tree.py +4 -2
  9. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/modals.py +3 -2
  10. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/status_bar.py +3 -1
  11. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_hostile_repo.py +92 -0
  12. git_visual_timeline-0.2.4/src/gvt/__init__.py +0 -1
  13. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/LICENSE +0 -0
  14. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/README.md +0 -0
  15. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/setup.cfg +0 -0
  16. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/git_visual_timeline.egg-info/SOURCES.txt +0 -0
  17. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/git_visual_timeline.egg-info/dependency_links.txt +0 -0
  18. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/git_visual_timeline.egg-info/entry_points.txt +0 -0
  19. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/git_visual_timeline.egg-info/requires.txt +0 -0
  20. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/git_visual_timeline.egg-info/top_level.txt +0 -0
  21. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/cli.py +0 -0
  22. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/git/__init__.py +0 -0
  23. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/git/cache.py +0 -0
  24. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/logging_setup.py +0 -0
  25. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/styles/app.tcss +0 -0
  26. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/textsafe.py +0 -0
  27. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/__init__.py +0 -0
  28. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/commit_bar.py +0 -0
  29. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/commit_toast.py +0 -0
  30. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/diff_view.py +0 -0
  31. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/src/gvt/widgets/timeline.py +0 -0
  32. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_app_actions.py +0 -0
  33. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_app_integration.py +0 -0
  34. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_cache.py +0 -0
  35. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_changed_files.py +0 -0
  36. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_diff_view_logic.py +0 -0
  37. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_git_repo.py +0 -0
  38. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_git_repo_extended.py +0 -0
  39. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_logging_setup.py +0 -0
  40. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_repo_resilience.py +0 -0
  41. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_textsafe.py +0 -0
  42. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_timeline_logic.py +0 -0
  43. {git_visual_timeline-0.2.4 → git_visual_timeline-0.2.5}/tests/test_widgets.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: git-visual-timeline
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Git Visual Timeline — a keyboard-driven TUI for exploring file commit history
5
5
  Author-email: Adam Reese <areese801@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "git-visual-timeline"
7
- version = "0.2.4"
7
+ version = "0.2.5"
8
8
  description = "Git Visual Timeline — a keyboard-driven TUI for exploring file commit history"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: git-visual-timeline
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Git Visual Timeline — a keyboard-driven TUI for exploring file commit history
5
5
  Author-email: Adam Reese <areese801@gmail.com>
6
6
  License: MIT
@@ -0,0 +1 @@
1
+ __version__ = "0.2.5"
@@ -23,6 +23,7 @@ from textual.widget import Widget
23
23
  from gvt.git.cache import DiffCache
24
24
  from gvt.git.repo import CommitInfo, GitRepo
25
25
  from gvt.logging_setup import get_logger
26
+ from gvt.textsafe import safe_text
26
27
 
27
28
  log = get_logger(__name__)
28
29
  from gvt.widgets.changed_files import ChangedFilesWidget, ChangedFileSelected, ChangedFileHighlighted
@@ -193,7 +194,7 @@ class GVTApp(App):
193
194
 
194
195
  @on(ChangedFileHighlighted)
195
196
  def on_changed_file_highlighted(self, event: ChangedFileHighlighted) -> None:
196
- self.query_one("#changed-files-pane", Container).border_title = f"[5] {escape(event.path)}"
197
+ self.query_one("#changed-files-pane", Container).border_title = f"[5] {escape(safe_text(event.path))}"
197
198
 
198
199
  def _load_untracked_file(self, file_path: str) -> None:
199
200
  """Show an untracked file as a read-only preview."""
@@ -233,7 +234,7 @@ class GVTApp(App):
233
234
  _, branch = self.git_repo.get_branches()
234
235
  status_bar.update_info(file_path=file_path, branch=branch)
235
236
  self.query_one("#timeline-pane", Container).border_title = "[2] Timeline"
236
- self.query_one("#diff-pane", Container).border_title = f"[4] Preview {escape(file_path)} (untracked)"
237
+ self.query_one("#diff-pane", Container).border_title = f"[4] Preview {escape(safe_text(file_path))} (untracked)"
237
238
  self.query_one("#changed-files-pane", Container).border_title = "[5] Changed"
238
239
 
239
240
  # Focus the diff pane so user can scroll the preview
@@ -337,10 +338,10 @@ class GVTApp(App):
337
338
  # Update dynamic pane titles
338
339
  current_commit = self.current_commits[timeline.cursor]
339
340
  if current_commit.is_wip:
340
- self.query_one("#diff-pane", Container).border_title = f"[4] Diff {escape(file_path)} (WIP)"
341
+ self.query_one("#diff-pane", Container).border_title = f"[4] Diff {escape(safe_text(file_path))} (WIP)"
341
342
  self.query_one("#changed-files-pane", Container).border_title = "[5] Uncommitted changes"
342
343
  else:
343
- self.query_one("#diff-pane", Container).border_title = f"[4] Diff {escape(file_path)}"
344
+ self.query_one("#diff-pane", Container).border_title = f"[4] Diff {escape(safe_text(file_path))}"
344
345
  self.query_one("#changed-files-pane", Container).border_title = f"[5] Also changed on {current_commit.short_hash}"
345
346
 
346
347
  self._load_diff(file_path, left_idx, right_idx)
@@ -25,6 +25,17 @@ SAFE_DIFF = ("--no-ext-diff", "--no-textconv")
25
25
  # Largest working-tree file shown as a preview
26
26
  MAX_PREVIEW_BYTES = 2_000_000
27
27
 
28
+ # Commit timestamps are clamped to 1970..2100: a crafted date outside Python's
29
+ # datetime range would otherwise crash parsing
30
+ MAX_TIMESTAMP = 4_102_444_800 # 2100-01-01 UTC
31
+
32
+
33
+ def commit_date(timestamp: int) -> datetime:
34
+ """
35
+ UTC datetime for a git timestamp, clamped to 1970-01-01..2100-01-01.
36
+ """
37
+ return datetime.fromtimestamp(max(0, min(timestamp, MAX_TIMESTAMP)), tz=timezone.utc)
38
+
28
39
 
29
40
  @dataclass
30
41
  class CommitInfo:
@@ -89,7 +100,8 @@ class GitRepo:
89
100
  for ref in refs:
90
101
  try:
91
102
  sha = ref.commit.hexsha
92
- ref_map.setdefault(sha, []).append(ref.name)
103
+ # Ref names may hold bidi or C1 characters; they're only displayed
104
+ ref_map.setdefault(sha, []).append(safe_text(ref.name))
93
105
  except (GitCommandError, AttributeError, ValueError) as e:
94
106
  log.debug("skipping ref %s: %s", getattr(ref, "name", "?"), e)
95
107
  return ref_map
@@ -158,7 +170,7 @@ class GitRepo:
158
170
  commits.append(
159
171
  CommitInfo(
160
172
  hexsha=hexsha,
161
- date=datetime.fromtimestamp(timestamp, tz=timezone.utc),
173
+ date=commit_date(timestamp),
162
174
  author=author,
163
175
  message=subject,
164
176
  additions=additions,
@@ -228,7 +240,7 @@ class GitRepo:
228
240
  commits.append(
229
241
  CommitInfo(
230
242
  hexsha=hexsha,
231
- date=datetime.fromtimestamp(timestamp, tz=timezone.utc),
243
+ date=commit_date(timestamp),
232
244
  author=author,
233
245
  message=subject,
234
246
  additions=total_adds,
@@ -320,7 +332,7 @@ class GitRepo:
320
332
  elif raw_line.startswith("author-time "):
321
333
  from datetime import datetime, timezone
322
334
  ts = int(raw_line[12:])
323
- dates[current_hash] = datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d")
335
+ dates[current_hash] = commit_date(ts).strftime("%Y-%m-%d")
324
336
  elif not raw_line.startswith("author-") and not raw_line.startswith("committer") and not raw_line.startswith("summary ") and not raw_line.startswith("previous ") and not raw_line.startswith("filename ") and not raw_line.startswith("boundary"):
325
337
  # Could be a commit line: hash orig_line final_line [num_lines]
326
338
  parts = raw_line.split()
@@ -7,6 +7,8 @@ from textual.message import Message
7
7
  from textual.reactive import reactive
8
8
  from textual.scroll_view import ScrollView
9
9
 
10
+ from gvt.textsafe import safe_text
11
+
10
12
  COLOR_ACCENT = "#7aa2f7"
11
13
  COLOR_TEXT = "#c0caf5"
12
14
  COLOR_DIM = "#565f89"
@@ -70,7 +72,8 @@ class ChangedFilesWidget(ScrollView, can_focus=True):
70
72
  self._lines.append(Text("No files changed", style=COLOR_DIM))
71
73
  return
72
74
 
73
- for idx, (file_path, adds, dels) in enumerate(self.files):
75
+ for idx, (raw_path, adds, dels) in enumerate(self.files):
76
+ file_path = safe_text(raw_path)
74
77
  line = Text()
75
78
  is_selected = idx == self.selected_idx
76
79
 
@@ -12,6 +12,8 @@ from textual.widget import Widget
12
12
  from textual.widgets import Tree
13
13
  from textual.widgets._tree import TreeNode
14
14
 
15
+ from gvt.textsafe import safe_text
16
+
15
17
  COLOR_DIM = "#565f89"
16
18
  COLOR_UNTRACKED = "#e0af68"
17
19
 
@@ -143,7 +145,7 @@ class FileTreeWidget(Widget, can_focus=True):
143
145
 
144
146
  for subdir in subdirs:
145
147
  # Display name is the last component
146
- display_name = subdir.split("/")[-1]
148
+ display_name = safe_text(subdir.split("/")[-1])
147
149
  # Text, not str: a str label would be parsed as markup
148
150
  if is_untracked:
149
151
  label = Text(display_name, style=COLOR_DIM)
@@ -153,7 +155,7 @@ class FileTreeWidget(Widget, can_focus=True):
153
155
  node.allow_expand = True
154
156
 
155
157
  for file_path in files:
156
- display_name = file_path.split("/")[-1]
158
+ display_name = safe_text(file_path.split("/")[-1])
157
159
  if is_untracked:
158
160
  label = Text(f"? {display_name}", style=COLOR_DIM)
159
161
  else:
@@ -13,6 +13,7 @@ from textual.widgets import Input, Label, Static
13
13
  from rich.text import Text
14
14
 
15
15
  from gvt.git.repo import CommitInfo
16
+ from gvt.textsafe import safe_text
16
17
 
17
18
  try:
18
19
  from thefuzz import fuzz
@@ -266,7 +267,7 @@ class FileSearchModal(ModalScreen):
266
267
  else:
267
268
  line.append(" ")
268
269
 
269
- line.append(file_path, style=COLOR_TEXT)
270
+ line.append(safe_text(file_path), style=COLOR_TEXT)
270
271
 
271
272
  label = Static(line)
272
273
  if is_selected:
@@ -412,7 +413,7 @@ class CommitFilesModal(ModalScreen):
412
413
  else:
413
414
  line.append(" ")
414
415
 
415
- line.append(file_path, style=COLOR_TEXT if not is_selected else f"bold {COLOR_TEXT}")
416
+ line.append(safe_text(file_path), style=COLOR_TEXT if not is_selected else f"bold {COLOR_TEXT}")
416
417
  line.append(" ", style="")
417
418
  line.append(f"+{adds}", style=COLOR_GREEN)
418
419
  line.append(f" -{dels}", style=COLOR_RED)
@@ -6,6 +6,8 @@ from rich.text import Text
6
6
  from textual.widget import Widget
7
7
  from textual.strip import Strip
8
8
 
9
+ from gvt.textsafe import safe_text
10
+
9
11
  COLOR_BAR_BG = "#7aa2f7"
10
12
  COLOR_BAR_FG = "#1a1b26"
11
13
 
@@ -101,7 +103,7 @@ class GVTStatusBar(Widget):
101
103
  text.append(" gvt", style=f"bold on {COLOR_BAR_BG} {COLOR_BAR_FG}")
102
104
 
103
105
  if self.file_path:
104
- text.append(f" {self.file_path}", style=f"on {COLOR_BAR_BG} {COLOR_BAR_FG}")
106
+ text.append(f" {safe_text(self.file_path)}", style=f"on {COLOR_BAR_BG} {COLOR_BAR_FG}")
105
107
 
106
108
  if self.commit_position:
107
109
  text.append(f" [{self.commit_position}]", style=f"on {COLOR_BAR_BG} {COLOR_BAR_FG}")
@@ -211,3 +211,95 @@ class TestApp:
211
211
  tree = app.query_one(FileTreeWidget)._tree
212
212
  labels = [str(child.label) for child in tree.root.children]
213
213
  assert "[red]styled.py" in labels
214
+
215
+
216
+ # Characters git passes through raw with core.quotePath=false: C1 controls and
217
+ # bidi overrides (these can reorder or control what a terminal shows)
218
+ UNSAFE_DISPLAY = ("‮", "\x9b", "⁦")
219
+
220
+
221
+ def _display_safe(text: str) -> bool:
222
+ return not any(ch in text for ch in UNSAFE_DISPLAY) and _no_raw_controls(text)
223
+
224
+
225
+ @pytest.fixture
226
+ def unicode_tricks_repo(tmp_path):
227
+ repo_dir = str(tmp_path / "tricks")
228
+ os.makedirs(repo_dir)
229
+ repo = Repo.init(repo_dir)
230
+ with repo.config_writer() as cw:
231
+ cw.set_value("user", "name", "T")
232
+ cw.set_value("user", "email", "t@example.com")
233
+ _write(repo_dir, "bidi‮txt.py", "x\n")
234
+ _write(repo_dir, "c1\x9bname.py", "y\n")
235
+ repo.git.add("-A")
236
+ repo.git.commit("-m", "init")
237
+ repo.git.tag("v1‮rtl")
238
+ return repo_dir
239
+
240
+
241
+ class TestDisplayedNames:
242
+ SIZE = (120, 40)
243
+
244
+ def test_ref_names_are_safe(self, unicode_tricks_repo):
245
+ commits = GitRepo(unicode_tricks_repo).get_all_commits()
246
+ assert "v1" in commits[0].refs
247
+ assert _display_safe(commits[0].refs)
248
+
249
+ async def test_file_names_with_c1_and_bidi_are_shown_escaped(self, unicode_tricks_repo):
250
+ from gvt.widgets.changed_files import ChangedFilesWidget
251
+ from gvt.widgets.status_bar import GVTStatusBar
252
+
253
+ path = "bidi‮txt.py"
254
+ app = GVTApp(repo_path=unicode_tricks_repo, initial_file=path)
255
+ async with app.run_test(size=self.SIZE) as pilot:
256
+ await pilot.pause()
257
+ await app.workers.wait_for_complete()
258
+ await pilot.pause()
259
+ assert app.current_file == path # the real name still opens the file
260
+
261
+ title = Content.from_markup(str(app.query_one("#diff-pane").border_title)).plain
262
+ assert "bidi" in title and _display_safe(title)
263
+
264
+ tree = app.query_one(FileTreeWidget)._tree
265
+ labels = [str(child.label) for child in tree.root.children]
266
+ assert labels and all(_display_safe(label) for label in labels)
267
+
268
+ status = app.query_one(GVTStatusBar)._render_info_line().plain
269
+ assert "bidi" in status and _display_safe(status)
270
+
271
+ changed = app.query_one(ChangedFilesWidget)
272
+ rendered = " ".join(line.plain for line in changed._lines)
273
+ assert "bidi" in rendered and _display_safe(rendered)
274
+
275
+ async def test_commit_files_picker_shows_names_escaped(self, unicode_tricks_repo):
276
+ from gvt.widgets.modals import CommitFilesModal
277
+
278
+ app = GVTApp(repo_path=unicode_tricks_repo)
279
+ async with app.run_test(size=self.SIZE) as pilot:
280
+ await pilot.pause()
281
+ app._all_commits_cache = app.git_repo.get_all_commits()
282
+ await pilot.press("c")
283
+ await pilot.pause()
284
+ await pilot.press("enter")
285
+ await pilot.pause()
286
+ assert isinstance(app.screen, CommitFilesModal)
287
+ text = " ".join(str(s.render()) for s in app.screen.query("Static"))
288
+ assert "bidi" in text and _display_safe(text)
289
+
290
+
291
+ def test_far_future_commit_dates_do_not_crash(tmp_path):
292
+ repo_dir = str(tmp_path / "future")
293
+ os.makedirs(repo_dir)
294
+ repo = Repo.init(repo_dir)
295
+ with repo.config_writer() as cw:
296
+ cw.set_value("user", "name", "T")
297
+ cw.set_value("user", "email", "t@example.com")
298
+ _write(repo_dir, "a.txt", "x\n")
299
+ repo.git.add("a.txt")
300
+ stamp = "@300000000000 +0000" # year 11476
301
+ repo.git.commit("-m", "far", env={"GIT_AUTHOR_DATE": stamp, "GIT_COMMITTER_DATE": stamp})
302
+ gvt = GitRepo(repo_dir)
303
+ commits = gvt.get_file_commits("a.txt") + gvt.get_all_commits()
304
+ assert commits and all(c.date.year == 2100 for c in commits)
305
+ assert gvt.get_blame("a.txt", commits[0].hexsha)[0][2].startswith("2100")
@@ -1 +0,0 @@
1
- __version__ = "0.2.4"