Skip to content

Commit 6a2ad11

Browse files
committed
Disables GitGutter from remote SSHFS file views
> see #54
1 parent da6e166 commit 6a2ad11

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Unmount on macOS
1717

18+
### Removed
19+
20+
- GitGutter from remote SSHFS file views
21+
1822
## [0.6.0] - 2025-08-06
1923

2024
### Added

sshubl/listeners.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import contextlib
22
import logging
33
import uuid
4-
from pathlib import Path
4+
from pathlib import Path, PurePath
55
from threading import Lock as ThreadingLock
66

77
import sublime
88
import sublime_plugin
99

1010
from .actions import SshKeepaliveThread
1111
from .project_data import SshSession, remove_from_project_folders, update_window_status
12+
from .paths import mounts_path
1213
from .ssh_utils import ssh_disconnect, umount_sshfs
1314

1415
_logger = logging.getLogger(__package__)
@@ -18,6 +19,40 @@
1819
_ka_threads_lock = ThreadingLock()
1920

2021

22+
def disable_git_gutter_for_view(view: sublime.View) -> None:
23+
"""
24+
This function disables GitGutter from view, if it contains a file relative to SSHubl mount paths
25+
folder (which is very likely supposed to be a remote file mounted over SSHFS).
26+
This is to prevent Sublime's Git integration to keep opening file descriptors which mess with
27+
unmounting operations.
28+
It requires GitGutter v1.7.5+.
29+
"""
30+
view_file_name = view.file_name()
31+
if view_file_name is None:
32+
# file doesn't exist on disk
33+
return
34+
35+
view_file_name_path = PurePath(view_file_name)
36+
# Python < 3.9, `PurePath.is_relative_to` doesn't exist
37+
try:
38+
view_file_name_path.relative_to(mounts_path)
39+
except ValueError:
40+
# file isn't relative to SSHFS mount points
41+
return
42+
43+
_logger.debug(
44+
"%s is likely a remote file, disabling GitGutter from view %d...",
45+
view_file_name_path,
46+
view.id(),
47+
)
48+
49+
view.settings().update(
50+
{
51+
"git_gutter_enable": False,
52+
}
53+
)
54+
55+
2156
def start_ka_thread_if_needed(window: sublime.Window) -> None:
2257
"""
2358
This function starts a new `SshKeepaliveThread` for passed `window`, only if there isn't any at
@@ -66,6 +101,7 @@ def on_pre_close_window(self, window):
66101

67102
class ViewEventListener(sublime_plugin.ViewEventListener):
68103
def on_load_async(self):
104+
disable_git_gutter_for_view(self.view)
69105
update_window_status(self.view.window())
70106

71107

0 commit comments

Comments
 (0)