I'm not an emacs power user nor very proficient at elisp.
I use magit quite heavily in emacs, and I'm regularly working on multiple git repositories at the same time. These are different repositories/worktrees for the same project, just with different branches checked out. I'm not sure if it is relevant, but these are Perl projects, using cperl-mode, and each project has a single TAGS files at the project root. The first time I use \`M-.\` (\`xref-find-definitions\`), I get prompted to load a TAGS file, and I select the one for the current repository I'm using. This works as expected. However when I happen to be editing a file from a different repository and hit M-., the previously loaded TAGS file is still used, so this brings me to the source file from the wrong repository. Since the files look identical, I don't notice this and regularly make edits in the wrong git worktree.
I saw that I can load multiple tags tables using visit-tags-table, and then switch between them using select-tags-table. Is there any way to automate this so that when I use \`M-.\` it automatically chooses the TAGS file closest to the current file path? I looked into project.el and projectile, but I couldn't find any examples for how to do this.