From d8dfaf68948ea2c33de2d4fefe904bab6e636d6b Mon Sep 17 00:00:00 2001 From: Chris Penner Date: Mon, 6 Dec 2021 15:49:02 -0600 Subject: [PATCH] Consider only head when checking for empty branch in most commands --- .../src/Unison/Codebase/Editor/HandleInput.hs | 10 +-- .../transcripts/empty-namespaces.output.md | 66 +++++-------------- 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs index 85bc5d1ed..53efd57fe 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs @@ -660,7 +660,7 @@ loop = do let dest = resolveToAbsolute dest0 -- if dest isn't empty: leave dest unchanged, and complain. destb <- getAt dest - if Branch.isEmpty destb + if Branch.isEmpty0 (Branch.head destb) then do ok <- updateAtM dest (const $ pure srcb) if ok then success else respond $ BranchEmpty src0 @@ -677,7 +677,7 @@ loop = do MergeLocalBranchI src0 dest0 mergeMode -> do let [src, dest] = resolveToAbsolute <$> [src0, dest0] srcb <- getAt src - if Branch.isEmpty srcb + if Branch.isEmpty0 (Branch.head srcb) then branchNotFound src0 else do let err = Just $ MergeAlreadyUpToDate src0 dest0 @@ -685,7 +685,7 @@ loop = do PreviewMergeLocalBranchI src0 dest0 -> do let [src, dest] = resolveToAbsolute <$> [src0, dest0] srcb <- getAt src - if Branch.isEmpty srcb + if Branch.isEmpty0 (Branch.head srcb) then branchNotFound src0 else do destb <- getAt dest @@ -1903,8 +1903,8 @@ doPushRemoteBranch repo localPath syncMode remoteTarget = do shouldPushTo :: PushBehavior -> Branch m -> Bool shouldPushTo pushBehavior remoteBranch = case pushBehavior of - PushBehavior.RequireEmpty -> Branch.isEmpty remoteBranch - PushBehavior.RequireNonEmpty -> not (Branch.isEmpty remoteBranch) + PushBehavior.RequireEmpty -> Branch.isEmpty0 (Branch.head remoteBranch) + PushBehavior.RequireNonEmpty -> not (Branch.isEmpty0 (Branch.head remoteBranch)) -- | Handle a @ShowDefinitionI@ input command, i.e. `view` or `edit`. handleShowDefinition :: diff --git a/unison-src/transcripts/empty-namespaces.output.md b/unison-src/transcripts/empty-namespaces.output.md index f6c20757a..e617c22ba 100644 --- a/unison-src/transcripts/empty-namespaces.output.md +++ b/unison-src/transcripts/empty-namespaces.output.md @@ -1,75 +1,41 @@ # Empty namespace behaviours +## Operations on empty namespaces + +Add and then delete a term to add some history to a deleted namespace. + ```unison -mynamespace.x = 1 +deleted.x = 1 +stuff.thing = 2 ``` -The deleted namespace shouldn't appear in `ls` output. -```ucm -.> ls +I should be allowed to fork over a deleted namespace - nothing to show +```ucm +.> fork stuff deleted + + Done. ``` -```ucm -.> ls.verbose - - 😶 - - No results. Check your spelling, or try using tab completion - to supply command arguments. - -``` -```ucm -.> find mynamespace - - 😶 - - No results. Check your spelling, or try using tab completion - to supply command arguments. - -``` -The history of the namespace should still exist if requested explicitly. +The history from the `deleted` namespace should have been overwritten by the history from `stuff`. ```ucm -.> history mynamespace +.> history stuff Note: The most recent namespace hash is immediately below this message. - ⊙ #qjc20aua9h - - Deletes: - - x - □ #hkrqt3tm05 (start of history) + □ #3bm1524lb7 (start of history) -``` -Merging an empty namespace should still copy its history if it has some. - -```ucm - ☝️ The namespace .empty is empty. - -.empty> history - - ☝️ The namespace .empty is empty. - -.empty> merge .mynamespace - - Nothing changed as a result of the merge. - -.empty> history +.> history deleted Note: The most recent namespace hash is immediately below this message. - ⊙ #qjc20aua9h - - Deletes: - - x - □ #hkrqt3tm05 (start of history) + □ #3bm1524lb7 (start of history) ```