fix(scm): resolve the editor's repository on the file's own machine

`scm_editor_target` paired the focused buffer's path with `spawn_host`,
the window's own machine. That was true of every file the tree could
open, but an SFTP buffer carries a path from somewhere else: with
`/home/me/proj` probed on both boxes, the panel would resolve the remote
file against the *local* repository and open a `.git` watch on it —
another machine's branch and status, shown for this file. The two
sibling targets already take the host from wherever the path came from.

Also drop a claim the watcher comment could not keep: a host that cannot
watch has no external-change detection at all, not a save-time check.
There is no such check, and adding one needs a "keep mine" that survives
to the next save, which the conflict banner does not have.
This commit is contained in:
l0ng-ai
2026-08-16 18:45:50 +08:00
parent 6a15d212a7
commit 05cdf17382
2 changed files with 13 additions and 3 deletions
+5 -1
View File
@@ -885,7 +885,11 @@ impl Tty7App {
return None;
}
let open = code.active_file()?;
let host = self.spawn_host(cx);
// The file's host, not the window's. They are the same for everything
// the tree can open, but a buffer read over SFTP carries a path from
// another machine, and pairing it with this one's host would resolve
// it against a local repository that merely shares the path.
let host = open.host.id();
let root = cx
.try_global::<crate::terminal::git_status::GitStatusCache>()?
.repo_root_for(host, open.path.parent()?)?;
+8 -2
View File
@@ -294,8 +294,14 @@ impl Tty7App {
fn editor_rebuild_watcher(&mut self, cx: &mut Context<Self>) {
// Only files on the host the watch itself runs on. A path from
// another machine — an SFTP file, say — does not exist under that
// watcher's feet, and hosts without watching (SFTP again) fall back
// to the save-time conflict check instead.
// watcher's feet, and would either miss or, worse, match a local file
// that happens to share its name.
//
// A host that cannot watch therefore gets no external-change
// detection at all: an SFTP buffer will not notice the file changing
// underneath it, and saving overwrites whatever is there. Catching
// that at save time needs a "keep mine" that survives to the next
// save, which the conflict banner does not have yet.
let watch_host = self.spawn_host(cx);
let files: HashSet<PathBuf> = self
.tabs