The feature "show annotate" that displays the equivalent of the git blame function works in main git repositories (where the .git/ folder lies), but not in the git worktrees (see https://git-scm.com/docs/git-worktree ). In worktrees, a .git file exists (no .git folder), pointing to the main git folder. It contains "gitdir: /path/to/the/main/repo". Kdevelop is not able to follow this link to show annotations. When calling for annotations, it fails with the message: "Could not annotate the document because it is not part of a version-controlled project."
Interesting issue. Maybe you want to have a look at it yourself and fix the issue in KDevelop? The Git plugin is pretty much self-contained and easy to work with. To get started: https://www.kdevelop.org/contribute-kdevelop
The place where this needs to be fixed I think is plugins/git/gitplugin.cpp:QUrl GitPlugin::repositoryRoot(const QUrl& path).
Thanks for all the pointers. Since it's not trivial to prepare a dev environment for kdevelop *and* work at the same time ("You have to remove all KDevelop packages provided by your distribution"), I wasn't able to build/check a fix yet, but I came up with the following that might work (or not?): diff --git a/plugins/git/gitplugin.cpp b/plugins/git/gitplugin.cpp index b56d53d..b78e6bd 100644 --- a/plugins/git/gitplugin.cpp +++ b/plugins/git/gitplugin.cpp @@ -88,7 +88,18 @@ QDir dotGitDirectory(const QUrl& dirPath) if (dir.isRoot()) { qCWarning(PLUGIN_GIT) << "couldn't find the git root for" << dirPath; } - + // is this a worktree ? + QFile dotGitPotentialFile(dir.filePath(".git")); + if (!dotGitPotentialFile.exists()) { + if (dotGitPotentialFile.open(QFile::ReadOnly)) { + QTextStream content(&dotGitPotentialFile); + QString gitWorktreeFileContent; + content >> gitWorktreeFileContent; + const auto items = gitWorktreeFileContent.splitRef(' ', QString::SkipEmptyParts); + if (items.size() == 2 && items.at(0) == "gitdir:") + return QDir(items.at(1)); + } + } return dir; } (Again: I don't even know if this compiles - and maybe I'm totally off :)) Comments/feedback appreciated.
Seems a bit strange, first you check whether the file does not exist, then you open it? ;) But otherwise looks good, it'd be great if you could test it and put it on phabricator.kde.org. Having a development setup is actually quite simple, you can either just use the KDevelop you work on for working as well (that works fine with --pick-session) or use the AppImage we provide on kdevelop.org/download.
Hu, right, that what happens when one edits the diff... :) Ok. I'll be off for two weeks, I'll come back to this bug ASAP.
Turns out only the function isValidDirectory() needs fixing. A request is now available on Phabricator here: https://phabricator.kde.org/D5014
Git commit a200280a9b5b1d2ab5e9a98863db7eeaa9373174 by Sven Brauch, on behalf of Thibault North. Committed on 11/03/2017 at 14:49. Pushed by brauch into branch 'master'. Add support for git worktrees This patch adds support for the git worktree feature (see https://git-scm.com/docs/git-worktree). In a worktree, there is no .git/ folder, rather a .git file which contains a path to the corresponding worktree within the .git folder of the repository. Differential Revision: https://phabricator.kde.org/D5014 M +18 -1 plugins/git/gitplugin.cpp https://commits.kde.org/kdevplatform/a200280a9b5b1d2ab5e9a98863db7eeaa9373174
Thanks Thibault!
Thanks for the guidance and fast integration!