git-visual-timeline 0.2.2__tar.gz → 0.2.4__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.2/src/git_visual_timeline.egg-info → git_visual_timeline-0.2.4}/PKG-INFO +20 -12
  2. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/README.md +17 -9
  3. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/pyproject.toml +3 -3
  4. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4/src/git_visual_timeline.egg-info}/PKG-INFO +20 -12
  5. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/git_visual_timeline.egg-info/SOURCES.txt +3 -0
  6. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/git_visual_timeline.egg-info/requires.txt +2 -2
  7. git_visual_timeline-0.2.4/src/gvt/__init__.py +1 -0
  8. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/app.py +17 -9
  9. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/git/repo.py +50 -21
  10. git_visual_timeline-0.2.4/src/gvt/textsafe.py +33 -0
  11. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/diff_view.py +38 -10
  12. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/file_tree.py +3 -2
  13. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_app_actions.py +30 -0
  14. git_visual_timeline-0.2.4/tests/test_hostile_repo.py +213 -0
  15. git_visual_timeline-0.2.4/tests/test_textsafe.py +37 -0
  16. git_visual_timeline-0.2.2/src/gvt/__init__.py +0 -1
  17. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/LICENSE +0 -0
  18. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/setup.cfg +0 -0
  19. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/git_visual_timeline.egg-info/dependency_links.txt +0 -0
  20. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/git_visual_timeline.egg-info/entry_points.txt +0 -0
  21. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/git_visual_timeline.egg-info/top_level.txt +0 -0
  22. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/cli.py +0 -0
  23. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/git/__init__.py +0 -0
  24. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/git/cache.py +0 -0
  25. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/logging_setup.py +0 -0
  26. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/styles/app.tcss +0 -0
  27. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/__init__.py +0 -0
  28. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/changed_files.py +0 -0
  29. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/commit_bar.py +0 -0
  30. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/commit_toast.py +0 -0
  31. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/modals.py +0 -0
  32. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/status_bar.py +0 -0
  33. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/src/gvt/widgets/timeline.py +0 -0
  34. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_app_integration.py +0 -0
  35. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_cache.py +0 -0
  36. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_changed_files.py +0 -0
  37. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_diff_view_logic.py +0 -0
  38. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_git_repo.py +0 -0
  39. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_git_repo_extended.py +0 -0
  40. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_logging_setup.py +0 -0
  41. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_repo_resilience.py +0 -0
  42. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/tests/test_timeline_logic.py +0 -0
  43. {git_visual_timeline-0.2.2 → git_visual_timeline-0.2.4}/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.2
3
+ Version: 0.2.4
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
@@ -22,8 +22,8 @@ Classifier: Topic :: Software Development :: Version Control :: Git
22
22
  Requires-Python: >=3.10
23
23
  Description-Content-Type: text/markdown
24
24
  License-File: LICENSE
25
- Requires-Dist: textual>=0.40.0
26
- Requires-Dist: gitpython>=3.1.40
25
+ Requires-Dist: textual<9,>=8.0
26
+ Requires-Dist: gitpython>=3.1.41
27
27
  Requires-Dist: pygments>=2.17.0
28
28
  Requires-Dist: thefuzz[speedup]>=0.20.0
29
29
  Provides-Extra: dev
@@ -39,16 +39,18 @@ Dynamic: license-file
39
39
 
40
40
  A keyboard-driven TUI for exploring the commit history of any file in a git repo. Think lazygit meets a video timeline scrubber, focused on per-file history.
41
41
 
42
- ![gvt full layout](assets/gvt-full-layout.png)
42
+ ![gvt full layout](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-full-layout.png)
43
43
 
44
44
  **gvt is a read-only history explorer, not a git UI.** It doesn't stage, commit, push, or manage branches — lazygit is great for that. gvt does one thing: lets you scrub through a file's commit timeline, see what changed and when, and understand how code evolved over time. It's the tool you reach for when you're staring at a file and asking "how did this get here?"
45
45
 
46
46
  ## Install
47
47
 
48
48
  ```bash
49
- pip install git-visual-timeline
49
+ pipx install git-visual-timeline
50
50
  ```
51
51
 
