Commit d1ebbcb8 authored by Friedemann Kleint's avatar Friedemann Kleint

Fixes: git commit fails due to wrong working directory

Details: Execute git status from repo directory
parent d8bc36eb
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <QtCore/QRegExp> #include <QtCore/QRegExp>
#include <QtCore/QTemporaryFile> #include <QtCore/QTemporaryFile>
#include <QtCore/QFuture> #include <QtCore/QFuture>
#include <QtCore/QTime>
#include <QtGui/QErrorMessage> #include <QtGui/QErrorMessage>
...@@ -76,6 +77,12 @@ inline Core::IEditor* locateEditor(const Core::ICore *core, const char *property ...@@ -76,6 +77,12 @@ inline Core::IEditor* locateEditor(const Core::ICore *core, const char *property
return 0; return 0;
} }
static QString formatCommand(const QString &binary, const QStringList &args)
{
const QString timeStamp = QTime::currentTime().toString(QLatin1String("HH:mm"));
return GitClient::tr("%1 Executing: %2 %3\n").arg(timeStamp, binary, args.join(QString(QLatin1Char(' '))));
}
GitClient::GitClient(GitPlugin* plugin, Core::ICore *core) : GitClient::GitClient(GitPlugin* plugin, Core::ICore *core) :
m_msgWait(tr("Waiting for data...")), m_msgWait(tr("Waiting for data...")),
m_plugin(plugin), m_plugin(plugin),
...@@ -331,7 +338,8 @@ void GitClient::executeGit(const QString &workingDirectory, const QStringList &a ...@@ -331,7 +338,8 @@ void GitClient::executeGit(const QString &workingDirectory, const QStringList &a
{ {
if (Git::Constants::debug) if (Git::Constants::debug)
qDebug() << "executeGit" << workingDirectory << arguments << editor; qDebug() << "executeGit" << workingDirectory << arguments << editor;
outputWindow->clearContents();
m_plugin->m_outputWindow->append(formatCommand(QLatin1String(kGitCommand), arguments));
QProcess process; QProcess process;
ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment(); ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment();
...@@ -363,8 +371,11 @@ bool GitClient::synchronousGit(const QString &workingDirectory ...@@ -363,8 +371,11 @@ bool GitClient::synchronousGit(const QString &workingDirectory
{ {
if (Git::Constants::debug) if (Git::Constants::debug)
qDebug() << "synchronousGit" << workingDirectory << arguments; qDebug() << "synchronousGit" << workingDirectory << arguments;
QProcess process; const QString binary = QLatin1String(kGitCommand);
m_plugin->m_outputWindow->append(formatCommand(binary, arguments));
QProcess process;
process.setWorkingDirectory(workingDirectory); process.setWorkingDirectory(workingDirectory);
ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment(); ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment();
...@@ -372,7 +383,7 @@ bool GitClient::synchronousGit(const QString &workingDirectory ...@@ -372,7 +383,7 @@ bool GitClient::synchronousGit(const QString &workingDirectory
environment.set(QLatin1String("PATH"), m_plugin->m_settingsPage->path()); environment.set(QLatin1String("PATH"), m_plugin->m_settingsPage->path());
process.setEnvironment(environment.toStringList()); process.setEnvironment(environment.toStringList());
process.start(QLatin1String(kGitCommand), arguments); process.start(binary, arguments);
if (!process.waitForFinished()) { if (!process.waitForFinished()) {
if (errorText) if (errorText)
*errorText = "Error: Git timed out"; *errorText = "Error: Git timed out";
...@@ -477,6 +488,9 @@ bool GitClient::getCommitData(const QString &workingDirectory, ...@@ -477,6 +488,9 @@ bool GitClient::getCommitData(const QString &workingDirectory,
CommitData *d, CommitData *d,
QString *errorMessage) QString *errorMessage)
{ {
if (Git::Constants::debug)
qDebug() << Q_FUNC_INFO << workingDirectory;
d->clear(); d->clear();
// Find repo // Find repo
...@@ -506,9 +520,10 @@ bool GitClient::getCommitData(const QString &workingDirectory, ...@@ -506,9 +520,10 @@ bool GitClient::getCommitData(const QString &workingDirectory,
QByteArray outputText; QByteArray outputText;
QByteArray errorText; QByteArray errorText;
QStringList statusArgs(QLatin1String("status")); QStringList statusArgs(QLatin1String("status"));
if (untrackedFilesInCommit) if (untrackedFilesInCommit)
statusArgs << QLatin1String("-u"); statusArgs << QLatin1String("-u");
const bool statusRc = synchronousGit(workingDirectory, statusArgs, &outputText, &errorText); const bool statusRc = synchronousGit(repoDirectory, statusArgs, &outputText, &errorText);
if (!statusRc) { if (!statusRc) {
// Something fatal // Something fatal
if (!outputText.contains(kBranchIndicatorC)) { if (!outputText.contains(kBranchIndicatorC)) {
...@@ -565,24 +580,24 @@ bool GitClient::getCommitData(const QString &workingDirectory, ...@@ -565,24 +580,24 @@ bool GitClient::getCommitData(const QString &workingDirectory,
} }
// addAndCommit: // addAndCommit:
bool GitClient::addAndCommit(const QString &workingDirectory, bool GitClient::addAndCommit(const QString &repositoryDirectory,
const GitSubmitEditorPanelData &data, const GitSubmitEditorPanelData &data,
const QString &messageFile, const QString &messageFile,
const QStringList &checkedFiles, const QStringList &checkedFiles,
const QStringList &origCommitFiles) const QStringList &origCommitFiles)
{ {
if (Git::Constants::debug) if (Git::Constants::debug)
qDebug() << "GitClient::addAndCommit:" << workingDirectory << checkedFiles << origCommitFiles; qDebug() << "GitClient::addAndCommit:" << repositoryDirectory << checkedFiles << origCommitFiles;
// Do we need to reset any files that had been added before // Do we need to reset any files that had been added before
// (did the user uncheck any previously added files) // (did the user uncheck any previously added files)
const QSet<QString> resetFiles = origCommitFiles.toSet().subtract(checkedFiles.toSet()); const QSet<QString> resetFiles = origCommitFiles.toSet().subtract(checkedFiles.toSet());
if (!resetFiles.empty()) if (!resetFiles.empty())
if (!synchronousReset(workingDirectory, resetFiles.toList())) if (!synchronousReset(repositoryDirectory, resetFiles.toList()))
return false; return false;
// Re-add all to make sure we have the latest changes // Re-add all to make sure we have the latest changes
if (!synchronousAdd(workingDirectory, checkedFiles)) if (!synchronousAdd(repositoryDirectory, checkedFiles))
return false; return false;
// Do the final commit // Do the final commit
...@@ -593,7 +608,7 @@ bool GitClient::addAndCommit(const QString &workingDirectory, ...@@ -593,7 +608,7 @@ bool GitClient::addAndCommit(const QString &workingDirectory,
QByteArray outputText; QByteArray outputText;
QByteArray errorText; QByteArray errorText;
const bool rc = synchronousGit(workingDirectory, args, &outputText, &errorText); const bool rc = synchronousGit(repositoryDirectory, args, &outputText, &errorText);
const QString message = rc ? const QString message = rc ?
tr("Committed %n file(s).", 0, checkedFiles.size()) : tr("Committed %n file(s).", 0, checkedFiles.size()) :
tr("Unable to commit %n file(s): %1", 0, checkedFiles.size()).arg(QString::fromLocal8Bit(errorText)); tr("Unable to commit %n file(s): %1", 0, checkedFiles.size()).arg(QString::fromLocal8Bit(errorText));
......
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