Consider only head when checking for empty branch in most commands

This commit is contained in:
Chris Penner 2021-12-06 15:49:02 -06:00
parent 6f6685ca35
commit d8dfaf6894
2 changed files with 21 additions and 55 deletions

View File

@ -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 ::

View File

@ -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)
```