Commit 903e9e0c authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Git: Guard against invalid index

parent 825f693f
Pipeline #218547 passed with stage
in 6 minutes and 58 seconds
......@@ -24,7 +24,7 @@ BranchCheckoutDialog::~BranchCheckoutDialog()
void BranchCheckoutDialog::resetValues()
{
m_checkoutBranchName.clear();
m_checkoutFromBranchName.clear();
m_checkingOutFromBranch = false;
m_lineEdit.setPlaceholderText(i18n("Select branch to checkout. Press 'Esc' to cancel."));
}
......@@ -63,7 +63,13 @@ void BranchCheckoutDialog::slotReturnPressed(const QModelIndex &index)
{
// we cleared the model to checkout new branch
if (m_model->rowCount() == 0) {
createNewBranch(m_lineEdit.text(), m_checkoutBranchName);
createNewBranch(m_lineEdit.text(), m_checkoutFromBranchName);
return;
}
if (!index.isValid()) {
clearLineEdit();
hide();
return;
}
......@@ -71,7 +77,7 @@ void BranchCheckoutDialog::slotReturnPressed(const QModelIndex &index)
if (m_checkingOutFromBranch) {
m_checkingOutFromBranch = false;
const auto fromBranch = index.data(BranchesDialogModel::CheckoutName).toString();
m_checkoutBranchName = fromBranch;
m_checkoutFromBranchName = fromBranch;
m_model->clear();
clearLineEdit();
m_lineEdit.setPlaceholderText(i18n("Enter new branch name. Press 'Esc' to cancel."));
......
......@@ -26,7 +26,7 @@ private:
private:
QFutureWatcher<GitUtils::CheckoutResult> m_checkoutWatcher;
QString m_checkoutBranchName;
QString m_checkoutFromBranchName;
bool m_checkingOutFromBranch = false;
};
......
......@@ -116,12 +116,14 @@ void BranchesDialog::openDialog(GitUtils::RefType r)
void BranchesDialog::slotReturnPressed(const QModelIndex &index)
{
const auto branch = index.data().toString();
const auto itemType = (BranchesDialogModel::ItemType)index.data(BranchesDialogModel::ItemTypeRole).toInt();
Q_ASSERT(itemType == BranchesDialogModel::BranchItem);
if (index.isValid()) {
const auto branch = index.data().toString();
const auto itemType = (BranchesDialogModel::ItemType)index.data(BranchesDialogModel::ItemTypeRole).toInt();
Q_ASSERT(itemType == BranchesDialogModel::BranchItem);
m_branch = branch;
Q_EMIT branchSelected(branch);
m_branch = branch;
Q_EMIT branchSelected(branch);
}
clearLineEdit();
hide();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment