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
(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
BUG:375849
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 (dotGitPotentialFile.open(QFile::ReadOnly)) {
// the content should be gitdir: /path/to/the/.git/worktree
gitWorktreeFileContent = QString::fromUtf8(dotGitPotentialFile.readAll());
dotGitPotentialFile.close();
} else {
return false;
}
const auto items = gitWorktreeFileContent.split(' ');
if (items.size() == 2 && items.at(0) == "gitdir:") {
qCDebug(PLUGIN_GIT) << "we are in a git worktree" << items.at(1);
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