Git: Push to non-default remotes

Allow pushing into any of the defined remotes via Tools->Git->Remotes...

Task-number: QTCREATORBUG-6382
Change-Id: I0bab34da4ec27c377993782b905b1d6c4f5a14b9
Reviewed-by: Hugues Delorme <delorme.hugues@fougsys.fr>
This commit is contained in:
Tobias Hunger
2011-12-07 14:02:36 +01:00
committed by Hugues Delorme
parent f517215a3d
commit 02d74bd3e7
5 changed files with 44 additions and 3 deletions

View File

@@ -1967,13 +1967,16 @@ void GitClient::subversionLog(const QString &workingDirectory)
executeGit(workingDirectory, arguments, editor); executeGit(workingDirectory, arguments, editor);
} }
bool GitClient::synchronousPush(const QString &workingDirectory) bool GitClient::synchronousPush(const QString &workingDirectory, const QString &remote)
{ {
// Disable UNIX terminals to suppress SSH prompting. // Disable UNIX terminals to suppress SSH prompting.
const unsigned flags = VCSBase::VCSBasePlugin::SshPasswordPrompt|VCSBase::VCSBasePlugin::ShowStdOutInLogWindow const unsigned flags = VCSBase::VCSBasePlugin::SshPasswordPrompt|VCSBase::VCSBasePlugin::ShowStdOutInLogWindow
|VCSBase::VCSBasePlugin::ShowSuccessMessage; |VCSBase::VCSBasePlugin::ShowSuccessMessage;
QStringList arguments(QLatin1String("push"));
if (!remote.isEmpty())
arguments << remote;
const Utils::SynchronousProcessResponse resp = const Utils::SynchronousProcessResponse resp =
synchronousGit(workingDirectory, QStringList(QLatin1String("push")), flags); synchronousGit(workingDirectory, arguments, flags);
return resp.result == Utils::SynchronousProcessResponse::Finished; return resp.result == Utils::SynchronousProcessResponse::Finished;
} }

View File

@@ -170,7 +170,7 @@ public:
QString vcsGetRepositoryURL(const QString &directory); QString vcsGetRepositoryURL(const QString &directory);
bool synchronousFetch(const QString &workingDirectory, const QString &remote); bool synchronousFetch(const QString &workingDirectory, const QString &remote);
bool synchronousPull(const QString &workingDirectory); bool synchronousPull(const QString &workingDirectory);
bool synchronousPush(const QString &workingDirectory); bool synchronousPush(const QString &workingDirectory, const QString &remote = QString());
// git svn support (asynchronous). // git svn support (asynchronous).
void synchronousSubversionFetch(const QString &workingDirectory); void synchronousSubversionFetch(const QString &workingDirectory);

View File

@@ -106,8 +106,14 @@ RemoteDialog::RemoteDialog(QWidget *parent) :
connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(addRemote())); connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(addRemote()));
connect(m_ui->fetchButton, SIGNAL(clicked()), this, SLOT(fetchFromRemote())); connect(m_ui->fetchButton, SIGNAL(clicked()), this, SLOT(fetchFromRemote()));
connect(m_ui->pushButton, SIGNAL(clicked()), this, SLOT(pushToRemote()));
connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(removeRemote())); connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(removeRemote()));
connect(m_ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshRemotes())); connect(m_ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshRemotes()));
connect(m_ui->remoteView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(updateButtonState()));
updateButtonState();
} }
RemoteDialog::~RemoteDialog() RemoteDialog::~RemoteDialog()
@@ -163,6 +169,17 @@ void RemoteDialog::removeRemote()
} }
} }
void RemoteDialog::pushToRemote()
{
const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes();
if (indexList.count() == 0)
return;
const int row = indexList.at(0).row();
const QString remoteName = m_remoteModel->remoteName(row);
m_remoteModel->client()->synchronousPush(m_remoteModel->workingDirectory(), remoteName);
}
void RemoteDialog::fetchFromRemote() void RemoteDialog::fetchFromRemote()
{ {
const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes(); const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes();
@@ -174,6 +191,17 @@ void RemoteDialog::fetchFromRemote()
m_remoteModel->client()->synchronousFetch(m_remoteModel->workingDirectory(), remoteName); m_remoteModel->client()->synchronousFetch(m_remoteModel->workingDirectory(), remoteName);
} }
void RemoteDialog::updateButtonState()
{
const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes();
const bool haveSelection = (indexList.count() > 0);
m_ui->addButton->setEnabled(true);
m_ui->fetchButton->setEnabled(haveSelection);
m_ui->pushButton->setEnabled(haveSelection);
m_ui->removeButton->setEnabled(haveSelection);
}
void RemoteDialog::changeEvent(QEvent *e) void RemoteDialog::changeEvent(QEvent *e)
{ {
QDialog::changeEvent(e); QDialog::changeEvent(e);

View File

@@ -84,8 +84,11 @@ public slots:
void refreshRemotes(); void refreshRemotes();
void addRemote(); void addRemote();
void removeRemote(); void removeRemote();
void pushToRemote();
void fetchFromRemote(); void fetchFromRemote();
void updateButtonState();
private slots: private slots:
protected: protected:

View File

@@ -111,6 +111,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>&amp;Push</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="removeButton"> <widget class="QPushButton" name="removeButton">
<property name="text"> <property name="text">