From 778715ae9f0b8d6c214a88ec2736055bfcc94971 Mon Sep 17 00:00:00 2001 From: Silvan Forrer Date: Sun, 10 Mar 2024 14:09:29 +0100 Subject: [PATCH 1/5] 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. --- src/ui/RepoView.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ui/RepoView.cpp b/src/ui/RepoView.cpp index 713b82cc..f2294372 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -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) { From 0515491197ab4e81821f9166517afb0d78e0b494 Mon Sep 17 00:00:00 2001 From: Silvan Forrer Date: Wed, 13 Mar 2024 21:12:09 +0100 Subject: [PATCH 2/5] Set head reference after pop stash or refresh When executing "Stash->Pop Stash" from the menu bar or when popping a specific stash from the commit list then the repo view is set to the head revision and the commit list is updated with the content from the head revision. Before the when doing a "Refresh" and being on the stash view the commit list stayed on the stashes but the head revision was selected. Now the commit list contains the commits from the head revision. --- src/ui/RepoView.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/ui/RepoView.cpp b/src/ui/RepoView.cpp index f2294372..d00d27f6 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -2141,13 +2141,7 @@ void RepoView::popStash(int index) { error(entry, tr("pop stash"), commit.link()); return; } - - if (mRepo.stashes().size() == 0) { - // switch back to head when there are no stashes left - mCommits->setReference(mRepo.head()); - } else { - mCommits->setReference(mRepo.stashRef()); - } + refresh(false); } void RepoView::promptToAddTag(const git::Commit &commit) { @@ -2809,6 +2803,7 @@ void RepoView::refresh(bool restoreSelection) { dtw->setDiffCounter(); } if (mRepo.head().isValid()) { + mCommits->setReference(mRepo.head()); DebugRefresh("Head name: " << mRepo.head().name()); } else { DebugRefresh("Head invalid"); From 659776f938add8ff4dcf4800261e2325f848259f Mon Sep 17 00:00:00 2001 From: Silvan Forrer Date: Sat, 23 Mar 2024 21:12:12 +0100 Subject: [PATCH 3/5] Revert the refresh behavior --- src/ui/RepoView.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/RepoView.cpp b/src/ui/RepoView.cpp index d00d27f6..867cbfb6 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -2141,7 +2141,10 @@ void RepoView::popStash(int index) { error(entry, tr("pop stash"), commit.link()); return; } - refresh(false); + if (mRepo.stashes().size() == 0) { + // switch back to head when there are no stashes left + mCommits->setReference(mRepo.head()); + } } void RepoView::promptToAddTag(const git::Commit &commit) { @@ -2803,7 +2806,6 @@ void RepoView::refresh(bool restoreSelection) { dtw->setDiffCounter(); } if (mRepo.head().isValid()) { - mCommits->setReference(mRepo.head()); DebugRefresh("Head name: " << mRepo.head().name()); } else { DebugRefresh("Head invalid"); From 1cb74d17e103002e1cbce4f4308bc04ae2e483c6 Mon Sep 17 00:00:00 2001 From: Silvan Forrer Date: Sat, 23 Mar 2024 21:49:40 +0100 Subject: [PATCH 4/5] Select "Uncommitted changes" after "Pop Stash" --- src/ui/RepoView.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ui/RepoView.cpp b/src/ui/RepoView.cpp index 867cbfb6..815eecc8 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -2141,10 +2141,8 @@ void RepoView::popStash(int index) { error(entry, tr("pop stash"), commit.link()); return; } - if (mRepo.stashes().size() == 0) { - // switch back to head when there are no stashes left - mCommits->setReference(mRepo.head()); - } + // switch back to head + selectReference(mRepo.head()); } void RepoView::promptToAddTag(const git::Commit &commit) { From 744dc13551dadc8df72a34c00457e746efea7b62 Mon Sep 17 00:00:00 2001 From: siforrer <80523026+siforrer@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:20:00 +0100 Subject: [PATCH 5/5] Update src/ui/RepoView.cpp Co-authored-by: Ryan Jensen --- src/ui/RepoView.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/RepoView.cpp b/src/ui/RepoView.cpp index 815eecc8..ff398a5c 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -2143,6 +2143,7 @@ void RepoView::popStash(int index) { } // switch back to head selectReference(mRepo.head()); + selectFirstCommit(); } void RepoView::promptToAddTag(const git::Commit &commit) {