Fix up reset transcripts for projects

This commit is contained in:
Chris Penner 2024-07-05 16:55:07 -07:00
parent d0002b45c9
commit 424b43b897
5 changed files with 181 additions and 117 deletions

View File

@ -251,13 +251,7 @@ loop e = do
ShowProjectReflogI mayProj -> do ShowProjectReflogI mayProj -> do
Reflogs.showProjectReflog mayProj Reflogs.showProjectReflog mayProj
ResetI newRoot mtarget -> do ResetI newRoot mtarget -> do
newRoot <- newRoot <- resolveBranchId2 newRoot
case newRoot of
BranchAtPath p -> do
pp <- Cli.resolvePath' p
Cli.getBranchFromProjectPath pp
BranchAtSCH sch -> Cli.resolveShortCausalHash sch
BranchAtProjectPath pp -> Cli.getBranchFromProjectPath pp
target <- target <-
case mtarget of case mtarget of
Nothing -> Cli.getCurrentProjectPath Nothing -> Cli.getCurrentProjectPath
@ -902,11 +896,8 @@ inputDescription input =
Branch.RegularMerge -> "merge" Branch.RegularMerge -> "merge"
Branch.SquashMerge -> "merge.squash" Branch.SquashMerge -> "merge.squash"
pure (command <> " " <> src <> " " <> dest) pure (command <> " " <> src <> " " <> dest)
ResetI hash tgt -> do ResetI newRoot tgt -> do
hashTxt <- case hash of hashTxt <- bid2 newRoot
BranchAtSCH hash -> hp' $ Left hash
BranchAtPath pr -> pure $ into @Text pr
BranchAtProjectPath pp -> pure $ into @Text pp
tgt <- case tgt of tgt <- case tgt of
Nothing -> pure "" Nothing -> pure ""
Just tgt -> do Just tgt -> do
@ -1074,8 +1065,6 @@ inputDescription input =
UpgradeCommitI {} -> wat UpgradeCommitI {} -> wat
VersionI -> wat VersionI -> wat
where where
hp' :: Either SCH.ShortCausalHash Path' -> Cli Text
hp' = either (pure . into @Text) p'
p :: Path -> Cli Text p :: Path -> Cli Text
p = fmap (into @Text) . Cli.resolvePath p = fmap (into @Text) . Cli.resolvePath
p' :: Path' -> Cli Text p' :: Path' -> Cli Text
@ -1096,6 +1085,10 @@ inputDescription input =
hqs (p, hq) = hqs' (Path' . Right . Path.Relative $ p, hq) hqs (p, hq) = hqs' (Path' . Right . Path.Relative $ p, hq)
ps' = p' . Path.unsplit' ps' = p' . Path.unsplit'
ps = p . Path.unsplit ps = p . Path.unsplit
bid2 :: BranchId2 -> Cli Text
bid2 = \case
Left sch -> pure $ into @Text sch
Right p -> brp p
handleFindI :: handleFindI ::
Bool -> Bool ->

View File

@ -126,9 +126,9 @@ data Input
| PullI !PullSourceTarget !PullMode | PullI !PullSourceTarget !PullMode
| PushRemoteBranchI PushRemoteBranchInput | PushRemoteBranchI PushRemoteBranchInput
| ResetRootI BranchId | ResetRootI BranchId
| ResetI BranchId (Maybe UnresolvedProjectBranch) | ResetI (BranchId2 {- namespace to reset it to -}) (Maybe UnresolvedProjectBranch {- ProjectBranch to reset -})
| -- todo: Q: Does it make sense to publish to not-the-root of a Github repo? -- todo: Q: Does it make sense to publish to not-the-root of a Github repo?
-- Does it make sense to fork from not-the-root of a Github repo? | -- Does it make sense to fork from not-the-root of a Github repo?
-- used in Welcome module to give directions to user -- used in Welcome module to give directions to user
CreateMessage (P.Pretty P.ColorText) CreateMessage (P.Pretty P.ColorText)
| -- Change directory. | -- Change directory.

View File

@ -1663,8 +1663,8 @@ reset =
] ]
) )
\case \case
[arg0] -> Input.ResetI <$> handleBranchIdArg arg0 <*> pure Nothing [resetTo] -> Input.ResetI <$> handleBranchId2Arg resetTo <*> pure Nothing
[arg0, arg1] -> Input.ResetI <$> handleBranchIdArg arg0 <*> fmap pure (handleMaybeProjectBranchArg arg1) [resetTo, branchToReset] -> Input.ResetI <$> handleBranchId2Arg resetTo <*> fmap pure (handleMaybeProjectBranchArg branchToReset)
args -> wrongArgsLength "one or two arguments" args args -> wrongArgsLength "one or two arguments" args
where where
config = config =

View File

