forked from qt-creator/qt-creator
Git: Custom gitk launch
Launch gitk only for current file, or for the folder that current file belongs to Task-number: QTCREATORBUG-8327 Change-Id: I2ffbd44e3b3eeaffad32e84af9ca2085b16fdaa2 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Tobias Hunger
parent
221cfbfac0
commit
4ffc1a2f10
@@ -1689,18 +1689,18 @@ QStringList GitClient::synchronousRepositoryBranches(const QString &repositoryUR
|
||||
return branches;
|
||||
}
|
||||
|
||||
void GitClient::launchGitK(const QString &workingDirectory)
|
||||
void GitClient::launchGitK(const QString &workingDirectory, const QString &fileName)
|
||||
{
|
||||
const QFileInfo binaryInfo(gitBinaryPath());
|
||||
QDir foundBinDir(binaryInfo.dir());
|
||||
const bool foundBinDirIsCmdDir = foundBinDir.dirName() == QLatin1String("cmd");
|
||||
QProcessEnvironment env = processEnvironment();
|
||||
if (tryLauchingGitK(env, workingDirectory, foundBinDir.path(), foundBinDirIsCmdDir))
|
||||
if (tryLauchingGitK(env, workingDirectory, fileName, foundBinDir.path(), foundBinDirIsCmdDir))
|
||||
return;
|
||||
if (!foundBinDirIsCmdDir)
|
||||
return;
|
||||
foundBinDir.cdUp();
|
||||
tryLauchingGitK(env, workingDirectory, foundBinDir.path() + QLatin1String("/bin"), false);
|
||||
tryLauchingGitK(env, workingDirectory, fileName, foundBinDir.path() + QLatin1String("/bin"), false);
|
||||
}
|
||||
|
||||
void GitClient::launchRepositoryBrowser(const QString &workingDirectory)
|
||||
@@ -1712,6 +1712,7 @@ void GitClient::launchRepositoryBrowser(const QString &workingDirectory)
|
||||
|
||||
bool GitClient::tryLauchingGitK(const QProcessEnvironment &env,
|
||||
const QString &workingDirectory,
|
||||
const QString &fileName,
|
||||
const QString &gitBinDirectory,
|
||||
bool silent)
|
||||
{
|
||||
@@ -1729,6 +1730,8 @@ bool GitClient::tryLauchingGitK(const QProcessEnvironment &env,
|
||||
const QString gitkOpts = settings()->stringValue(GitSettings::gitkOptionsKey);
|
||||
if (!gitkOpts.isEmpty())
|
||||
arguments.append(Utils::QtcProcess::splitArgs(gitkOpts));
|
||||
if (!fileName.isEmpty())
|
||||
arguments << QLatin1String("--") << fileName;
|
||||
outwin->appendCommand(workingDirectory, binary, arguments);
|
||||
// This should always use QProcess::startDetached (as not to kill
|
||||
// the child), but that does not have an environment parameter.
|
||||
|
||||
@@ -214,7 +214,9 @@ public:
|
||||
QString *output = 0,
|
||||
QString *errorMessage = 0);
|
||||
|
||||
void launchGitK(const QString &workingDirectory);
|
||||
void launchGitK(const QString &workingDirectory, const QString &fileName);
|
||||
void launchGitK(const QString &workingDirectory) { launchGitK(workingDirectory, QString()); }
|
||||
|
||||
void launchRepositoryBrowser(const QString &workingDirectory);
|
||||
|
||||
QStringList synchronousRepositoryBranches(const QString &repositoryURL);
|
||||
@@ -291,6 +293,7 @@ private:
|
||||
void handleMergeConflicts(const QString &workingDir, bool rebase);
|
||||
bool tryLauchingGitK(const QProcessEnvironment &env,
|
||||
const QString &workingDirectory,
|
||||
const QString &fileName,
|
||||
const QString &gitBinDirectory,
|
||||
bool silent);
|
||||
bool cleanList(const QString &workingDirectory, const QString &flag, QStringList *files, QString *errorMessage);
|
||||
|
||||
@@ -545,6 +545,19 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
tr("Gitk"), Core::Id("Git.LaunchGitK"),
|
||||
globalcontext, true, &GitClient::launchGitK);
|
||||
|
||||
parameterActionCommand
|
||||
= createFileAction(gitToolsMenu,
|
||||
tr("Gitk Current File"), tr("Gitk of \"%1\""),
|
||||
Core::Id("Git.GitkFile"), globalcontext, true, SLOT(gitkForCurrentFile()));
|
||||
|
||||
parameterActionCommand
|
||||
= createFileAction(gitToolsMenu,
|
||||
tr("Gitk for folder of Current File"), tr("Gitk for folder of \"%1\""),
|
||||
Core::Id("Git.GitkFolder"), globalcontext, true, SLOT(gitkForCurrentFolder()));
|
||||
|
||||
// --------------
|
||||
gitToolsMenu->addSeparator(globalcontext);
|
||||
|
||||
m_repositoryBrowserAction
|
||||
= createRepositoryAction(gitToolsMenu,
|
||||
tr("Repository Browser"), Core::Id("Git.LaunchRepositoryBrowser"),
|
||||
@@ -698,6 +711,43 @@ void GitPlugin::unstageFile()
|
||||
m_gitClient->synchronousReset(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
|
||||
}
|
||||
|
||||
void GitPlugin::gitkForCurrentFile()
|
||||
{
|
||||
const VcsBase::VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasFile(), return);
|
||||
m_gitClient->launchGitK(state.currentFileTopLevel(), state.relativeCurrentFile());
|
||||
}
|
||||
|
||||
void GitPlugin::gitkForCurrentFolder()
|
||||
{
|
||||
const VcsBase::VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasFile(), return);
|
||||
|
||||
/*
|
||||
* entire lower part of the code can be easily replaced with one line:
|
||||
*
|
||||
* m_gitClient->launchGitK(dir.currentFileDirectory(), QLatin1String("."));
|
||||
*
|
||||
* However, there is a bug in gitk in version 1.7.9.5, and if you run above
|
||||
* command, there will be no documents listed in lower right section.
|
||||
*
|
||||
* This is why I use lower combination in order to avoid this problems in gitk.
|
||||
*
|
||||
* Git version 1.7.10.4 does not have this issue, and it can easily use
|
||||
* one line command mentioned above.
|
||||
*
|
||||
*/
|
||||
QDir dir(state.currentFileDirectory());
|
||||
if (QFileInfo(dir,QLatin1String(".git")).exists() || dir.cd(QLatin1String(".git")))
|
||||
m_gitClient->launchGitK(state.currentFileDirectory());
|
||||
else {
|
||||
QString folderName = dir.absolutePath();
|
||||
dir.cdUp();
|
||||
folderName = folderName.remove(0, dir.absolutePath().length() + 1);
|
||||
m_gitClient->launchGitK(dir.absolutePath(), folderName);
|
||||
}
|
||||
}
|
||||
|
||||
void GitPlugin::startAmendCommit()
|
||||
{
|
||||
startCommit(true);
|
||||
|
||||
@@ -115,6 +115,8 @@ private slots:
|
||||
void resetRepository();
|
||||
void stageFile();
|
||||
void unstageFile();
|
||||
void gitkForCurrentFile();
|
||||
void gitkForCurrentFolder();
|
||||
void cleanProject();
|
||||
void cleanRepository();
|
||||
void applyCurrentFilePatch();
|
||||
|
||||
Reference in New Issue
Block a user