Changeset View
Changeset View
Standalone View
Standalone View
plugins/git/gitplugin.cpp
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Line(s) | |||||
272 | { | 272 | { | ||
273 | return QUrl::fromLocalFile(dotGitDirectory(path).absolutePath()); | 273 | return QUrl::fromLocalFile(dotGitDirectory(path).absolutePath()); | ||
274 | } | 274 | } | ||
275 | 275 | | |||
276 | bool GitPlugin::isValidDirectory(const QUrl & dirPath) | 276 | bool GitPlugin::isValidDirectory(const QUrl & dirPath) | ||
277 | { | 277 | { | ||
278 | QDir dir=dotGitDirectory(dirPath); | 278 | QDir dir=dotGitDirectory(dirPath); | ||
279 | QFile dotGitPotentialFile(dir.filePath(QStringLiteral(".git"))); | 279 | QFile dotGitPotentialFile(dir.filePath(QStringLiteral(".git"))); | ||
280 | if (!dotGitPotentialFile.isLocalFile()) { | ||||
281 | return false; | ||||
282 | } | ||||
280 | // if .git is a file, we may be in a git worktree | 283 | // if .git is a file, we may be in a git worktree | ||
281 | QFileInfo dotGitPotentialFileInfo(dotGitPotentialFile); | 284 | QFileInfo dotGitPotentialFileInfo(dotGitPotentialFile); | ||
282 | if (!dotGitPotentialFileInfo.isDir() && dotGitPotentialFile.exists()) { | 285 | if (!dotGitPotentialFileInfo.isDir() && dotGitPotentialFile.exists()) { | ||
283 | QString gitWorktreeFileContent; | 286 | QString gitWorktreeFileContent; | ||
284 | if (dotGitPotentialFile.open(QFile::ReadOnly)) { | 287 | if (dotGitPotentialFile.open(QFile::ReadOnly)) { | ||
285 | // the content should be gitdir: /path/to/the/.git/worktree | 288 | // the content should be gitdir: /path/to/the/.git/worktree | ||
286 | gitWorktreeFileContent = QString::fromUtf8(dotGitPotentialFile.readAll()); | 289 | gitWorktreeFileContent = QString::fromUtf8(dotGitPotentialFile.readAll()); | ||
287 | dotGitPotentialFile.close(); | 290 | dotGitPotentialFile.close(); | ||
288 | } else { | 291 | } else { | ||
289 | return false; | 292 | return false; | ||
290 | } | 293 | } | ||
291 | const auto items = gitWorktreeFileContent.split(' '); | 294 | const auto items = gitWorktreeFileContent.split(' '); | ||
292 | if (items.size() == 2 && items.at(0) == QLatin1String("gitdir:")) { | 295 | if (items.size() == 2 && items.at(0) == QLatin1String("gitdir:")) { | ||
293 | qCDebug(PLUGIN_GIT) << "we are in a git worktree" << items.at(1); | 296 | qCDebug(PLUGIN_GIT) << "we are in a git worktree" << items.at(1); | ||
294 | return true; | 297 | return true; | ||
295 | } | 298 | } | ||
296 | } | 299 | } | ||
297 | return dir.exists(QStringLiteral(".git/HEAD")); | 300 | if (!dir.exists(QStringLiteral(".git/HEAD"))) { | ||
301 | return false; | ||||
302 | } | ||||
303 | // check if plugin should be disabled by reading git config | ||||
304 | QString disabled = readConfigOption(dirPath, "kdevgit.disabled"); | ||||
305 | return disabled.compare(QLatin1String("true"), Qt::CaseInsensitive) != 0; | ||||
298 | } | 306 | } | ||
299 | 307 | | |||
300 | bool GitPlugin::isValidRemoteRepositoryUrl(const QUrl& remoteLocation) | 308 | bool GitPlugin::isValidRemoteRepositoryUrl(const QUrl& remoteLocation) | ||
301 | { | 309 | { | ||
302 | if (remoteLocation.isLocalFile()) { | 310 | if (remoteLocation.isLocalFile()) { | ||
303 | QFileInfo fileInfo(remoteLocation.toLocalFile()); | 311 | QFileInfo fileInfo(remoteLocation.toLocalFile()); | ||
304 | if (fileInfo.isDir()) { | 312 | if (fileInfo.isDir()) { | ||
305 | QDir dir(fileInfo.filePath()); | 313 | QDir dir(fileInfo.filePath()); | ||
▲ Show 20 Lines • Show All 1256 Lines • Show Last 20 Lines |