52
+ [pipx](https://pipx.pypa.io/) installs `gvt` in an isolated environment and puts it on your PATH — the recommended way to install Python CLI tools. Install pipx itself with `brew install pipx` (macOS) or `apt install pipx` (Debian/Ubuntu).
53
+
52
54
  ## Usage
53
55
 
54
56
  ```bash
@@ -77,25 +79,31 @@ gvt uses a 5-pane layout, each accessible by number key:
77
79
 
78
80
  Scrub through a file's commit history one tick at a time. Each tick is colored by change type — green for additions, red for deletions, amber for mixed.
79
81
 
80
- ![Timeline navigation](assets/gvt-timeline-navigation.gif)
82
+ ![Timeline navigation](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-timeline-navigation.gif)
81
83
 
82
84
  ### Pin Mode
83
85
 
84
86
  Press `x` to pin a commit, then move to another and press `x` again to diff any two commits. Press `x` a third time to clear. Use `X` to snap the nearest pin to your cursor.
85
87
 
86
- ![Pin mode](assets/gvt-pin-mode.gif)
88
+ ![Pin mode](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-pin-mode.gif)
87
89
 
88
90
  ### Inline Blame
89
91
 
90
92
  Toggle blame annotations with `b` to see who last modified each line, right-aligned alongside the diff.
91
93
 
92
- ![Blame mode](assets/gvt-blame-mode.gif)
94
+ ![Blame mode](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-blame-mode.gif)
93
95
 
94
96
  ### File Search
95
97
 
96
98
  Press `f` for an fzf-style fuzzy file picker that filters as you type.
97
99
 
98
- ![File search](assets/gvt-file-search.gif)
100
+ ![File search](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-file-search.gif)
101
+
102
+ ### Commit Search
103
+
104
+ Press `c` to fuzzy search all repo commits by message, branch, or author.
105
+
106
+ ![Commit search](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-commit-search.gif)
99
107
 
100
108
  ### All Features
101
109
 
@@ -148,10 +156,10 @@ Press `f` for an fzf-style fuzzy file picker that filters as you type.
148
156
 
149
157
  | Key | Action |
150
158
  |-----|--------|
151
- | `j`/`k` | Scroll |
159
+ | `j`/`k` | Scroll vertically |
160
+ | `h`/`l` | Scroll horizontally |
152
161
  | `g`/`G` | Top/bottom |
153
- | `+`/`-` or `m`/`l` | More/less context lines |
154
- | `Shift+Left/Right` | Horizontal scroll |
162
+ | `+`/`-` | More/less context lines |
155
163
 
156
164
  ### Search Modals
157
165
 
@@ -2,16 +2,18 @@
2
2
 
3
3
  A keyboard-driven TUI for exploring the commit history of any file in a git repo. Think lazygit meets a video timeline scrubber, focused on per-file history.
4
4
 
5
- ![gvt full layout](assets/gvt-full-layout.png)
5
+ ![gvt full layout](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-full-layout.png)
6
6
 
7
7
  **gvt is a read-only history explorer, not a git UI.** It doesn't stage, commit, push, or manage branches — lazygit is great for that. gvt does one thing: lets you scrub through a file's commit timeline, see what changed and when, and understand how code evolved over time. It's the tool you reach for when you're staring at a file and asking "how did this get here?"
8
8
 
9
9
  ## Install
10
10
 
11
11
  ```bash
12
- pip install git-visual-timeline
12
+ pipx install git-visual-timeline
13
13
  ```
14
14
 
15
+ [pipx](https://pipx.pypa.io/) installs `gvt` in an isolated environment and puts it on your PATH — the recommended way to install Python CLI tools. Install pipx itself with `brew install pipx` (macOS) or `apt install pipx` (Debian/Ubuntu).
16
+
15
17
  ## Usage
16
18
 
17
19
  ```bash
@@ -40,25 +42,31 @@ gvt uses a 5-pane layout, each accessible by number key:
40
42
 
41
43
  Scrub through a file's commit history one tick at a time. Each tick is colored by change type — green for additions, red for deletions, amber for mixed.
42
44
 
43
- ![Timeline navigation](assets/gvt-timeline-navigation.gif)
45
+ ![Timeline navigation](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-timeline-navigation.gif)
44
46
 
45
47
  ### Pin Mode
46
48
 
47
49
  Press `x` to pin a commit, then move to another and press `x` again to diff any two commits. Press `x` a third time to clear. Use `X` to snap the nearest pin to your cursor.
48
50
 
49
- ![Pin mode](assets/gvt-pin-mode.gif)
51
+ ![Pin mode](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-pin-mode.gif)
50
52
 
51
53
  ### Inline Blame
52
54
 
53
55
  Toggle blame annotations with `b` to see who last modified each line, right-aligned alongside the diff.
54
56
 
55
- ![Blame mode](assets/gvt-blame-mode.gif)
57
+ ![Blame mode](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-blame-mode.gif)
56
58
 
57
59
  ### File Search
58
60
 
59
61
  Press `f` for an fzf-style fuzzy file picker that filters as you type.
60
62
 
61
- ![File search](assets/gvt-file-search.gif)
63
+ ![File search](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-file-search.gif)
64
+
65
+ ### Commit Search
66
+
67
+ Press `c` to fuzzy search all repo commits by message, branch, or author.
68
+
69
+ ![Commit search](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-commit-search.gif)
62
70
 
63
71
  ### All Features
64
72
 
@@ -111,10 +119,10 @@ Press `f` for an fzf-style fuzzy file picker that filters as you type.
111
119
 
112
120
  | Key | Action |
113
121
  |-----|--------|
114
- | `j`/`k` | Scroll |
122
+ | `j`/`k` | Scroll vertically |
123
+ | `h`/`l` | Scroll horizontally |
115
124
  | `g`/`G` | Top/bottom |
116
- | `+`/`-` or `m`/`l` | More/less context lines |
117
- | `Shift+Left/Right` | Horizontal scroll |
125
+ | `+`/`-` | More/less context lines |
118
126
 
119
127
  ### Search Modals
120
128
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "git-visual-timeline"
7
- version = "0.2.2"
7
+ version = "0.2.4"
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"}
@@ -27,8 +27,8 @@ classifiers = [
27
27
  ]
28
28
  keywords = ["git", "tui", "timeline", "diff", "blame", "textual"]
29
29
  dependencies = [
30
- "textual>=0.40.0",
31
- "gitpython>=3.1.40",
30
+ "textual>=8.0,<9",
31
+ "gitpython>=3.1.41",
32
32
  "pygments>=2.17.0",
33
33
  "thefuzz[speedup]>=0.20.0",
34
34
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: git-visual-timeline
3
- Version: 0.2.2
3
+ Version: 0.2.4
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
@@ -22,8 +22,8 @@ Classifier: Topic :: Software Development :: Version Control :: Git
22
22
  Requires-Python: >=3.10
23
23
  Description-Content-Type: text/markdown
24
24
  License-File: LICENSE
25
- Requires-Dist: textual>=0.40.0
26
- Requires-Dist: gitpython>=3.1.40
25
+ Requires-Dist: textual<9,>=8.0
26
+ Requires-Dist: gitpython>=3.1.41
27
27
  Requires-Dist: pygments>=2.17.0
28
28
  Requires-Dist: thefuzz[speedup]>=0.20.0
29
29
  Provides-Extra: dev
@@ -39,16 +39,18 @@ Dynamic: license-file
39
39
 
40
40
  A keyboard-driven TUI for exploring the commit history of any file in a git repo. Think lazygit meets a video timeline scrubber, focused on per-file history.
41
41
 
42
- ![gvt full layout](assets/gvt-full-layout.png)
42
+ ![gvt full layout](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-full-layout.png)
43
43
 
44
44
  **gvt is a read-only history explorer, not a git UI.** It doesn't stage, commit, push, or manage branches — lazygit is great for that. gvt does one thing: lets you scrub through a file's commit timeline, see what changed and when, and understand how code evolved over time. It's the tool you reach for when you're staring at a file and asking "how did this get here?"
45
45
 
46
46
  ## Install
47
47
 
48
48
  ```bash
49
- pip install git-visual-timeline
49
+ pipx install git-visual-timeline
50
50
  ```
51
51
 
52
+ [pipx](https://pipx.pypa.io/) installs `gvt` in an isolated environment and puts it on your PATH — the recommended way to install Python CLI tools. Install pipx itself with `brew install pipx` (macOS) or `apt install pipx` (Debian/Ubuntu).
53
+
52
54
  ## Usage
53
55
 
54
56
  ```bash
@@ -77,25 +79,31 @@ gvt uses a 5-pane layout, each accessible by number key:
77
79
 
78
80
  Scrub through a file's commit history one tick at a time. Each tick is colored by change type — green for additions, red for deletions, amber for mixed.
79
81
 
80
- ![Timeline navigation](assets/gvt-timeline-navigation.gif)
82
+ ![Timeline navigation](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-timeline-navigation.gif)
81
83
 
82
84
  ### Pin Mode
83
85
 
84
86
  Press `x` to pin a commit, then move to another and press `x` again to diff any two commits. Press `x` a third time to clear. Use `X` to snap the nearest pin to your cursor.
85
87
 
86
- ![Pin mode](assets/gvt-pin-mode.gif)
88
+ ![Pin mode](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-pin-mode.gif)
87
89
 
88
90
  ### Inline Blame
89
91
 
90
92
  Toggle blame annotations with `b` to see who last modified each line, right-aligned alongside the diff.
91
93
 
92
- ![Blame mode](assets/gvt-blame-mode.gif)
94
+ ![Blame mode](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-blame-mode.gif)
93
95
 
94
96
  ### File Search
95
97
 
96
98
  Press `f` for an fzf-style fuzzy file picker that filters as you type.
97
99
 
98
- ![File search](assets/gvt-file-search.gif)
100
+ ![File search](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-file-search.gif)
101
+
102
+ ### Commit Search
103
+
104
+ Press `c` to fuzzy search all repo commits by message, branch, or author.
105
+
106
+ ![Commit search](https://raw.githubusercontent.com/areese801/git-visual-timeline/main/assets/gvt-commit-search.gif)
99
107
 
100
108
  ### All Features
101
109
 
@@ -148,10 +156,10 @@ Press `f` for an fzf-style fuzzy file picker that filters as you type.
148
156
 
149
157
  | Key | Action |
150
158
  |-----|--------|
151
- | `j`/`k` | Scroll |
159
+ | `j`/`k` | Scroll vertically |
160
+ | `h`/`l` | Scroll horizontally |
152
161
  | `g`/`G` | Top/bottom |
153
- | `+`/`-` or `m`/`l` | More/less context lines |
154
- | `Shift+Left/Right` | Horizontal scroll |
162
+ | `+`/`-` | More/less context lines |
155
163
 
156
164
  ### Search Modals
157
165
 
@@ -11,6 +11,7 @@ src/gvt/__init__.py
11
11
  src/gvt/app.py
12
12
  src/gvt/cli.py
13
13
  src/gvt/logging_setup.py
14
+ src/gvt/textsafe.py
14
15
  src/gvt/git/__init__.py
15
16
  src/gvt/git/cache.py
16
17
  src/gvt/git/repo.py
@@ -31,7 +32,9 @@ tests/test_changed_files.py
31
32
  tests/test_diff_view_logic.py
32
33
  tests/test_git_repo.py
33
34
  tests/test_git_repo_extended.py
35
+ tests/test_hostile_repo.py
34
36
  tests/test_logging_setup.py
35
37
  tests/test_repo_resilience.py
38
+ tests/test_textsafe.py
36
39
  tests/test_timeline_logic.py
37
40
  tests/test_widgets.py
@@ -1,5 +1,5 @@
1
- textual>=0.40.0
2
- gitpython>=3.1.40
1
+ textual<9,>=8.0
2
+ gitpython>=3.1.41
3
3
  pygments>=2.17.0
4
4
  thefuzz[speedup]>=0.20.0
5
5
 
@@ -0,0 +1 @@
1
+ __version__ = "0.2.4"
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import hashlib
6
6
  import os
7
+ import shlex
7
8
  import shutil
8
9
  import subprocess
9
10
  from datetime import datetime, timezone
@@ -16,6 +17,7 @@ from textual.app import App, ComposeResult
16
17
  from textual.binding import Binding
17
18
  from textual.containers import Container, Horizontal, Vertical
18
19
  from textual.css.query import NoMatches
20
+ from textual.markup import escape
19
21
  from textual.widget import Widget
20
22
 
21
23
  from gvt.git.cache import DiffCache
@@ -191,7 +193,7 @@ class GVTApp(App):
191
193
 
192
194
  @on(ChangedFileHighlighted)
193
195
  def on_changed_file_highlighted(self, event: ChangedFileHighlighted) -> None:
194
- self.query_one("#changed-files-pane", Container).border_title = f"[5] {event.path}"
196
+ self.query_one("#changed-files-pane", Container).border_title = f"[5] {escape(event.path)}"
195
197
 
196
198
  def _load_untracked_file(self, file_path: str) -> None:
197
199
  """Show an untracked file as a read-only preview."""
@@ -231,7 +233,7 @@ class GVTApp(App):
231
233
  _, branch = self.git_repo.get_branches()
232
234
  status_bar.update_info(file_path=file_path, branch=branch)
233
235
  self.query_one("#timeline-pane", Container).border_title = "[2] Timeline"
234
- self.query_one("#diff-pane", Container).border_title = f"[4] Preview {file_path} (untracked)"
236
+ self.query_one("#diff-pane", Container).border_title = f"[4] Preview {escape(file_path)} (untracked)"
235
237
  self.query_one("#changed-files-pane", Container).border_title = "[5] Changed"
236
238
 
237
239
  # Focus the diff pane so user can scroll the preview
@@ -314,10 +316,12 @@ class GVTApp(App):
314
316
  title = "WIP"
315
317
  else:
316
318
  title = f"{commit.short_hash} {commit.date.strftime('%Y-%m-%d')} {commit.author} +{commit.additions} -{commit.deletions}"
319
+ # Commit text comes from the repo: show it literally, not as markup
317
320
  self.notify(
318
321
  commit.message.strip(),
319
322
  title=title,
320
323
  timeout=2,
324
+ markup=False,
321
325
  )
322
326
 
323
327
  def _update_from_timeline(self, timeline: TimelineWidget, file_path: str) -> None:
@@ -333,10 +337,10 @@ class GVTApp(App):
333
337
  # Update dynamic pane titles
334
338
  current_commit = self.current_commits[timeline.cursor]
335
339
  if current_commit.is_wip:
336
- self.query_one("#diff-pane", Container).border_title = f"[4] Diff {file_path} (WIP)"
340
+ self.query_one("#diff-pane", Container).border_title = f"[4] Diff {escape(file_path)} (WIP)"
337
341
  self.query_one("#changed-files-pane", Container).border_title = "[5] Uncommitted changes"
338
342
  else:
339
- self.query_one("#diff-pane", Container).border_title = f"[4] Diff {file_path}"
343
+ self.query_one("#diff-pane", Container).border_title = f"[4] Diff {escape(file_path)}"
340
344
  self.query_one("#changed-files-pane", Container).border_title = f"[5] Also changed on {current_commit.short_hash}"
341
345
 
342
346
  self._load_diff(file_path, left_idx, right_idx)
@@ -515,7 +519,10 @@ class GVTApp(App):
515
519
  def _tmux_select_pane(direction: str) -> None:
516
520
  """Hand off navigation to tmux if running inside tmux."""
517
521
  if os.environ.get("TMUX"):
518
- subprocess.run(["tmux", "select-pane", f"-{direction}"], check=False)
522
+ try:
523
+ subprocess.run(["tmux", "select-pane", f"-{direction}"], check=False)
524
+ except OSError as e:
525
+ log.warning("tmux pane handoff failed: %s", e)
519
526
 
520
527
  def action_focus_left(self) -> None:
521
528
  if self._current_pane_idx in self._LEFT_PANES:
@@ -709,7 +716,7 @@ class GVTApp(App):
709
716
  bar = "█" * max(1, round(count / total * 20))
710
717
  lines.append(f" {bar} {name} {count} commits ({pct:.0f}%)")
711
718
  self.clear_notifications()
712
- self.notify("\n".join(lines), title="Contributors", timeout=5)
719
+ self.notify("\n".join(lines), title="Contributors", timeout=5, markup=False)
713
720
 
714
721
  def action_copy_short_hash(self) -> None:
715
722
  if not self.current_commits:
@@ -749,11 +756,12 @@ class GVTApp(App):
749
756
  result = None
750
757
  with self.suspend():
751
758
  try:
752
- result = subprocess.run([editor, file_path])
753
- except (OSError, FileNotFoundError) as e:
759
+ # $EDITOR may carry arguments, e.g. "code --wait"
760
+ result = subprocess.run(shlex.split(editor) + [file_path])
761
+ except (OSError, ValueError) as e:
754
762
  log.warning("editor %s failed to launch: %s", editor, e)
755
763
  if result is None:
756
- self.notify(f"Could not launch editor: {editor}", timeout=3)
764
+ self.notify(f"Could not launch editor: {editor}", timeout=3, markup=False)
757
765
  elif result.returncode != 0:
758
766
  log.warning("editor %s exited with code %d", editor, result.returncode)
759
767
  self.notify(f"Editor exited with code {result.returncode}", timeout=2)
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import os
6
+ import re
6
7
  from dataclasses import dataclass
7
8
  from datetime import datetime, timezone
8
9
 
@@ -10,9 +11,20 @@ from git import Repo
10
11
  from git.exc import GitCommandError
11
12
 
12
13
  from gvt.logging_setup import get_logger
14
+ from gvt.textsafe import safe_text
13
15
 
14
16
  log = get_logger(__name__)
15
17
 
18
+ # Commit records start with a NUL byte, which can't appear in commit metadata
19
+ LOG_FORMAT = "--format=%x00%H%n%at%n%an%n%s"
20
+ RECORD_SEPARATOR = "\x00"
21
+
22
+ # Never run diff programs or text converters configured by the repo
23
+ SAFE_DIFF = ("--no-ext-diff", "--no-textconv")
24
+
25
+ # Largest working-tree file shown as a preview
26
+ MAX_PREVIEW_BYTES = 2_000_000
27
+
16
28
 
17
29
  @dataclass
18
30
  class CommitInfo:
@@ -58,6 +70,13 @@ class GitRepo:
58
70
  def __init__(self, path: str):
59
71
  self.repo = Repo(path, search_parent_directories=True)
60
72
  self.root = self.repo.working_tree_dir
73
+ # Paths are file names, not pathspecs: "app/[slug]/page.tsx" must not
74
+ # match "app/s/page.tsx". List non-ASCII paths as-is instead of
75
+ # C-quoting them, and never run a repo-configured fsmonitor hook.
76
+ self.repo.git.update_environment(GIT_LITERAL_PATHSPECS="1")
77
+ self.repo.git.set_persistent_git_options(
78
+ c=["core.quotePath=false", "core.fsmonitor=false"]
79
+ )
61
80
 
62
81
  def _build_ref_map(self) -> dict[str, list[str]]:
63
82
  """Build a sha -> [ref names] map, tolerating individual bad refs."""
@@ -87,7 +106,7 @@ class GitRepo:
87
106
 
88
107
  # Use git log with --numstat for stats, avoiding gitpython's object parser
89
108
  output = self.repo.git.log(
90
- "--format=---GVT_START---%n%H%n%at%n%an%n%s",
109
+ LOG_FORMAT,
91
110
  "--numstat",
92
111
  "--follow",
93
112
  "--", rel_path,
@@ -97,7 +116,7 @@ class GitRepo:
97
116
  return []
98
117
 
99
118
  commits = []
100
- chunks = output.split("---GVT_START---")
119
+ chunks = output.split(RECORD_SEPARATOR)
101
120
 
102
121
  for chunk in chunks:
103
122
  chunk = chunk.strip()
@@ -117,8 +136,8 @@ class GitRepo:
117
136
  except (ValueError, IndexError):
118
137
  continue
119
138
 
120
- author = lines[2].strip()
121
- subject = lines[3].strip()
139
+ author = safe_text(lines[2].strip())
140
+ subject = safe_text(lines[3].strip())
122
141
 
123
142
  # Remaining lines are numstat (tab-separated: adds, dels, filename)
124
143
  additions = 0
@@ -162,7 +181,7 @@ class GitRepo:
162
181
  output = self.repo.git.log(
163
182
  f"--max-count={max_count}",
164
183
  "--no-merges",
165
- "--format=---GVT_START---%n%H%n%at%n%an%n%s",
184
+ LOG_FORMAT,
166
185
  "--shortstat",
167
186
  )
168
187
 
@@ -170,7 +189,7 @@ class GitRepo:
170
189
  return []
171
190
 
172
191
  commits = []
173
- chunks = output.split("---GVT_START---")
192
+ chunks = output.split(RECORD_SEPARATOR)
174
193
 
175
194
  for chunk in chunks:
176
195
  chunk = chunk.strip()
@@ -190,15 +209,14 @@ class GitRepo:
190
209
  except (ValueError, IndexError):
191
210
  continue
192
211
 
193
- author = lines[2].strip()
194
- subject = lines[3].strip()
212
+ author = safe_text(lines[2].strip())
213
+ subject = safe_text(lines[3].strip())
195
214
 
196
215
  # Parse shortstat line (e.g. " 3 files changed, 10 insertions(+), 5 deletions(-)")
197
216
  total_adds = 0
198
217
  total_dels = 0
199
218
  for line in lines[4:]:
200
219
  if "insertion" in line or "deletion" in line:
201
- import re
202
220
  add_match = re.search(r"(\d+) insertion", line)
203
221
  del_match = re.search(r"(\d+) deletion", line)
204
222
  if add_match:
@@ -227,26 +245,28 @@ class GitRepo:
227
245
  rel_path = self._to_relative(path)
228
246
  # Use git diff directly for context line control
229
247
  diff_output = self.repo.git.diff(
230
- f"-U{context_lines}", commit_a, commit_b, "--", rel_path
248
+ *SAFE_DIFF, f"-U{context_lines}", commit_a, commit_b, "--", rel_path
231
249
  )
232
- return diff_output
250
+ return safe_text(diff_output)
233
251
 
234
252
  def has_uncommitted_changes(self, path: str) -> bool:
235
253
  """Check if a file has uncommitted changes (staged or unstaged)."""
236
254
  rel_path = self._to_relative(path)
237
255
  # Check both staged and unstaged
238
- diff_output = self.repo.git.diff("HEAD", "--", rel_path)
256
+ diff_output = self.repo.git.diff(*SAFE_DIFF, "HEAD", "--", rel_path)
239
257
  return bool(diff_output.strip())
240
258
 
241
259
  def get_diff_to_working_tree(self, path: str, commit_sha: str, context_lines: int = 3) -> str:
242
260
  """Get diff from a commit to the current working tree for a file."""
243
261
  rel_path = self._to_relative(path)
244
- return self.repo.git.diff(f"-U{context_lines}", commit_sha, "--", rel_path)
262
+ return safe_text(
263
+ self.repo.git.diff(*SAFE_DIFF, f"-U{context_lines}", commit_sha, "--", rel_path)
264
+ )
245
265
 
246
266
  def get_working_tree_stats(self, path: str) -> tuple[int, int]:
247
267
  """Get +/- stats for uncommitted changes to a file."""
248
268
  rel_path = self._to_relative(path)
249
- output = self.repo.git.diff("--numstat", "HEAD", "--", rel_path)
269
+ output = self.repo.git.diff(*SAFE_DIFF, "--numstat", "HEAD", "--", rel_path)
250
270
  if not output.strip():
251
271
  return (0, 0)
252
272
  parts = output.strip().split("\t")
@@ -262,7 +282,7 @@ class GitRepo:
262
282
  """
263
283
  rel_path = self._to_relative(path)
264
284
  try:
265
- return self.repo.git.show(f"{commit_sha}:{rel_path}")
285
+ return safe_text(self.repo.git.show(f"{commit_sha}:{rel_path}"))
266
286
  except GitCommandError as e:
267
287
  log.warning("git show %s:%s failed: %s", commit_sha, rel_path, e)
268
288
  return ""
@@ -275,7 +295,7 @@ class GitRepo:
275
295
  rel_path = self._to_relative(path)
276
296
  try:
277
297
  output = self.repo.git.blame(
278
- commit_sha, "--", rel_path,
298
+ "--no-textconv", commit_sha, "--", rel_path,
279
299
  porcelain=True,
280
300
  )
281
301
  except GitCommandError as e:
@@ -296,7 +316,7 @@ class GitRepo:
296
316
  dates.get(current_hash, ""),
297
317
  ))
298
318
  elif raw_line.startswith("author "):
299
- authors[current_hash] = raw_line[7:]
319
+ authors[current_hash] = safe_text(raw_line[7:])
300
320
  elif raw_line.startswith("author-time "):
301
321
  from datetime import datetime, timezone
302
322
  ts = int(raw_line[12:])
@@ -329,7 +349,7 @@ class GitRepo:
329
349
  # Lines come in pairs: email, then name
330
350
  for i in range(0, len(lines) - 1, 2):
331
351
  email = lines[i].strip()
332
- name = lines[i + 1].strip()
352
+ name = safe_text(lines[i + 1].strip())
333
353
  if not email:
334
354
  continue
335
355
  if email in by_email:
@@ -353,7 +373,7 @@ class GitRepo:
353
373
  """
354
374
  try:
355
375
  output = self.repo.git.diff_tree(
356
- "--numstat", "-r", "--root", "--no-commit-id", commit_sha
376
+ *SAFE_DIFF, "--numstat", "-r", "--root", "--no-commit-id", commit_sha
357
377
  )
358
378
  except (GitCommandError, ValueError) as e:
359
379
  log.warning("diff-tree for %s failed: %s", commit_sha, e)
@@ -396,12 +416,21 @@ class GitRepo:
396
416
  def get_file_content(self, path: str) -> str:
397
417
  """
398
418
  Get the current working tree content of a file.
419
+
420
+ Only regular files inside the repo are read (a symlink pointing
421
+ elsewhere, a FIFO or a device returns ""), and only the first
422
+ MAX_PREVIEW_BYTES.
399
423
  """
400
424
  rel_path = self._to_relative(path)
401
425
  full_path = os.path.join(self.root, rel_path)
426
+ real_root = os.path.realpath(self.root)
427
+ real_path = os.path.realpath(full_path)
428
+ if os.path.commonpath([real_root, real_path]) != real_root or not os.path.isfile(real_path):
429
+ log.info("not previewing %s: outside the repo or not a regular file", rel_path)
430
+ return ""
402
431
  try:
403
- with open(full_path, "r", errors="replace") as f:
404
- return f.read()
432
+ with open(real_path, "r", errors="replace") as f:
433
+ return safe_text(f.read(MAX_PREVIEW_BYTES))
405
434
  except (OSError, UnicodeDecodeError):
406
435
  return ""
407
436
 
@@ -0,0 +1,33 @@
1
+ """
2
+ Make repository-controlled text safe to print in a terminal.
3
+
4
+ Commit messages, author names and file contents come from whoever made the
5
+ repo. Raw control characters in them would reach the terminal as escape
6
+ sequences, and bidi controls can reorder what is displayed, so anything shown
7
+ from a repo passes through safe_text() first.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import re
13
+
14
+ # C0 controls except tab and newline, DEL, C1 controls, and bidi
15
+ # embedding/override/isolate characters
16
+ _UNSAFE = re.compile(r"[\x00-\x08\x0b-\x1f\x7f-\x9f‪-‮⁦-⁩]")
17
+
18
+
19
+ def _visible(match: re.Match[str]) -> str:
20
+ code = ord(match.group())
21
+ return f"\\x{code:02x}" if code < 0x100 else f"\\u{code:04x}"
22
+
23
+
24
+ def safe_text(text: str) -> str:
25
+ """
26
+ Replace control and bidi characters with visible escapes like "\\x1b".
27
+
28
+ Tabs and newlines are kept, and CRLF line endings become plain newlines.
29
+ """
30
+ text = text.replace("\r\n", "\n")
31
+ if text.endswith("\r"):
32
+ text = text[:-1]
33
+ return _UNSAFE.sub(_visible, text)
@@ -49,11 +49,13 @@ class DiffViewWidget(ScrollView, can_focus=True):
49
49
  ("P", "next_hunk", "Next hunk"),
50
50
  ("plus", "more_context", "+context"),
51
51
  ("minus", "less_context", "-context"),
52
- ("m", "more_context", "+context"),
53
- ("l", "less_context", "-context"),
54
- ("M", "less_context", "-context"),
55
- ("L", "more_context", "+context"),
56
52
  ("w", "toggle_full_file", "Whole file"),
53
+ ("h", "scroll_left_step", "Scroll left"),
54
+ ("l", "scroll_right_step", "Scroll right"),
55
+ ("left", "scroll_left_step", "Scroll left"),
56
+ ("right", "scroll_right_step", "Scroll right"),
57
+ ("shift+left", "scroll_left_step", "Scroll left"),
58
+ ("shift+right", "scroll_right_step", "Scroll right"),
57
59
  ]
58
60
 
59
61
  diff_text: reactive[str] = reactive("")
@@ -91,6 +93,17 @@ class DiffViewWidget(ScrollView, can_focus=True):
91
93
  if self.view_mode == MODE_FULL:
92
94
  self._render_full_file()
93
95
 
96
+ def _max_content_width(self) -> int:
97
+ """Return the width of the widest rendered line."""
98
+ if not self._lines:
99
+ return self.size.width
100
+ return max(self.size.width, max(len(line.plain) for line in self._lines))
101
+
102
+ def _update_virtual_size(self) -> None:
103
+ """Set virtual size based on line count and max content width."""
104
+ from textual.geometry import Size
105
+ self.virtual_size = Size(self._max_content_width(), max(len(self._lines), 1))
106
+
94
107
  def watch_diff_text(self, value: str) -> None:
95
108
  if self.side_by_side and self.view_mode == MODE_DIFF:
96
109
  self._render_side_by_side(value)
@@ -99,7 +112,7 @@ class DiffViewWidget(ScrollView, can_focus=True):
99
112
  else:
100
113
  self._parse_diff_line_numbers(value)
101
114
  self._render_full_file()
102
- self.virtual_size = self.size.with_height(max(len(self._lines), 1))
115
+ self._update_virtual_size()
103
116
  self.scroll_home(animate=False)
104
117
  self.refresh()
105
118
 
@@ -211,7 +224,7 @@ class DiffViewWidget(ScrollView, can_focus=True):
211
224
 
212
225
  self._lines.append(line)
213
226
 
214
- self.virtual_size = self.size.with_height(max(len(self._lines), 1))
227
+ self._update_virtual_size()
215
228
  self.refresh()
216
229
 
217
230
  def _render_side_by_side(self, diff: str) -> None:
@@ -298,7 +311,7 @@ class DiffViewWidget(ScrollView, can_focus=True):
298
311
 
299
312
  self._lines.append(line)
300
313
 
301
- self.virtual_size = self.size.with_height(max(len(self._lines), 1))
314
+ self._update_virtual_size()
302
315
  self.refresh()
303
316
 
304
317
  def action_toggle_side_by_side(self) -> None:
@@ -310,7 +323,7 @@ class DiffViewWidget(ScrollView, can_focus=True):
310
323
  self._render_side_by_side(self.diff_text)
311
324
  else:
312
325
  self._parse_diff(self.diff_text)
313
- self.virtual_size = self.size.with_height(max(len(self._lines), 1))
326
+ self._update_virtual_size()
314
327
  self.scroll_home(animate=False)
315
328
  self.refresh()
316
329
 
@@ -421,7 +434,11 @@ class DiffViewWidget(ScrollView, can_focus=True):
421
434
  if content_width < self.size.width:
422
435
  segments.append(Segment(" " * (self.size.width - content_width), flash_style))
423
436
 
424
- return Strip(segments)
437
+ strip = Strip(segments)
438
+ scroll_x = int(self.scroll_offset.x)
439
+ if scroll_x:
440
+ return strip.crop(scroll_x, scroll_x + self.size.width)
441
+ return strip
425
442
  bg = Style(bgcolor="#1a1b26")
426
443
  return Strip([Segment(" " * self.size.width, bg)])
427
444
 
@@ -485,6 +502,17 @@ class DiffViewWidget(ScrollView, can_focus=True):
485
502
  self.context_lines = max(0, self.context_lines - 3)
486
503
  self.post_message(DiffContextChanged(self.context_lines, self.view_mode == MODE_FULL))
487
504
 
505
+ def action_scroll_left_step(self) -> None:
506
+ """Scroll diff content left (show earlier columns)."""
507
+ target_x = max(0, int(self.scroll_offset.x) - 8)
508
+ self.scroll_to(x=target_x, animate=False)
509
+
510
+ def action_scroll_right_step(self) -> None:
511
+ """Scroll diff content right (show later columns)."""
512
+ max_x = self.virtual_size.width - self.size.width
513
+ target_x = min(max_x, int(self.scroll_offset.x) + 8)
514
+ self.scroll_to(x=target_x, animate=False)
515
+
488
516
  def action_toggle_full_file(self) -> None:
489
517
  """Toggle between diff and full-file view."""
490
518
  if self.view_mode == MODE_DIFF:
@@ -493,7 +521,7 @@ class DiffViewWidget(ScrollView, can_focus=True):
493
521
  else:
494
522
  self.view_mode = MODE_DIFF
495
523
  self._parse_diff(self.diff_text)
496
- self.virtual_size = self.size.with_height(max(len(self._lines), 1))
524
+ self._update_virtual_size()
497
525
  self.refresh()
498
526
 
499
527
  # --- Diff search ---
@@ -144,10 +144,11 @@ class FileTreeWidget(Widget, can_focus=True):
144
144
  for subdir in subdirs:
145
145
  # Display name is the last component
146
146
  display_name = subdir.split("/")[-1]
147
+ # Text, not str: a str label would be parsed as markup
147
148
  if is_untracked:
148
149
  label = Text(display_name, style=COLOR_DIM)
149
150
  else:
150
- label = display_name
151
+ label = Text(display_name)
151
152
  node = parent_node.add(label, data=subdir, expand=False)
152
153
  node.allow_expand = True
153
154
 
@@ -156,7 +157,7 @@ class FileTreeWidget(Widget, can_focus=True):
156
157
  if is_untracked:
157
158
  label = Text(f"? {display_name}", style=COLOR_DIM)
158
159
  else:
159
- label = display_name
160
+ label = Text(display_name)
160
161
  parent_node.add_leaf(label, data=file_path)
161
162
 
162
163
  @on(Tree.NodeExpanded)
@@ -123,3 +123,33 @@ def test_open_in_editor_no_current_file(fixture_app, monkeypatch):
123
123
 
124
124
  assert not runs
125
125
  assert not called
126
+
127
+
128
+ def test_open_in_editor_splits_editor_arguments(fixture_app, monkeypatch):
129
+ """EDITOR="code --wait" runs `code --wait <file>`, not a program named "code --wait"."""
130
+ import contextlib
131
+
132
+ fixture_app.current_file = "hello.py"
133
+ monkeypatch.delenv("VISUAL", raising=False)
134
+ monkeypatch.setenv("EDITOR", "code --wait")
135
+ monkeypatch.setattr(fixture_app, "suspend", lambda: contextlib.nullcontext())
136
+ runs = []
137
+ monkeypatch.setattr(
138
+ "gvt.app.subprocess.run", lambda cmd, **k: runs.append(cmd) or subprocess.CompletedProcess(cmd, 0)
139
+ )
140
+ fixture_app.action_open_in_editor()
141
+ assert runs and runs[0][:2] == ["code", "--wait"]
142
+ assert runs[0][2].endswith("hello.py")
143
+
144
+
145
+ def test_tmux_missing_from_path_is_ignored(monkeypatch):
146
+ """With $TMUX set but no tmux binary, pane handoff does nothing instead of crashing."""
147
+ from gvt.app import GVTApp
148
+
149
+ monkeypatch.setenv("TMUX", "/tmp/tmux-1/default,1,0")
150
+
151
+ def missing(*a, **k):
152
+ raise FileNotFoundError("tmux")
153
+
154
+ monkeypatch.setattr("gvt.app.subprocess.run", missing)
155
+ GVTApp._tmux_select_pane("L")
@@ -0,0 +1,213 @@
1
+ """
2
+ gvt run against a repo from an untrusted source: control characters in commit
3
+ messages and file contents, markup-like and pathspec-like file names, non-ASCII
4
+ names, and a hostile .git/config.
5
+ """
6
+
7
+ import os
8
+ import stat
9
+
10
+ import pytest
11
+ from git import Repo
12
+
13
+ from textual.content import Content
14
+
15
+ from gvt.app import GVTApp
16
+ from gvt.git.repo import GitRepo
17
+ from gvt.widgets.file_tree import FileTreeWidget
18
+ from gvt.widgets.timeline import TimelineWidget
19
+
20
+ ESC_TITLE = "\x1b]0;PWNED\x07"
21
+
22
+
23
+ def _write(repo_dir: str, path: str, text: str, mode: str = "w") -> None:
24
+ full = os.path.join(repo_dir, path)
25
+ os.makedirs(os.path.dirname(full) or repo_dir, exist_ok=True)
26
+ with open(full, mode, newline="") as f:
27
+ f.write(text)
28
+
29
+
30
+ @pytest.fixture
31
+ def hostile_repo(tmp_path):
32
+ """
33
+ A repo whose names, messages and contents try to attack the terminal and gvt.
34
+ """
35
+ repo_dir = str(tmp_path / "hostile")
36
+ os.makedirs(repo_dir)
37
+ repo = Repo.init(repo_dir)
38
+ with repo.config_writer() as cw:
39
+ cw.set_value("user", "name", f"Mal{ESC_TITLE}lory")
40
+ cw.set_value("user", "email", "m@example.com")
41
+
42
+ _write(repo_dir, "normal.py", "a\n")
43
+ _write(repo_dir, "[/]bad.py", "b\n")
44
+ _write(repo_dir, "[red]styled.py", "c\n")
45
+ _write(repo_dir, "café.py", "d\n")
46
+ _write(repo_dir, "app/[slug]/page.tsx", "slug v1\n")
47
+ _write(repo_dir, "app/s/page.tsx", "s v1\n")
48
+ _write(repo_dir, "content.txt", "plain\r\nwindows line\r\n")
49
+ repo.git.add("-A")
50
+ repo.git.commit("-m", "[/] unbalanced close tag")
51
+
52
+ _write(repo_dir, "normal.py", "a\na2\n")
53
+ _write(repo_dir, "content.txt", f"plain\r\nwindows line\r\n{ESC_TITLE} hidden\n")
54
+ repo.git.add("-A")
55
+ repo.git.commit("-m", f"escape {ESC_TITLE} and \x1b[2J clear")
56
+
57
+ _write(repo_dir, "app/s/page.tsx", "s v2\n")
58
+ repo.git.add("-A")
59
+ repo.git.commit("-m", "Only the s page")
60
+
61
+ _write(repo_dir, "normal.py", "a\na2\na3\n")
62
+ _write(repo_dir, "café.py", "d\nd2\n")
63
+ repo.git.add("-A")
64
+ repo.git.commit("-m", "Subject with ---GVT_START--- inside")
65
+ return repo_dir
66
+
67
+
68
+ def _no_raw_controls(text: str) -> bool:
69
+ return "\x1b" not in text and "\x07" not in text
70
+
71
+
72
+ class TestGitBoundary:
73
+ def test_commit_messages_and_authors_are_safe(self, hostile_repo):
74
+ repo = GitRepo(hostile_repo)
75
+ commits = repo.get_file_commits("normal.py") + repo.get_all_commits()
76
+ assert commits
77
+ for c in commits:
78
+ assert _no_raw_controls(c.message), c.message
79
+ assert _no_raw_controls(c.author), c.author
80
+ assert any("\\x1b]0;PWNED\\x07" in c.message for c in commits)
81
+
82
+ def test_file_contents_and_diffs_are_safe(self, hostile_repo):
83
+ repo = GitRepo(hostile_repo)
84
+ commits = repo.get_file_commits("content.txt")
85
+ diff = repo.get_diff("content.txt", commits[0].hexsha, commits[-1].hexsha)
86
+ content = repo.get_file_at_commit("content.txt", commits[-1].hexsha)
87
+ assert "PWNED" in diff and _no_raw_controls(diff)
88
+ assert "PWNED" in content and _no_raw_controls(content)
89
+ assert "\r" not in content
90
+ assert _no_raw_controls(repo.get_file_content("content.txt"))
91
+
92
+ def test_blame_and_contributors_are_safe(self, hostile_repo):
93
+ repo = GitRepo(hostile_repo)
94
+ sha = repo.get_file_commits("normal.py")[-1].hexsha
95
+ assert all(_no_raw_controls(author) for _, author, _ in repo.get_blame("normal.py", sha))
96
+ assert all(_no_raw_controls(name) for name, _ in repo.get_file_contributors("normal.py"))
97
+
98
+ def test_paths_are_literal_not_pathspecs(self, hostile_repo):
99
+ repo = GitRepo(hostile_repo)
100
+ slug = repo.get_file_commits("app/[slug]/page.tsx")
101
+ assert [c.message for c in slug] == ["[/] unbalanced close tag"]
102
+ s_commits = repo.get_file_commits("app/s/page.tsx")
103
+ assert len(s_commits) == 2
104
+ diff = repo.get_diff("app/[slug]/page.tsx", s_commits[0].hexsha, s_commits[-1].hexsha)
105
+ assert "s v2" not in diff
106
+
107
+ def test_non_ascii_file_names(self, hostile_repo):
108
+ repo = GitRepo(hostile_repo)
109
+ assert "café.py" in repo.get_tracked_files()
110
+ assert len(repo.get_file_commits("café.py")) == 2
111
+ newest = repo.get_all_commits()[0]
112
+ assert ("café.py", 1, 0) in repo.get_commit_files(newest.hexsha)
113
+
114
+ def test_record_marker_in_subject_does_not_break_parsing(self, hostile_repo):
115
+ repo = GitRepo(hostile_repo)
116
+ newest = repo.get_all_commits()[0]
117
+ assert newest.message == "Subject with ---GVT_START--- inside"
118
+ assert (newest.additions, newest.deletions) == (2, 0)
119
+ normal = repo.get_file_commits("normal.py")
120
+ assert normal[-1].message == "Subject with ---GVT_START--- inside"
121
+ assert normal[-1].additions == 1
122
+
123
+ def test_control_characters_in_file_names_never_reach_output(self, tmp_path):
124
+ repo_dir = str(tmp_path / "ctlnames")
125
+ os.makedirs(repo_dir)
126
+ repo = Repo.init(repo_dir)
127
+ with repo.config_writer() as cw:
128
+ cw.set_value("user", "name", "T")
129
+ cw.set_value("user", "email", "t@example.com")
130
+ _write(repo_dir, f"evil{ESC_TITLE}.txt", "x\n")
131
+ repo.git.add("-A")
132
+ repo.git.commit("-m", "init")
133
+ gvt = GitRepo(repo_dir)
134
+ listed = gvt.get_tracked_files() + [f[0] for f in gvt.get_commit_files(gvt.get_all_commits()[0].hexsha)]
135
+ assert listed and all(_no_raw_controls(path) for path in listed)
136
+
137
+ def test_markup_named_paths_listed(self, hostile_repo):
138
+ files = GitRepo(hostile_repo).get_tracked_files()
139
+ assert "[/]bad.py" in files and "[red]styled.py" in files
140
+
141
+
142
+ def _marker_script(tmp_path, name: str) -> tuple[str, str]:
143
+ marker = str(tmp_path / f"{name}.ran")
144
+ script = tmp_path / f"{name}.sh"
145
+ script.write_text(f"#!/bin/sh\ntouch {marker}\n")
146
+ script.chmod(script.stat().st_mode | stat.S_IEXEC)
147
+ return str(script), marker
148
+
149
+
150
+ class TestHostileGitConfig:
151
+ def test_external_diff_and_textconv_do_not_run(self, hostile_repo, tmp_path):
152
+ ext, ext_marker = _marker_script(tmp_path, "extdiff")
153
+ conv, conv_marker = _marker_script(tmp_path, "textconv")
154
+ _write(hostile_repo, ".gitattributes", "*.py diff=evil\n")
155
+ repo = Repo(hostile_repo)
156
+ with repo.config_writer() as cw:
157
+ cw.set_value("diff", "external", ext)
158
+ cw.set_value('diff "evil"', "textconv", conv)
159
+ gvt = GitRepo(hostile_repo)
160
+ commits = gvt.get_file_commits("normal.py")
161
+ assert "a2" in gvt.get_diff("normal.py", commits[0].hexsha, commits[-1].hexsha)
162
+ gvt.get_blame("normal.py", commits[-1].hexsha)
163
+ _write(hostile_repo, "normal.py", "changed\n")
164
+ gvt.has_uncommitted_changes("normal.py")
165
+ gvt.get_diff_to_working_tree("normal.py", commits[-1].hexsha)
166
+ assert not os.path.exists(ext_marker)
167
+ assert not os.path.exists(conv_marker)
168
+
169
+ def test_fsmonitor_does_not_run(self, hostile_repo, tmp_path):
170
+ hook, marker = _marker_script(tmp_path, "fsmonitor")
171
+ with Repo(hostile_repo).config_writer() as cw:
172
+ cw.set_value("core", "fsmonitor", hook)
173
+ gvt = GitRepo(hostile_repo)
174
+ gvt.get_untracked_files()
175
+ gvt.has_uncommitted_changes("normal.py")
176
+ gvt.get_commit_files(gvt.get_all_commits()[0].hexsha)
177
+ assert not os.path.exists(marker)
178
+
179
+
180
+ class TestApp:
181
+ SIZE = (120, 40)
182
+
183
+ @pytest.mark.parametrize("path", ["[/]bad.py", "[red]styled.py", "normal.py", "café.py"])
184
+ async def test_opening_hostile_files_does_not_crash(self, hostile_repo, path):
185
+ app = GVTApp(repo_path=hostile_repo, initial_file=path)
186
+ async with app.run_test(size=self.SIZE) as pilot:
187
+ await pilot.pause()
188
+ await app.workers.wait_for_complete()
189
+ await pilot.pause()
190
+ for key in ("h", "l", "B", "c"):
191
+ await pilot.press(key)
192
+ await pilot.pause()
193
+ assert app.is_running
194
+ assert app.current_file == path
195
+ assert app.query_one("#timeline-widget", TimelineWidget).commits
196
+
197
+ async def test_border_title_shows_path_literally(self, hostile_repo):
198
+ app = GVTApp(repo_path=hostile_repo, initial_file="[red]styled.py")
199
+ async with app.run_test(size=self.SIZE) as pilot:
200
+ await pilot.pause()
201
+ await app.workers.wait_for_complete()
202
+ await pilot.pause()
203
+ title = app.query_one("#diff-pane").border_title
204
+ # Rendered, the title must still show the brackets, not apply a style
205
+ assert "[red]styled.py" in Content.from_markup(str(title)).plain
206
+
207
+ async def test_tree_labels_show_names_literally(self, hostile_repo):
208
+ app = GVTApp(repo_path=hostile_repo)
209
+ async with app.run_test(size=self.SIZE) as pilot:
210
+ await pilot.pause()
211
+ tree = app.query_one(FileTreeWidget)._tree
212
+ labels = [str(child.label) for child in tree.root.children]
213
+ assert "[red]styled.py" in labels
@@ -0,0 +1,37 @@
1
+ """Tests for making repo-controlled text safe to show in a terminal."""
2
+
3
+ from gvt.textsafe import safe_text
4
+
5
+
6
+ def test_plain_text_unchanged():
7
+ assert safe_text("Fix the parser (#12)\ttabs stay\nnewlines stay") == (
8
+ "Fix the parser (#12)\ttabs stay\nnewlines stay"
9
+ )
10
+
11
+
12
+ def test_escape_sequences_become_visible():
13
+ assert safe_text("a\x1b]0;PWNED\x07b") == "a\\x1b]0;PWNED\\x07b"
14
+ assert safe_text("\x1b[2J") == "\\x1b[2J"
15
+
16
+
17
+ def test_c1_and_del_controls_become_visible():
18
+ assert safe_text("x\x9by\x7fz") == "x\\x9by\\x7fz"
19
+
20
+
21
+ def test_crlf_line_endings_are_normalized():
22
+ assert safe_text("one\r\ntwo\r\n") == "one\ntwo\n"
23
+ assert safe_text("trailing\r") == "trailing"
24
+
25
+
26
+ def test_lone_carriage_return_is_visible():
27
+ assert safe_text("overwrite\rme") == "overwrite\\x0dme"
28
+
29
+
30
+ def test_bidi_controls_become_visible():
31
+ # "Trojan Source": bidi overrides reorder what the terminal displays
32
+ assert safe_text("access‮level") == "access\\u202elevel"
33
+ assert safe_text("⁦x⁩") == "\\u2066x\\u2069"
34
+
35
+
36
+ def test_unicode_text_unchanged():
37
+ assert safe_text("café — naïve 日本") == "café — naïve 日本"
@@ -1 +0,0 @@
1
- __version__ = "0.2.2"