diff --git a/src/plugins/git/changeselectiondialog.cpp b/src/plugins/git/changeselectiondialog.cpp index 62c4c35a10268f5315592d7c226e39ccb15cc32b..e137f99b2ff65fce11990827d6f1651f276a903c 100644 --- a/src/plugins/git/changeselectiondialog.cpp +++ b/src/plugins/git/changeselectiondialog.cpp @@ -31,6 +31,8 @@ **************************************************************************/ #include "changeselectiondialog.h" +#include "gitplugin.h" +#include "gitclient.h" #include <QFileDialog> #include <QMessageBox> @@ -43,7 +45,7 @@ ChangeSelectionDialog::ChangeSelectionDialog(QWidget *parent) { m_ui.setupUi(this); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - connect(m_ui.repositoryButton, SIGNAL(clicked()), this, SLOT(selectWorkingDirectory())); + connect(m_ui.workingDirectoryButton, SIGNAL(clicked()), this, SLOT(selectWorkingDirectory())); setWindowTitle(tr("Select a Git Commit")); } @@ -52,14 +54,14 @@ QString ChangeSelectionDialog::change() const return m_ui.changeNumberEdit->text(); } -QString ChangeSelectionDialog::repository() const +QString ChangeSelectionDialog::workingDirectory() const { - return m_ui.repositoryEdit->text(); + return m_ui.workingDirectoryEdit->text(); } -void ChangeSelectionDialog::setRepository(const QString &s) +void ChangeSelectionDialog::setWorkingDirectory(const QString &s) { - m_ui.repositoryEdit->setText(QDir::toNativeSeparators(s)); + m_ui.workingDirectoryEdit->setText(QDir::toNativeSeparators(s)); m_ui.changeNumberEdit->setFocus(Qt::ActiveWindowFocusReason); m_ui.changeNumberEdit->setText(QLatin1String("HEAD")); m_ui.changeNumberEdit->selectAll(); @@ -67,28 +69,20 @@ void ChangeSelectionDialog::setRepository(const QString &s) void ChangeSelectionDialog::selectWorkingDirectory() { - static QString location; - location = QFileDialog::getExistingDirectory(this, - tr("Select Git Repository"), - location); + QString location = QFileDialog::getExistingDirectory(this, tr("Select Working Directory"), + m_ui.workingDirectoryEdit->text()); if (location.isEmpty()) return; // Verify that the location is a repository - // We are polite, we also allow to specify a directory, which is not - // the head directory of the repository. - QDir repository(location); - do { - if (repository.entryList(QDir::AllDirs|QDir::Hidden).contains(QLatin1String(".git"))) { - m_ui.repositoryEdit->setText(repository.absolutePath()); - return; - } - } while (repository.cdUp()); - - // Did not find a repo - QMessageBox::critical(this, tr("Error"), - tr("Selected directory is not a Git repository")); - + // We allow specifying a directory, which is not the head directory of the repository. + // This is useful for git show commit:./file + QString topLevel = GitPlugin::instance()->gitClient()->findRepositoryForDirectory(location); + if (!topLevel.isEmpty()) + m_ui.workingDirectoryEdit->setText(location); + else // Did not find a repo + QMessageBox::critical(this, tr("Error"), + tr("Selected directory is not a Git repository")); } } diff --git a/src/plugins/git/changeselectiondialog.h b/src/plugins/git/changeselectiondialog.h index 0020cdc72482e7e3b95dad974bffcbd8c8201afd..f77274edf74364400ee1c0c1bd88c35d65f14107 100644 --- a/src/plugins/git/changeselectiondialog.h +++ b/src/plugins/git/changeselectiondialog.h @@ -48,8 +48,8 @@ public: QString change() const; - QString repository() const; - void setRepository(const QString &s); + QString workingDirectory() const; + void setWorkingDirectory(const QString &s); public slots: void selectWorkingDirectory(); diff --git a/src/plugins/git/changeselectiondialog.ui b/src/plugins/git/changeselectiondialog.ui index 1b6180cad29f1628e44821d627be5db4d0526d1a..7cc88ec38b67603d88d561cfd06de2d11b3a8e02 100644 --- a/src/plugins/git/changeselectiondialog.ui +++ b/src/plugins/git/changeselectiondialog.ui @@ -17,15 +17,15 @@ <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="text"> - <string>Repository location:</string> + <string>Working directory:</string> </property> </widget> </item> <item row="0" column="1"> - <widget class="QLineEdit" name="repositoryEdit"/> + <widget class="QLineEdit" name="workingDirectoryEdit"/> </item> <item row="0" column="2"> - <widget class="QPushButton" name="repositoryButton"> + <widget class="QPushButton" name="workingDirectoryButton"> <property name="text"> <string>Select</string> </property> diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index bd11886cabde0af47dfd365730142f3bf442fd44..6c8c557e9baf2afdae4724b4184eb01a02c99393 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -438,7 +438,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) tr("Remotes..."), Core::Id("Git.RemoteList"), globalcontext, false, SLOT(remoteList())); - m_showAction = new QAction(tr("Show Commit..."), this); + m_showAction = new QAction(tr("Show..."), this); Core::Command *showCommitCommand = actionManager->registerAction(m_showAction, "Git.ShowCommit", globalcontext); connect(m_showAction, SIGNAL(triggered()), this, SLOT(showCommit())); gitContainer->addAction(showCommitCommand); @@ -1038,8 +1038,10 @@ void GitPlugin::showCommit() if (!m_changeSelectionDialog) m_changeSelectionDialog = new ChangeSelectionDialog(); - if (state.hasTopLevel()) - m_changeSelectionDialog->setRepository(state.topLevel()); + if (state.hasFile()) + m_changeSelectionDialog->setWorkingDirectory(state.currentFileDirectory()); + else if (state.hasTopLevel()) + m_changeSelectionDialog->setWorkingDirectory(state.topLevel()); if (m_changeSelectionDialog->exec() != QDialog::Accepted) return; @@ -1047,7 +1049,7 @@ void GitPlugin::showCommit() if (change.isEmpty()) return; - m_gitClient->show(m_changeSelectionDialog->repository(), change); + m_gitClient->show(m_changeSelectionDialog->workingDirectory(), change); } const GitSettings &GitPlugin::settings() const