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:
Orgad Shaneh
2013-05-06 22:40:41 +03:00
committed by Orgad Shaneh
parent 1f38110dad
commit e836cd082c
3 changed files with 33 additions and 4 deletions

View File

@@ -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();

View File

@@ -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")

View File

@@ -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);