| 298 | } |
| 299 | |
| 300 | bool GitPlugin::isValidDirectory(const QUrl & dirPath) |
| 301 | { |
| 302 | QDir dir = dotGitDirectory(dirPath, true); |
| 303 | QFile dotGitPotentialFile(dir.filePath(QStringLiteral(".git"))); |
| 304 | // if .git is a file, we may be in a git worktree |
| 305 | QFileInfo dotGitPotentialFileInfo(dotGitPotentialFile); |
| 306 | if (!dotGitPotentialFileInfo.isDir() && dotGitPotentialFile.exists()) { |
| 307 | QString gitWorktreeFileContent; |
| 308 | if (dotGitPotentialFile.open(QFile::ReadOnly)) { |
| 309 | // the content should be gitdir: /path/to/the/.git/worktree |
| 310 | gitWorktreeFileContent = QString::fromUtf8(dotGitPotentialFile.readAll()); |
| 311 | dotGitPotentialFile.close(); |
| 312 | } else { |
| 313 | return false; |
| 314 | } |
| 315 | const auto items = gitWorktreeFileContent.split(QLatin1Char(' ')); |
| 316 | if (items.size() == 2 && items.at(0) == QLatin1String("gitdir:")) { |
| 317 | qCDebug(PLUGIN_GIT) << "we are in a git worktree" << items.at(1); |
| 318 | return true; |
| 319 | } |
| 320 | } |
| 321 | return dir.exists(QStringLiteral(".git/HEAD")); |
| 322 | } |
| 323 | |
| 324 | bool GitPlugin::isValidRemoteRepositoryUrl(const QUrl& remoteLocation) |
| 325 | { |