Files
qt-creator/src/plugins/git/gerrit/branchcombobox.cpp
Lucie Gérard a7956df3ca Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.

Task-number: QTBUG-67283
Change-Id: I708fd1f9f2b73d60f57cc3568646929117825813
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-08-26 12:27:18 +00:00

40 lines
1.2 KiB
C++

// Copyright (C) 2016 Orgad Shaneh <orgads@gmail.com>.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "branchcombobox.h"
#include "../gitclient.h"
using namespace Git::Internal;
using namespace Gerrit::Internal;
using namespace Utils;
BranchComboBox::BranchComboBox(QWidget *parent) : QComboBox(parent)
{ }
void BranchComboBox::init(const FilePath &repository)
{
m_repository = repository;
QString currentBranch = GitClient::instance()->synchronousCurrentLocalBranch(repository);
if (currentBranch.isEmpty()) {
m_detached = true;
currentBranch = "HEAD";
addItem(currentBranch);
}
QString output;
const QString branchPrefix("refs/heads/");
if (!GitClient::instance()->synchronousForEachRefCmd(
m_repository, {"--format=%(refname)", branchPrefix}, &output)) {
return;
}
const QStringList branches = output.trimmed().split('\n');
for (const QString &ref : branches) {
const QString branch = ref.mid(branchPrefix.size());
addItem(branch);
}
if (currentBranch.isEmpty())
return;
int index = findText(currentBranch);
if (index != -1)
setCurrentIndex(index);
}