forked from qt-creator/qt-creator
Fixes: Show untracked files in git submit dialog
Details: Move routine to get project file list into VCSBase, use it in p4 and git to filter submit lists.
This commit is contained in:
@@ -65,8 +65,6 @@ const char *const kGitCommand = "git";
|
|||||||
const char *const kGitDirectoryC = ".git";
|
const char *const kGitDirectoryC = ".git";
|
||||||
const char *const kBranchIndicatorC = "# On branch";
|
const char *const kBranchIndicatorC = "# On branch";
|
||||||
|
|
||||||
enum { untrackedFilesInCommit = 0 };
|
|
||||||
|
|
||||||
static inline QString msgServerFailure()
|
static inline QString msgServerFailure()
|
||||||
{
|
{
|
||||||
return GitClient::tr(
|
return GitClient::tr(
|
||||||
@@ -631,7 +629,7 @@ GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
|
|||||||
# Changed but not updated:
|
# Changed but not updated:
|
||||||
#<tab>modified:<blanks>git.pro
|
#<tab>modified:<blanks>git.pro
|
||||||
# Untracked files:
|
# Untracked files:
|
||||||
#<tab>modified:<blanks>git.pro
|
#<tab>git.pro
|
||||||
\endcode
|
\endcode
|
||||||
*/
|
*/
|
||||||
static bool parseFiles(const QString &output, CommitData *d)
|
static bool parseFiles(const QString &output, CommitData *d)
|
||||||
@@ -677,7 +675,7 @@ static bool parseFiles(const QString &output, CommitData *d)
|
|||||||
d->unstagedFiles.push_back(trimFileSpecification(fileSpec));
|
d->unstagedFiles.push_back(trimFileSpecification(fileSpec));
|
||||||
break;
|
break;
|
||||||
case UntrackedFiles:
|
case UntrackedFiles:
|
||||||
d->untrackedFiles.push_back(QLatin1String("untracked: ") + fileSpec);
|
d->untrackedFiles.push_back(fileSpec);
|
||||||
break;
|
break;
|
||||||
case None:
|
case None:
|
||||||
break;
|
break;
|
||||||
@@ -691,6 +689,25 @@ static bool parseFiles(const QString &output, CommitData *d)
|
|||||||
return !d->stagedFiles.empty() || !d->unstagedFiles.empty() || !d->untrackedFiles.empty();
|
return !d->stagedFiles.empty() || !d->unstagedFiles.empty() || !d->untrackedFiles.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter out untracked files that are not part of the project
|
||||||
|
static void filterUntrackedFilesOfProject(const QString &repoDir, QStringList *l)
|
||||||
|
{
|
||||||
|
if (l->empty())
|
||||||
|
return;
|
||||||
|
const QStringList nativeProjectFiles = VCSBase::VCSBaseSubmitEditor::currentProjectFiles(true);
|
||||||
|
if (nativeProjectFiles.empty())
|
||||||
|
return;
|
||||||
|
const QDir repoDirectory(repoDir);
|
||||||
|
for (QStringList::iterator it = l->begin(); it != l->end(); ) {
|
||||||
|
const QString path = QDir::toNativeSeparators(repoDirectory.absoluteFilePath(*it));
|
||||||
|
if (nativeProjectFiles.contains(path)) {
|
||||||
|
++it;
|
||||||
|
} else {
|
||||||
|
it = l->erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GitClient::getCommitData(const QString &workingDirectory,
|
bool GitClient::getCommitData(const QString &workingDirectory,
|
||||||
QString *commitTemplate,
|
QString *commitTemplate,
|
||||||
CommitData *d,
|
CommitData *d,
|
||||||
@@ -726,7 +743,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
|||||||
|
|
||||||
// Run status. Note that it has exitcode 1 if there are no added files.
|
// Run status. Note that it has exitcode 1 if there are no added files.
|
||||||
QString output;
|
QString output;
|
||||||
switch (gitStatus(repoDirectory, untrackedFilesInCommit, &output, errorMessage)) {
|
switch (gitStatus(repoDirectory, true, &output, errorMessage)) {
|
||||||
case StatusChanged:
|
case StatusChanged:
|
||||||
break;
|
break;
|
||||||
case StatusUnchanged:
|
case StatusUnchanged:
|
||||||
@@ -758,6 +775,16 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
|||||||
*errorMessage = msgParseFilesFailed();
|
*errorMessage = msgParseFilesFailed();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Filter out untracked files that are not part of the project and,
|
||||||
|
// for symmetry, insert the prefix "untracked:" (as "added:" or ":modified"
|
||||||
|
// for staged files).
|
||||||
|
filterUntrackedFilesOfProject(repoDirectory, &d->untrackedFiles);
|
||||||
|
if (!d->untrackedFiles.empty()) {
|
||||||
|
const QString untrackedPrefix = QLatin1String("untracked: ");
|
||||||
|
const QStringList::iterator pend = d->untrackedFiles.end();
|
||||||
|
for (QStringList::iterator it = d->untrackedFiles.begin(); it != pend; ++it)
|
||||||
|
it->insert(0, untrackedPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
d->panelData.author = readConfigValue(workingDirectory, QLatin1String("user.name"));
|
d->panelData.author = readConfigValue(workingDirectory, QLatin1String("user.name"));
|
||||||
d->panelData.email = readConfigValue(workingDirectory, QLatin1String("user.email"));
|
d->panelData.email = readConfigValue(workingDirectory, QLatin1String("user.email"));
|
||||||
@@ -853,8 +880,8 @@ GitClient::RevertResult GitClient::revertI(QStringList files, bool *ptrToIsDirec
|
|||||||
case StatusFailed:
|
case StatusFailed:
|
||||||
return RevertFailed;
|
return RevertFailed;
|
||||||
}
|
}
|
||||||
CommitData d;
|
CommitData data;
|
||||||
if (!parseFiles(output, &d)) {
|
if (!parseFiles(output, &data)) {
|
||||||
*errorMessage = msgParseFilesFailed();
|
*errorMessage = msgParseFilesFailed();
|
||||||
return RevertFailed;
|
return RevertFailed;
|
||||||
}
|
}
|
||||||
@@ -870,8 +897,8 @@ GitClient::RevertResult GitClient::revertI(QStringList files, bool *ptrToIsDirec
|
|||||||
|
|
||||||
// From the status output, determine all modified [un]staged files.
|
// From the status output, determine all modified [un]staged files.
|
||||||
const QString modifiedPattern = QLatin1String("modified: ");
|
const QString modifiedPattern = QLatin1String("modified: ");
|
||||||
const QStringList allStagedFiles = GitSubmitEditor::statusListToFileList(d.stagedFiles.filter(modifiedPattern));
|
const QStringList allStagedFiles = GitSubmitEditor::statusListToFileList(data.stagedFiles.filter(modifiedPattern));
|
||||||
const QStringList allUnstagedFiles = GitSubmitEditor::statusListToFileList(d.unstagedFiles.filter(modifiedPattern));
|
const QStringList allUnstagedFiles = GitSubmitEditor::statusListToFileList(data.unstagedFiles.filter(modifiedPattern));
|
||||||
// Unless a directory was passed, filter all modified files for the
|
// Unless a directory was passed, filter all modified files for the
|
||||||
// argument file list.
|
// argument file list.
|
||||||
QStringList stagedFiles = allStagedFiles;
|
QStringList stagedFiles = allStagedFiles;
|
||||||
@@ -882,7 +909,7 @@ GitClient::RevertResult GitClient::revertI(QStringList files, bool *ptrToIsDirec
|
|||||||
unstagedFiles = allUnstagedFiles.toSet().intersect(filesSet).toList();
|
unstagedFiles = allUnstagedFiles.toSet().intersect(filesSet).toList();
|
||||||
}
|
}
|
||||||
if (Git::Constants::debug)
|
if (Git::Constants::debug)
|
||||||
qDebug() << Q_FUNC_INFO << d.stagedFiles << d.unstagedFiles << allStagedFiles << allUnstagedFiles << stagedFiles << unstagedFiles;
|
qDebug() << Q_FUNC_INFO << data.stagedFiles << data.unstagedFiles << allStagedFiles << allUnstagedFiles << stagedFiles << unstagedFiles;
|
||||||
|
|
||||||
if (stagedFiles.empty() && unstagedFiles.empty())
|
if (stagedFiles.empty() && unstagedFiles.empty())
|
||||||
return RevertUnchanged;
|
return RevertUnchanged;
|
||||||
|
|||||||
@@ -463,22 +463,8 @@ void PerforcePlugin::diffCurrentFile()
|
|||||||
|
|
||||||
void PerforcePlugin::diffCurrentProject()
|
void PerforcePlugin::diffCurrentProject()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_projectExplorer, return);
|
|
||||||
QStringList files;
|
|
||||||
QString name;
|
QString name;
|
||||||
ProjectExplorer::Project *currentProject = m_projectExplorer->currentProject();
|
const QStringList nativeFiles = VCSBase::VCSBaseSubmitEditor::currentProjectFiles(true, &name);
|
||||||
if (currentProject) {
|
|
||||||
files << currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
|
||||||
name = currentProject->name();
|
|
||||||
} else if (m_projectExplorer->session()) {
|
|
||||||
name = m_projectExplorer->session()->file()->fileName();
|
|
||||||
QList<ProjectExplorer::Project *> projects = m_projectExplorer->session()->projects();
|
|
||||||
foreach (ProjectExplorer::Project *project, projects)
|
|
||||||
files << project->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
|
||||||
}
|
|
||||||
QStringList nativeFiles;
|
|
||||||
foreach (const QString &f, files)
|
|
||||||
nativeFiles << QDir::toNativeSeparators(f);
|
|
||||||
p4Diff(nativeFiles, name);
|
p4Diff(nativeFiles, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,23 +524,8 @@ void PerforcePlugin::submit()
|
|||||||
m_changeTmpFile->seek(0);
|
m_changeTmpFile->seek(0);
|
||||||
|
|
||||||
// Assemble file list of project
|
// Assemble file list of project
|
||||||
QTC_ASSERT(m_projectExplorer, return);
|
|
||||||
QStringList files;
|
|
||||||
QString name;
|
QString name;
|
||||||
ProjectExplorer::Project *currentProject = m_projectExplorer->currentProject();
|
const QStringList nativeFiles = VCSBase::VCSBaseSubmitEditor::currentProjectFiles(true, &name);
|
||||||
if (currentProject) {
|
|
||||||
files << currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
|
||||||
name = currentProject->name();
|
|
||||||
} else if (m_projectExplorer->session()) {
|
|
||||||
name = m_projectExplorer->session()->file()->fileName();
|
|
||||||
QList<ProjectExplorer::Project *> projects = m_projectExplorer->session()->projects();
|
|
||||||
foreach (ProjectExplorer::Project *project, projects)
|
|
||||||
files << project->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
|
||||||
}
|
|
||||||
QStringList nativeFiles;
|
|
||||||
foreach (const QString &f, files)
|
|
||||||
nativeFiles << QDir::toNativeSeparators(f);
|
|
||||||
|
|
||||||
PerforceResponse result2 = runP4Cmd(QStringList(QLatin1String("fstat")), nativeFiles,
|
PerforceResponse result2 = runP4Cmd(QStringList(QLatin1String("fstat")), nativeFiles,
|
||||||
CommandToWindow|StdErrToWindow|ErrorToWindow);
|
CommandToWindow|StdErrToWindow|ErrorToWindow);
|
||||||
if (result2.error) {
|
if (result2.error) {
|
||||||
|
|||||||
@@ -42,11 +42,15 @@
|
|||||||
#include <utils/submiteditorwidget.h>
|
#include <utils/submiteditorwidget.h>
|
||||||
#include <find/basetextfind.h>
|
#include <find/basetextfind.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/projectexplorer.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
|
|
||||||
#include <QtGui/QToolBar>
|
#include <QtGui/QToolBar>
|
||||||
#include <QtGui/QStyle>
|
#include <QtGui/QStyle>
|
||||||
#include <QtCore/QPointer>
|
#include <QtCore/QPointer>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
@@ -299,4 +303,32 @@ QIcon VCSBaseSubmitEditor::submitIcon()
|
|||||||
return QIcon(QLatin1String(":/vcsbase/images/submit.png"));
|
return QIcon(QLatin1String(":/vcsbase/images/submit.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList VCSBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QString *name)
|
||||||
|
{
|
||||||
|
if (name)
|
||||||
|
name->clear();
|
||||||
|
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::ProjectExplorerPlugin>();
|
||||||
|
if (!projectExplorer)
|
||||||
|
return QStringList();
|
||||||
|
QStringList files;
|
||||||
|
if (const ProjectExplorer::Project *currentProject = projectExplorer->currentProject()) {
|
||||||
|
files << currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
||||||
|
if (name)
|
||||||
|
*name = currentProject->name();
|
||||||
|
} else {
|
||||||
|
if (const ProjectExplorer::SessionManager *session = projectExplorer->session()) {
|
||||||
|
if (name)
|
||||||
|
*name = session->file()->fileName();
|
||||||
|
const QList<ProjectExplorer::Project *> projects = session->projects();
|
||||||
|
foreach (ProjectExplorer::Project *project, projects)
|
||||||
|
files << project->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nativeSeparators && !files.empty()) {
|
||||||
|
const QStringList::iterator end = files.end();
|
||||||
|
for (QStringList::iterator it = files.begin(); it != end; ++it)
|
||||||
|
*it = QDir::toNativeSeparators(*it);
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
} // namespace VCSBase
|
} // namespace VCSBase
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ public:
|
|||||||
static QIcon diffIcon();
|
static QIcon diffIcon();
|
||||||
static QIcon submitIcon();
|
static QIcon submitIcon();
|
||||||
|
|
||||||
|
// Utility returning all project files in case submit lists need to
|
||||||
|
// be restricted to them
|
||||||
|
static QStringList currentProjectFiles(bool nativeSeparators, QString *name = 0);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void diffSelectedFiles(const QStringList &files);
|
void diffSelectedFiles(const QStringList &files);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user