Skip to content

Commit 5539d96

Browse files
committed
common(fix[version-checks]): thread tmux_bin through callsites in pane.py and hooks.py
why: Version-check callsites in capture_pane() and HooksMixin methods query the system tmux instead of Server.tmux_bin, producing wrong results when a custom binary is configured. what: - Add _tmux_bin property to HooksMixin to resolve tmux_bin from self or self.server - Pass tmux_bin to has_lt_version() in 5 HooksMixin methods - Pass self.server.tmux_bin to has_gte_version() in Pane.capture_pane() - Fix test mock lambda to accept tmux_bin keyword argument
1 parent 309439d commit 5539d96

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/libtmux/hooks.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ def __init__(self, default_hook_scope: OptionScope | None) -> None:
7070
self.default_hook_scope = default_hook_scope
7171
self.hooks = Hooks()
7272

73+
@property
74+
def _tmux_bin(self) -> str | None:
75+
"""Resolve tmux_bin from self (Server) or self.server (Session/Window/Pane)."""
76+
return getattr(self, "tmux_bin", None) or getattr(
77+
getattr(self, "server", None), "tmux_bin", None
78+
)
79+
7380
def run_hook(
7481
self,
7582
hook: str,
@@ -89,7 +96,7 @@ def run_hook(
8996
assert scope in HOOK_SCOPE_FLAG_MAP
9097

9198
flag = HOOK_SCOPE_FLAG_MAP[scope]
92-
if flag in {"-p", "-w"} and has_lt_version("3.2"):
99+
if flag in {"-p", "-w"} and has_lt_version("3.2", tmux_bin=self._tmux_bin):
93100
warnings.warn(
94101
"Scope flag '-w' and '-p' requires tmux 3.2+. Ignoring.",
95102
stacklevel=2,
@@ -168,7 +175,7 @@ def set_hook(
168175
assert scope in HOOK_SCOPE_FLAG_MAP
169176

170177
flag = HOOK_SCOPE_FLAG_MAP[scope]
171-
if flag in {"-p", "-w"} and has_lt_version("3.2"):
178+
if flag in {"-p", "-w"} and has_lt_version("3.2", tmux_bin=self._tmux_bin):
172179
warnings.warn(
173180
"Scope flag '-w' and '-p' requires tmux 3.2+. Ignoring.",
174181
stacklevel=2,
@@ -221,7 +228,7 @@ def unset_hook(
221228
assert scope in HOOK_SCOPE_FLAG_MAP
222229

223230
flag = HOOK_SCOPE_FLAG_MAP[scope]
224-
if flag in {"-p", "-w"} and has_lt_version("3.2"):
231+
if flag in {"-p", "-w"} and has_lt_version("3.2", tmux_bin=self._tmux_bin):
225232
warnings.warn(
226233
"Scope flag '-w' and '-p' requires tmux 3.2+. Ignoring.",
227234
stacklevel=2,
@@ -286,7 +293,7 @@ def show_hooks(
286293
assert scope in HOOK_SCOPE_FLAG_MAP
287294

288295
flag = HOOK_SCOPE_FLAG_MAP[scope]
289-
if flag in {"-p", "-w"} and has_lt_version("3.2"):
296+
if flag in {"-p", "-w"} and has_lt_version("3.2", tmux_bin=self._tmux_bin):
290297
warnings.warn(
291298
"Scope flag '-w' and '-p' requires tmux 3.2+. Ignoring.",
292299
stacklevel=2,
@@ -344,7 +351,7 @@ def _show_hook(
344351
assert scope in HOOK_SCOPE_FLAG_MAP
345352

346353
flag = HOOK_SCOPE_FLAG_MAP[scope]
347-
if flag in {"-p", "-w"} and has_lt_version("3.2"):
354+
if flag in {"-p", "-w"} and has_lt_version("3.2", tmux_bin=self._tmux_bin):
348355
warnings.warn(
349356
"Scope flag '-w' and '-p' requires tmux 3.2+. Ignoring.",
350357
stacklevel=2,

src/libtmux/pane.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def capture_pane(
411411
if preserve_trailing:
412412
cmd.append("-N")
413413
if trim_trailing:
414-
if has_gte_version("3.4"):
414+
if has_gte_version("3.4", tmux_bin=self.server.tmux_bin):
415415
cmd.append("-T")
416416
else:
417417
warnings.warn(

tests/test_pane_capture_pane.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def test_capture_pane_trim_trailing_warning(
453453
from libtmux import common
454454

455455
# Mock has_gte_version to return False for 3.4
456-
monkeypatch.setattr(common, "has_gte_version", lambda v: v != "3.4")
456+
monkeypatch.setattr(common, "has_gte_version", lambda v, **kw: v != "3.4")
457457

458458
pane = session.active_window.split(shell="sh")
459459

0 commit comments

Comments
 (0)