Commit a200280a authored by Thibault North's avatar Thibault North Committed by Sven Brauch
Browse files

Add support for git worktrees

This patch adds support for the git worktree feature
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:
parent ad4c11f3
......@@ -276,7 +276,24 @@ QUrl GitPlugin::repositoryRoot(const QUrl& path)
bool GitPlugin::isValidDirectory(const QUrl & dirPath)
QDir dir=dotGitDirectory(dirPath);
QFile dotGitPotentialFile(dir.filePath(".git"));
// if .git is a file, we may be in a git worktree
QFileInfo dotGitPotentialFileInfo(dotGitPotentialFile);
if (!dotGitPotentialFileInfo.isDir() && dotGitPotentialFile.exists()) {
QString gitWorktreeFileContent;
if ( {
// the content should be gitdir: /path/to/the/.git/worktree
gitWorktreeFileContent = QString::fromUtf8(dotGitPotentialFile.readAll());
} else {
return false;
const auto items = gitWorktreeFileContent.split(' ');
if (items.size() == 2 && == "gitdir:") {
qCDebug(PLUGIN_GIT) << "we are in a git worktree" <<;
return true;
return dir.exists(QStringLiteral(".git/HEAD"));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment