From 424b43b897c99167246d528382c35cd38c7e5189 Mon Sep 17 00:00:00 2001 From: Chris Penner Date: Fri, 5 Jul 2024 16:55:07 -0700 Subject: [PATCH] Fix up reset transcripts for projects --- .../src/Unison/Codebase/Editor/HandleInput.hs | 21 +- .../src/Unison/Codebase/Editor/Input.hs | 6 +- .../src/Unison/CommandLine/InputPatterns.hs | 4 +- unison-src/transcripts/reset.md | 67 +++--- unison-src/transcripts/reset.output.md | 200 +++++++++++++----- 5 files changed, 181 insertions(+), 117 deletions(-) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs index 1361c13ad..1533096d3 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput.hs @@ -251,13 +251,7 @@ loop e = do ShowProjectReflogI mayProj -> do Reflogs.showProjectReflog mayProj ResetI newRoot mtarget -> do - newRoot <- - case newRoot of - BranchAtPath p -> do - pp <- Cli.resolvePath' p - Cli.getBranchFromProjectPath pp - BranchAtSCH sch -> Cli.resolveShortCausalHash sch - BranchAtProjectPath pp -> Cli.getBranchFromProjectPath pp + newRoot <- resolveBranchId2 newRoot target <- case mtarget of Nothing -> Cli.getCurrentProjectPath @@ -902,11 +896,8 @@ inputDescription input = Branch.RegularMerge -> "merge" Branch.SquashMerge -> "merge.squash" pure (command <> " " <> src <> " " <> dest) - ResetI hash tgt -> do - hashTxt <- case hash of - BranchAtSCH hash -> hp' $ Left hash - BranchAtPath pr -> pure $ into @Text pr - BranchAtProjectPath pp -> pure $ into @Text pp + ResetI newRoot tgt -> do + hashTxt <- bid2 newRoot tgt <- case tgt of Nothing -> pure "" Just tgt -> do @@ -1074,8 +1065,6 @@ inputDescription input = UpgradeCommitI {} -> wat VersionI -> wat where - hp' :: Either SCH.ShortCausalHash Path' -> Cli Text - hp' = either (pure . into @Text) p' p :: Path -> Cli Text p = fmap (into @Text) . Cli.resolvePath p' :: Path' -> Cli Text @@ -1096,6 +1085,10 @@ inputDescription input = hqs (p, hq) = hqs' (Path' . Right . Path.Relative $ p, hq) 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 :: Bool -> diff --git a/unison-cli/src/Unison/Codebase/Editor/Input.hs b/unison-cli/src/Unison/Codebase/Editor/Input.hs index 262b75908..0dfc2b034 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Input.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Input.hs @@ -126,9 +126,9 @@ data Input | PullI !PullSourceTarget !PullMode | PushRemoteBranchI PushRemoteBranchInput | ResetRootI BranchId - | ResetI BranchId (Maybe UnresolvedProjectBranch) - | -- 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? + | 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? + | -- Does it make sense to fork from not-the-root of a Github repo? -- used in Welcome module to give directions to user CreateMessage (P.Pretty P.ColorText) | -- Change directory. diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index 6032f2efb..c03b899dd 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -1663,8 +1663,8 @@ reset = ] ) \case - [arg0] -> Input.ResetI <$> handleBranchIdArg arg0 <*> pure Nothing - [arg0, arg1] -> Input.ResetI <$> handleBranchIdArg arg0 <*> fmap pure (handleMaybeProjectBranchArg arg1) + [resetTo] -> Input.ResetI <$> handleBranchId2Arg resetTo <*> pure Nothing + [resetTo, branchToReset] -> Input.ResetI <$> handleBranchId2Arg resetTo <*> fmap pure (handleMaybeProjectBranchArg branchToReset) args -> wrongArgsLength "one or two arguments" args where config = diff --git a/unison-src/transcripts/reset.md b/unison-src/transcripts/reset.md index f8d18e782..2cd19597d 100644 --- a/unison-src/transcripts/reset.md +++ b/unison-src/transcripts/reset.md @@ -2,28 +2,36 @@ scratch/main> builtins.merge ``` -# reset loose code ```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 -scratch/main> add +scratch/main> update scratch/main> history scratch/main> reset 2 +scratch/main> view def scratch/main> history ``` -```unison -foo.a = 5 -``` +Can reset to a value from reflog by number. ```ucm -scratch/main> add -scratch/main> ls foo +scratch/main> reflog +-- Reset the current branch to the first history element +scratch/main> reset 2 +scratch/main> view def scratch/main> history -scratch/main> reset 1 foo -scratch/main> ls foo.foo ``` # reset branch @@ -32,47 +40,24 @@ scratch/main> ls foo.foo foo/main> history ``` -```unison +```unison:hide a = 5 ``` ```ucm -foo/main> add -foo/main> branch topic -foo/main> history +foo/main> update +foo/empty> reset /main:. +foo/empty> view a +foo/empty> history ``` -```unison -a = 3 +## second argument is always interpreted as a branch +```unison:hide +main.a = 3 ``` ```ucm 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> reset 2 main ``` - -## ambiguous hash - -```unison -main.a = 3 -``` - -```ucm:error -foo/main> switch /topic -foo/topic> add -foo/topic> reset main -``` diff --git a/unison-src/transcripts/reset.output.md b/unison-src/transcripts/reset.output.md index ea8f1b645..7cfac62e4 100644 --- a/unison-src/transcripts/reset.output.md +++ b/unison-src/transcripts/reset.output.md @@ -1,6 +1,5 @@ -# reset loose code ```unison -a = 5 +def = "first value" ``` ```ucm @@ -13,30 +12,20 @@ a = 5 ⍟ 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 -scratch/main> add +scratch/main> update - ⍟ I've added these definitions: - - 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 + Okay, I'm searching the branch for code that needs to be + updated... Done. @@ -45,67 +34,164 @@ scratch/main> history Note: The most recent namespace hash is immediately below this message. + ⊙ 1. #5vq851j3hg - - □ 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`: + + Adds / updates: - foo.a : Nat - -``` -```ucm -scratch/main> add - - ⍟ I've added these definitions: + def - 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 Note: The most recent namespace hash is immediately below this message. - ⊙ 1. #tfg7r9359n + ⊙ 1. #ujvq6e87kp + Adds / updates: - foo.a + def □ 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 -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. + +```