forked from qt-creator/qt-creator
Git: Set remote-tracking branch
Task-number: QTCREATORBUG-8863 Change-Id: I06df735d85e2f9ed17c71385fed5057f8fc67d55 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
51a9d5065a
commit
062b8f5d31
@@ -69,6 +69,7 @@ BranchDialog::BranchDialog(QWidget *parent) :
|
||||
connect(m_ui->logButton, SIGNAL(clicked()), this, SLOT(log()));
|
||||
connect(m_ui->mergeButton, SIGNAL(clicked()), this, SLOT(merge()));
|
||||
connect(m_ui->rebaseButton, SIGNAL(clicked()), this, SLOT(rebase()));
|
||||
connect(m_ui->trackButton, SIGNAL(clicked()), this, SLOT(setRemoteTracking()));
|
||||
|
||||
m_ui->branchView->setModel(m_model);
|
||||
|
||||
@@ -106,12 +107,14 @@ void BranchDialog::refreshIfSame(const QString &repository)
|
||||
void BranchDialog::enableButtons()
|
||||
{
|
||||
QModelIndex idx = selectedIndex();
|
||||
QModelIndex currentBranch = m_model->currentBranch();
|
||||
const bool hasSelection = idx.isValid();
|
||||
const bool currentSelected = hasSelection && idx == m_model->currentBranch();
|
||||
const bool currentSelected = hasSelection && idx == currentBranch;
|
||||
const bool isLocal = m_model->isLocal(idx);
|
||||
const bool isLeaf = m_model->isLeaf(idx);
|
||||
const bool isTag = m_model->isTag(idx);
|
||||
const bool hasActions = hasSelection && isLeaf;
|
||||
const bool currentLocal = m_model->isLocal(currentBranch);
|
||||
|
||||
m_ui->removeButton->setEnabled(hasActions && !currentSelected && (isLocal || isTag));
|
||||
m_ui->renameButton->setEnabled(hasActions && (isLocal || isTag));
|
||||
@@ -120,6 +123,7 @@ void BranchDialog::enableButtons()
|
||||
m_ui->checkoutButton->setEnabled(hasActions && !currentSelected);
|
||||
m_ui->rebaseButton->setEnabled(hasActions && !currentSelected);
|
||||
m_ui->mergeButton->setEnabled(hasActions && !currentSelected);
|
||||
m_ui->trackButton->setEnabled(hasActions && currentLocal && !currentSelected && !isTag);
|
||||
}
|
||||
|
||||
void BranchDialog::refresh()
|
||||
@@ -331,6 +335,11 @@ void BranchDialog::rebase()
|
||||
client->rebase(m_repository, baseBranch);
|
||||
}
|
||||
|
||||
void BranchDialog::setRemoteTracking()
|
||||
{
|
||||
m_model->setRemoteTracking(selectedIndex());
|
||||
}
|
||||
|
||||
QModelIndex BranchDialog::selectedIndex()
|
||||
{
|
||||
QModelIndexList selected = m_ui->branchView->selectionModel()->selectedIndexes();
|
||||
|
||||
@@ -74,6 +74,7 @@ private slots:
|
||||
void log();
|
||||
void merge();
|
||||
void rebase();
|
||||
void setRemoteTracking();
|
||||
|
||||
private:
|
||||
QModelIndex selectedIndex();
|
||||
|
||||
@@ -153,6 +153,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="trackButton">
|
||||
<property name="toolTip">
|
||||
<string>Sets current branch to track the selected one</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Track</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
@@ -623,6 +623,18 @@ QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModel
|
||||
return nodeToIndex(newNode);
|
||||
}
|
||||
|
||||
void BranchModel::setRemoteTracking(const QModelIndex &trackingIndex)
|
||||
{
|
||||
QModelIndex current = currentBranch();
|
||||
QTC_ASSERT(current.isValid(), return);
|
||||
const QString currentName = fullName(current);
|
||||
const QString shortTracking = fullName(trackingIndex);
|
||||
const QString tracking = fullName(trackingIndex, true);
|
||||
m_client->synchronousSetTrackingBranch(m_workingDirectory, currentName, tracking);
|
||||
m_currentBranch->tracking = shortTracking;
|
||||
emit dataChanged(current, current);
|
||||
}
|
||||
|
||||
void BranchModel::parseOutputLine(const QString &line)
|
||||
{
|
||||
if (line.size() < 3)
|
||||
|
||||
@@ -82,6 +82,7 @@ public:
|
||||
void checkoutBranch(const QModelIndex &idx);
|
||||
bool branchIsMerged(const QModelIndex &idx);
|
||||
QModelIndex addBranch(const QString &name, bool track, const QModelIndex &trackedBranch);
|
||||
void setRemoteTracking(const QModelIndex &trackingIndex);
|
||||
|
||||
private:
|
||||
void parseOutputLine(const QString &line);
|
||||
|
||||
@@ -3059,6 +3059,26 @@ QString GitClient::synchronousTrackingBranch(const QString &workingDirectory, co
|
||||
return remote + QLatin1Char('/') + rBranch;
|
||||
}
|
||||
|
||||
bool GitClient::synchronousSetTrackingBranch(const QString &workingDirectory,
|
||||
const QString &branch, const QString &tracking)
|
||||
{
|
||||
QByteArray outputText;
|
||||
QByteArray errorText;
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String("branch");
|
||||
if (gitVersion() >= 0x010800)
|
||||
arguments << (QLatin1String("--set-upstream-to=") + tracking) << branch;
|
||||
else
|
||||
arguments << QLatin1String("--set-upstream") << branch << tracking;
|
||||
const bool rc = fullySynchronousGit(workingDirectory, arguments, &outputText, &errorText);
|
||||
if (!rc) {
|
||||
const QString errorMessage = tr("Cannot set tracking branch: %1")
|
||||
.arg(commandOutputFromLocal8Bit(errorText));
|
||||
outputWindow()->appendError(errorMessage);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
void GitClient::handleMergeConflicts(const QString &workingDir, const QString &commit,
|
||||
const QStringList &files, const QString &abortCommand)
|
||||
{
|
||||
|
||||
@@ -251,6 +251,9 @@ public:
|
||||
void synchronousAbortCommand(const QString &workingDir, const QString &abortCommand);
|
||||
QString synchronousTrackingBranch(const QString &workingDirectory,
|
||||
const QString &branch = QString());
|
||||
bool synchronousSetTrackingBranch(const QString &workingDirectory,
|
||||
const QString &branch,
|
||||
const QString &tracking);
|
||||
|
||||
// git svn support (asynchronous).
|
||||
void synchronousSubversionFetch(const QString &workingDirectory);
|
||||
|
||||
Reference in New Issue
Block a user