Subject: Re: bug#79126: vc-switch-working-tree does not work if there is no matching file

From: Sean Whitton <[email-masked]>
Date: Wed, 30 Jul 2025 12:04:06 +0100

Hello,

On Wed 30 Jul 2025 at 05:36am +03, Dmitry Gutov wrote:

> X-Debbugs-CC: [email-masked], [email-masked]
>
> Hi!
>
> If the current buffer does not visit a file (such as Dired, mentioned in a
> FIXME comment), or if the current file has no corresponding on the other
> worktree, we end up with an error.
>
> Like
>
>   file-relative-name: Wrong type argument: stringp, nil
>
> or
>
>   File ‘lisp/progmodes/abc.el’ not found in ‘~/vc/emacs-28/’
>
> I guess some of these could be improved in project-find-matching-file (support
> for more major modes?) but semantically it seems like vc-switch-working-tree
> should try harder. Falling back to visiting the worktree root in Dired, if it
> doesn't find a better choice.

I was thinking I would implement switching between Dired directories and
VC-Dir buffers in project-find-matching-file, yeah.

Maybe when the file doesn't exist we could fall back to going only as
high up the tree as we need to.  So for example if foo/bar.el doesn't
exist in the other worktree but foo/ does, invoking
vc-switch-working-tree would go to a dired buffer visiting foo/.

The last resort fallback could possibly be to call project-switch-project?

-- 
Sean Whitton