Set head/stash reference after pop/drop stash

Fixes the issue  "Dropping multiple stashs in a row segfaults #637".
The cause of the crash was that the commit list was not properly
updated after pop/drop stash actions.  With this change the commit
list is updated or when the stash gets empty (after last pop/drop) 
then the head is selected as current reference.
This commit is contained in:
Silvan Forrer 2024-03-10 14:09:29 +01:00 committed by Martin Marmsoler
parent ed47229ac9
commit 778715ae9f

View File

@ -2122,6 +2122,13 @@ void RepoView::dropStash(int index) {
LogEntry *entry = addLogEntry(msg(commit), tr("Drop Stash"));
if (!mRepo.dropStash(index))
error(entry, tr("drop stash"), commit.link());
if (mRepo.stashes().size() == 0) {
// switch back to head when there are no stashes left
mCommits->setReference(mRepo.head());
} else {
mCommits->setReference(mRepo.stashRef());
}
}
void RepoView::popStash(int index) {
@ -2135,7 +2142,12 @@ void RepoView::popStash(int index) {
return;
}
refresh(false);
if (mRepo.stashes().size() == 0) {
// switch back to head when there are no stashes left
mCommits->setReference(mRepo.head());
} else {
mCommits->setReference(mRepo.stashRef());
}
}
void RepoView::promptToAddTag(const git::Commit &commit) {