forked from qt-creator/qt-creator
Git: Added Revert and cherry-pick
Change-Id: Ic8ba7434e79b12eca680a67c2845c82915dc0088 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
8f4da818c8
commit
65aef73ec4
@@ -425,11 +425,21 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
createRepositoryAction(localRepositoryMenu,
|
||||
tr("Amend Last Commit..."), Core::Id("Git.AmendCommit"),
|
||||
globalcontext, true, SLOT(startAmendCommit()));
|
||||
// --------------
|
||||
localRepositoryMenu->addSeparator(globalcontext);
|
||||
|
||||
createRepositoryAction(localRepositoryMenu,
|
||||
tr("Reset..."), Core::Id("Git.Reset"),
|
||||
globalcontext, false, SLOT(resetRepository()));
|
||||
|
||||
createRepositoryAction(localRepositoryMenu,
|
||||
tr("Revert Single Commit..."), Core::Id("Git.Revert"),
|
||||
globalcontext, true, SLOT(startRevertCommit()));
|
||||
|
||||
createRepositoryAction(localRepositoryMenu,
|
||||
tr("Cherry-Pick Commit..."), Core::Id("Git.CherryPick"),
|
||||
globalcontext, true, SLOT(startCherryPickCommit()));
|
||||
|
||||
// --------------
|
||||
localRepositoryMenu->addSeparator(globalcontext);
|
||||
|
||||
@@ -704,6 +714,56 @@ void GitPlugin::resetRepository()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GitPlugin::startRevertCommit()
|
||||
{
|
||||
startRevertOrCherryPick(true);
|
||||
}
|
||||
|
||||
void GitPlugin::startCherryPickCommit()
|
||||
{
|
||||
startRevertOrCherryPick(false);
|
||||
}
|
||||
|
||||
void GitPlugin::startRevertOrCherryPick(bool isRevert)
|
||||
{
|
||||
const VcsBase::VcsBasePluginState state = currentState();
|
||||
|
||||
QString stashKeyword = (isRevert ? QLatin1String("Revert") : QLatin1String("Cherry-pick"));
|
||||
|
||||
GitClient::StashResult stashResult =
|
||||
m_gitClient->ensureStash(state.topLevel(), stashKeyword);
|
||||
switch (stashResult) {
|
||||
case GitClient::StashUnchanged:
|
||||
case GitClient::Stashed:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
QString workingDirectory;
|
||||
if (state.hasFile())
|
||||
workingDirectory = state.currentFileDirectory();
|
||||
else if (state.hasTopLevel())
|
||||
workingDirectory = state.topLevel();
|
||||
else
|
||||
return;
|
||||
|
||||
ChangeSelectionDialog changeSelectionDialog(workingDirectory);
|
||||
|
||||
if (changeSelectionDialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
const QString change = changeSelectionDialog.change();
|
||||
if (change.isEmpty())
|
||||
return;
|
||||
|
||||
bool success = (isRevert ? m_gitClient->revertCommit(workingDirectory, change) :
|
||||
m_gitClient->cherryPickCommit(workingDirectory, change));
|
||||
|
||||
if (success && (stashResult == GitClient::Stashed))
|
||||
m_gitClient->stashPop(workingDirectory);
|
||||
}
|
||||
|
||||
void GitPlugin::stageFile()
|
||||
{
|
||||
const VcsBase::VcsBasePluginState state = currentState();
|
||||
|
Reference in New Issue
Block a user