vpop: Only update state after successful checkout

If checkout fails for some reason, they're still in a view, and should be
able to vpop again.
This commit is contained in:
Joey Hess 2024-11-11 14:15:51 -04:00
parent c8e83189f6
commit 447e6adabd
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 42 additions and 6 deletions

View file

@ -28,22 +28,29 @@ start ps = go =<< currentView
where
go Nothing = giveup "Not in a view."
go (Just (v, madj)) = starting "vpop" ai si $ do
removeView v
(oldvs, vs) <- splitAt (num - 1) . filter (sameparentbranch v)
(oldvs, vs) <- splitAt (num - 1)
. filter (sameparentbranch v)
. filter (/= v)
<$> recentViews
mapM_ removeView oldvs
case vs of
(oldv:_) -> next $ do
let removeview = mapM_ removeView (v : oldvs)
ok <- case vs of
(oldv:_) -> do
showOutput
checkoutViewBranch oldv madj
(\v' madj' -> return (branchView v' madj'))
_ -> next $ do
_ -> do
showOutput
inRepo $ Git.Command.runBool
[ Param "checkout"
, Param $ Git.fromRef $ Git.Ref.base $
viewParentBranch v
]
if ok
then
next $ do
removeview
return True
else next $ return False
sameparentbranch a b = viewParentBranch a == viewParentBranch b
num = fromMaybe 1 $ readish =<< headMaybe ps