void BazaarPlugin::showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusItem> &status) { VcsBase::VcsBaseOutputWindow *outputWindow = VcsBase::VcsBaseOutputWindow::instance(); //Once we receive our data release the connection so it can be reused elsewhere disconnect(m_client, SIGNAL(parsedStatus(QList<VcsBase::VcsBaseClient::StatusItem>)), this, SLOT(showCommitWidget(QList<VcsBase::VcsBaseClient::StatusItem>))); if (status.isEmpty()) { outputWindow->appendError(tr("There are no changes to commit.")); return; } // Start new temp file Utils::TempFileSaver saver; // Keep the file alive, else it removes self and forgets its name saver.setAutoRemove(false); if (!saver.finalize()) { VcsBase::VcsBaseOutputWindow::instance()->append(saver.errorString()); return; } Core::IEditor *editor = Core::EditorManager::openEditor(saver.fileName(), Constants::COMMIT_ID, Core::EditorManager::ModeSwitch); if (!editor) { outputWindow->appendError(tr("Unable to create an editor for the commit.")); return; } CommitEditor *commitEditor = qobject_cast<CommitEditor *>(editor); if (!commitEditor) { outputWindow->appendError(tr("Unable to create a commit editor.")); return; } commitEditor->registerActions(m_editorUndo, m_editorRedo, m_editorCommit, m_editorDiff); connect(commitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(diffFromEditorSelected(QStringList))); commitEditor->setCheckScriptWorkingDirectory(m_submitRepository); const QString msg = tr("Commit changes for \"%1\"."). arg(QDir::toNativeSeparators(m_submitRepository)); commitEditor->setDisplayName(msg); const BranchInfo branch = m_client->synchronousBranchQuery(m_submitRepository); commitEditor->setFields(m_submitRepository, branch, m_bazaarSettings.stringValue(BazaarSettings::userNameKey), m_bazaarSettings.stringValue(BazaarSettings::userEmailKey), status); }
void GitEditor::applyDiffChunk(const VcsBase::DiffChunk& chunk, bool revert) { VcsBase::VcsBaseOutputWindow *outwin = VcsBase::VcsBaseOutputWindow::instance(); QTemporaryFile patchFile; if (!patchFile.open()) return; const QString baseDir = workingDirectory(); patchFile.write(chunk.header); patchFile.write(chunk.chunk); patchFile.close(); GitClient *client = GitPlugin::instance()->gitClient(); QStringList args = QStringList() << QLatin1String("--cached"); if (revert) args << QLatin1String("--reverse"); QString errorMessage; if (client->synchronousApplyPatch(baseDir, patchFile.fileName(), &errorMessage, args)) { if (errorMessage.isEmpty()) outwin->append(tr("Chunk successfully staged")); else outwin->append(errorMessage); if (revert) emit diffChunkReverted(chunk); else emit diffChunkApplied(chunk); } else { outwin->appendError(errorMessage); } }