@ -2,28 +2,36 @@
scratch/main> builtins.merge scratch/main> builtins.merge
``` ```
# reset loose code
```unison ```unison
a = 5 def = "first value"
``` ```
```ucm:hide
scratch/main> update
```
```unison:hide
def = "second value"
```
Can reset to a value from history by number.
```ucm ```ucm
scratch/main> add scratch/main> update
scratch/main> history scratch/main> history
scratch/main> reset 2 scratch/main> reset 2
scratch/main> view def
scratch/main> history scratch/main> history
``` ```
```unison Can reset to a value from reflog by number.
foo.a = 5
```
```ucm ```ucm
scratch/main> add scratch/main> reflog
scratch/main> ls foo -- Reset the current branch to the first history element
scratch/main> reset 2
scratch/main> view def
scratch/main> history scratch/main> history
scratch/main> reset 1 foo
scratch/main> ls foo.foo
``` ```
# reset branch # reset branch
@ -32,47 +40,24 @@ scratch/main> ls foo.foo
foo/main> history foo/main> history
``` ```
```unison ```unison:hide
a = 5 a = 5
``` ```
```ucm ```ucm
foo/main> add foo/main> update
foo/main> branch topic foo/empty> reset /main:.
foo/main> history foo/empty> view a
foo/empty> history
``` ```
```unison ## second argument is always interpreted as a branch
a = 3 ```unison:hide
main.a = 3
``` ```
```ucm ```ucm
foo/main> update foo/main> update
foo/main> reset /topic
foo/main> history
```
# ambiguous reset
## ambiguous target
```unison
main.a = 3
```
```ucm:error
foo/main> add
foo/main> history foo/main> history
foo/main> reset 2 main foo/main> reset 2 main
``` ```
## ambiguous hash
```unison
main.a = 3
```
```ucm:error
foo/main> switch /topic
foo/topic> add
foo/topic> reset main
```

View File

@ -1,6 +1,5 @@
# reset loose code
```unison ```unison
a = 5 def = "first value"
``` ```
```ucm ```ucm
@ -13,30 +12,20 @@ a = 5
⍟ These new definitions are ok to `add`: ⍟ These new definitions are ok to `add`:
a : Nat def : Text
``` ```
```unison
def = "second value"
```
Can reset to a value from history by number.
```ucm ```ucm
scratch/main> add scratch/main> update
⍟ I've added these definitions: Okay, I'm searching the branch for code that needs to be
updated...
a : Nat
scratch/main> history
Note: The most recent namespace hash is immediately below this
message.
⊙ 1. #d079vet1oj
+ Adds / updates:
a
□ 2. #4bigcpnl7t (start of history)
scratch/main> reset 2
Done. Done.
@ -45,67 +34,164 @@ scratch/main> history
Note: The most recent namespace hash is immediately below this Note: The most recent namespace hash is immediately below this
message. message.
⊙ 1. #5vq851j3hg
+ Adds / updates:
□ 1. #4bigcpnl7t (start of history)
```
```unison
foo.a = 5
```
```ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
foo.a : Nat def
```
```ucm
scratch/main> add
⍟ I've added these definitions:
foo.a : Nat ⊙ 2. #ujvq6e87kp
+ Adds / updates:
def
□ 3. #4bigcpnl7t (start of history)
scratch/main> ls foo scratch/main> reset 2
1. a (Nat) Done.
scratch/main> view def
def : Text
def = "first value"
scratch/main> history scratch/main> history
Note: The most recent namespace hash is immediately below this Note: The most recent namespace hash is immediately below this
message. message.
⊙ 1. #tfg7r9359n ⊙ 1. #ujvq6e87kp
+ Adds / updates: + Adds / updates:
foo.a def
□ 2. #4bigcpnl7t (start of history) □ 2. #4bigcpnl7t (start of history)
scratch/main> reset 1 foo ```
Can reset to a value from reflog by number.
scratch/foo does not exist. ```ucm
scratch/main> reflog
Below is a record of recent changes, you can use
`reset #abcdef` to reset the current branch to a previous
state.
Tip: Use `diff.namespace 1 7` to compare between points in
history.
Branch When Hash Description
1. scratch/main now #ujvq6e87kp reset ujvq6e87kp4288eq3al9v5luctic0ocd7ug1fu0go5bicrr2vfnrb0...
2. scratch/main now #5vq851j3hg update
3. scratch/main now #ujvq6e87kp update
4. scratch/main now #4bigcpnl7t builtins.merge
5. scratch/main now #sg60bvjo91 Project Created
-- Reset the current branch to the first history element
scratch/main> reset 2
Done.
scratch/main> view def
def : Text
def = "second value"
scratch/main> history
Note: The most recent namespace hash is immediately below this
message.
⊙ 1. #5vq851j3hg
+ Adds / updates:
def
⊙ 2. #ujvq6e87kp
+ Adds / updates:
def
□ 3. #4bigcpnl7t (start of history)
```
# reset branch
```ucm
foo/main> history
Note: The most recent namespace hash is immediately below this
message.
□ 1. #sg60bvjo91 (start of history)
```
```unison
a = 5
``` ```
```ucm ```ucm
scratch/main> addscratch/main> ls fooscratch/main> historyscratch/main> reset 1 fooscratch/main> ls foo.foo foo/main> update
Okay, I'm searching the branch for code that needs to be
updated...
Done.
foo/empty> reset /main:.
Done.
foo/empty> view a
a : ##Nat
a = 5
foo/empty> history
Note: The most recent namespace hash is immediately below this
message.
□ 1. #5l94rduvel (start of history)
```
## second argument is always interpreted as a branch
```unison
main.a = 3
``` ```
```ucm
foo/main> update
🛑 Okay, I'm searching the branch for code that needs to be
updated...
The transcript failed due to an error in the stanza above. The error is: Done.
foo/main> history
scratch/foo does not exist. Note: The most recent namespace hash is immediately below this
message.
⊙ 1. #0i64kpfccl
+ Adds / updates:
main.a
□ 2. #5l94rduvel (start of history)
foo/main> reset 2 main
Done.
```