summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/git/gerrit/gerritplugin.cpp10
-rw-r--r--src/plugins/git/gitclient.cpp38
-rw-r--r--src/plugins/git/gitclient.h5
-rw-r--r--src/plugins/git/gitplugin.cpp11
4 files changed, 29 insertions, 35 deletions
diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp
index a86da546c9..556af275ec 100644
--- a/src/plugins/git/gerrit/gerritplugin.cpp
+++ b/src/plugins/git/gerrit/gerritplugin.cpp
@@ -432,15 +432,7 @@ QString GerritPlugin::gitBinary()
QString GerritPlugin::branch(const QString &repository)
{
Git::Internal::GitClient *client = Git::Internal::GitPlugin::instance()->gitClient();
- QString errorMessage;
- QString output;
- if (client->synchronousBranchCmd(repository, QStringList(), &output, &errorMessage)) {
- output.remove(QLatin1Char('\r'));
- foreach (const QString &line, output.split(QLatin1Char('\n')))
- if (line.startsWith(QLatin1String("* ")))
- return line.right(line.size() - 2);
- }
- return QString();
+ return client->synchronousCurrentLocalBranch(repository);
}
void GerritPlugin::fetchDisplay(const QSharedPointer<Gerrit::Internal::GerritChange> &change)
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 1d2020e393..2db128d416 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -1190,6 +1190,22 @@ QString GitClient::synchronousShortDescription(const QString &workingDirectory,
return output;
}
+QString GitClient::synchronousCurrentLocalBranch(const QString &workingDirectory)
+{
+ QByteArray outputTextData;
+ QStringList arguments;
+ arguments << QLatin1String("symbolic-ref") << QLatin1String("HEAD");
+ if (fullySynchronousGit(workingDirectory, arguments, &outputTextData, 0, false)) {
+ QString branch = commandOutputFromLocal8Bit(outputTextData.trimmed());
+ const QString refsHeadsPrefix = QLatin1String("refs/heads/");
+ if (branch.startsWith(refsHeadsPrefix)) {
+ branch.remove(0, refsHeadsPrefix.count());
+ return branch;
+ }
+ }
+ return QString();
+}
+
static inline QString msgCannotDetermineBranch(const QString &workingDirectory, const QString &why)
{
return GitClient::tr("Cannot retrieve branch of \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), why);
@@ -1250,22 +1266,10 @@ QString GitClient::synchronousTopic(const QString &workingDirectory)
if (lastModified == data.timeStamp)
return data.topic;
data.timeStamp = lastModified;
- QByteArray outputTextData;
- QStringList arguments;
- arguments << QLatin1String("symbolic-ref") << QLatin1String("HEAD");
// First try to find branch
- if (fullySynchronousGit(workingDirectory, arguments, &outputTextData, 0, false)) {
- QString branch = commandOutputFromLocal8Bit(outputTextData.trimmed());
-
- // Must strip the "refs/heads/" prefix manually since the --short switch
- // of git symbolic-ref only got introduced with git 1.7.10, which is not
- // available for all popular Linux distributions yet.
- const QString refsHeadsPrefix = QLatin1String("refs/heads/");
- if (branch.startsWith(refsHeadsPrefix))
- branch.remove(0, refsHeadsPrefix.count());
-
+ QString branch = synchronousCurrentLocalBranch(workingDirectory);
+ if (!branch.isEmpty())
return data.topic = branch;
- }
// Detached HEAD, try a tag or remote branch
QStringList references;
@@ -1939,10 +1943,8 @@ void GitClient::continuePreviousGitCommand(const QString &workingDirectory,
// Quietly retrieve branch list of remote repository URL
//
// The branch HEAD is pointing to is always returned first.
-QStringList GitClient::synchronousRepositoryBranches(const QString &repositoryURL, bool *isDetached)
+QStringList GitClient::synchronousRepositoryBranches(const QString &repositoryURL)
{
- if (isDetached)
- *isDetached = true;
QStringList arguments(QLatin1String("ls-remote"));
arguments << repositoryURL << QLatin1String("HEAD") << QLatin1String("refs/heads/*");
const unsigned flags =
@@ -1969,8 +1971,6 @@ QStringList GitClient::synchronousRepositoryBranches(const QString &repositoryUR
if (!headFound && line.startsWith(headSha)) {
branches[0] = branchName;
headFound = true;
- if (isDetached)
- *isDetached = false;
} else {
branches.push_back(branchName);
}
diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h
index 04292fca76..cd0df0a60c 100644
--- a/src/plugins/git/gitclient.h
+++ b/src/plugins/git/gitclient.h
@@ -201,6 +201,9 @@ public:
QString synchronousShortDescription(const QString &workingDirectory, const QString &revision);
QString synchronousShortDescription(const QString &workingDirectory, const QString &revision,
const QString &format);
+
+ QString synchronousCurrentLocalBranch(const QString &workingDirectory);
+
bool synchronousHeadRefs(const QString &workingDirectory, QStringList *output,
QString *errorMessage = 0);
QString synchronousTopic(const QString &workingDirectory);
@@ -273,7 +276,7 @@ public:
void launchRepositoryBrowser(const QString &workingDirectory);
- QStringList synchronousRepositoryBranches(const QString &repositoryURL, bool *isDetached = 0);
+ QStringList synchronousRepositoryBranches(const QString &repositoryURL);
GitSettings *settings() const;
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp
index 22498c69d0..5796743901 100644
--- a/src/plugins/git/gitplugin.cpp
+++ b/src/plugins/git/gitplugin.cpp
@@ -1001,12 +1001,11 @@ void GitPlugin::pull()
bool rebase = m_gitClient->settings()->boolValue(GitSettings::pullRebaseKey);
if (!rebase) {
- bool isDetached;
- QString branchRebaseConfig = m_gitClient->synchronousRepositoryBranches(topLevel, &isDetached).at(0);
- if (!isDetached) {
- branchRebaseConfig.prepend(QLatin1String("branch."));
- branchRebaseConfig.append(QLatin1String(".rebase"));
- rebase = (m_gitClient->readConfigValue(topLevel, branchRebaseConfig) == QLatin1String("true"));
+ QString currentBranch = m_gitClient->synchronousCurrentLocalBranch(topLevel);
+ if (!currentBranch.isEmpty()) {
+ currentBranch.prepend(QLatin1String("branch."));
+ currentBranch.append(QLatin1String(".rebase"));
+ rebase = (m_gitClient->readConfigValue(topLevel, currentBranch) == QLatin1String("true"));
}
}