forked from qt-creator/qt-creator
Git: Prefer remote tracking branch in GerritPushDialog
In case it contains the latest remote commit Change-Id: Id9e4cc40b7d1aa9daac3a9a2cf9ba41f589da7eb Reviewed-by: Petar Perisin <petar.perisin@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
1f38110dad
commit
e836cd082c
@@ -77,13 +77,23 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
|
||||
|
||||
QString head = QLatin1String("/HEAD");
|
||||
QStringList refs = output.split(QLatin1Char('\n'));
|
||||
QString remoteTrackingBranch = gitClient->synchronousTrackingBranch(m_workingDir);
|
||||
QString remoteBranch;
|
||||
foreach (const QString &reference, refs) {
|
||||
if (reference.contains(head) || reference.isEmpty())
|
||||
const QString ref = reference.trimmed();
|
||||
if (ref.contains(head) || ref.isEmpty())
|
||||
continue;
|
||||
|
||||
m_suggestedRemoteName = reference.left(reference.indexOf(QLatin1Char('/'))).trimmed();
|
||||
m_suggestedRemoteBranch = reference.mid(reference.indexOf(QLatin1Char('/')) + 1).trimmed();
|
||||
break;
|
||||
remoteBranch = ref;
|
||||
|
||||
// Prefer remote tracking branch if it exists and contains the latest remote commit
|
||||
if (ref == remoteTrackingBranch)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!remoteBranch.isEmpty()) {
|
||||
m_suggestedRemoteName = remoteBranch.left(remoteBranch.indexOf(QLatin1Char('/')));
|
||||
m_suggestedRemoteBranch = remoteBranch.mid(remoteBranch.indexOf(QLatin1Char('/')) + 1);
|
||||
}
|
||||
|
||||
output.clear();
|
||||
|
@@ -2425,6 +2425,23 @@ void GitClient::synchronousAbortCommand(const QString &workingDir, const QString
|
||||
outwin->appendError(commandOutputFromLocal8Bit(stdErr));
|
||||
}
|
||||
|
||||
QString GitClient::synchronousTrackingBranch(const QString &workingDirectory, const QString &branch)
|
||||
{
|
||||
QString remote;
|
||||
QString localBranch = branch.isEmpty() ? synchronousCurrentLocalBranch(workingDirectory) : branch;
|
||||
if (localBranch.isEmpty())
|
||||
return QString();
|
||||
localBranch.prepend(QLatin1String("branch."));
|
||||
remote = readConfigValue(workingDirectory, localBranch + QLatin1String(".remote"));
|
||||
if (remote.isEmpty())
|
||||
return QString();
|
||||
const QString rBranch = readConfigValue(workingDirectory, localBranch + QLatin1String(".merge"))
|
||||
.replace(QLatin1String("refs/heads/"), QString());
|
||||
if (rBranch.isEmpty())
|
||||
return QString();
|
||||
return remote + QLatin1Char('/') + rBranch;
|
||||
}
|
||||
|
||||
void GitClient::handleMergeConflicts(const QString &workingDir, const QString &commit, const QString &abortCommand)
|
||||
{
|
||||
QString message = commit.isEmpty() ? tr("Conflicts detected")
|
||||
|
@@ -240,6 +240,8 @@ public:
|
||||
void interactiveRebase(const QString &workingDirectory, const QString &commit,
|
||||
StashGuard &stashGuard, bool fixup);
|
||||
void synchronousAbortCommand(const QString &workingDir, const QString &abortCommand);
|
||||
QString synchronousTrackingBranch(const QString &workingDirectory,
|
||||
const QString &branch = QString());
|
||||
|
||||
// git svn support (asynchronous).
|
||||
void synchronousSubversionFetch(const QString &workingDirectory);
|
||||
|
Reference in New Issue
Block a user