diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-07 22:00:57 +0100 | 
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-07 22:00:57 +0100 | 
| commit | b2295603ac1a8e333079fe1a87c04b27bd4ce157 (patch) | |
| tree | cdc68ec6d734b100453c22ab68ae09459fec9205 /src/Command | |
| parent | 53ed8a2eb2c0f8eab4c346114c0b777cdf7c9f55 (diff) | |
Subtree checkout option
Diffstat (limited to 'src/Command')
| -rw-r--r-- | src/Command/Checkout.hs | 10 | 
1 files changed, 9 insertions, 1 deletions
| diff --git a/src/Command/Checkout.hs b/src/Command/Checkout.hs index 0ed062d..65857b8 100644 --- a/src/Command/Checkout.hs +++ b/src/Command/Checkout.hs @@ -15,6 +15,7 @@ data CheckoutCommand = CheckoutCommand CheckoutOptions (Maybe RepoName) Text  data CheckoutOptions = CheckoutOptions      { coPath :: Maybe FilePath +    , coSubtree :: Maybe FilePath      }  instance Command CheckoutCommand where @@ -30,12 +31,16 @@ instance Command CheckoutCommand where      type CommandOptions CheckoutCommand = CheckoutOptions      defaultCommandOptions _ = CheckoutOptions          { coPath = Nothing +        , coSubtree = Nothing          }      commandOptions _ =          [ Option [] [ "path" ]              (ReqArg (\val opts -> opts { coPath = Just val }) "<path>")              "destination path" +        , Option [] [ "subtree" ] +            (ReqArg (\val opts -> opts { coSubtree = Just val }) "<path>") +            "repository subtree to checkout"          ]      commandInit _ co = uncurry (CheckoutCommand co) . \case @@ -47,5 +52,8 @@ instance Command CheckoutCommand where  cmdCheckout :: CheckoutCommand -> CommandExec ()  cmdCheckout (CheckoutCommand CheckoutOptions {..} name revision) = do      repo <- maybe getDefaultRepo getRepo name -    tree <- maybe (fail $ T.unpack $ "revision `" <> revision <> "' not found") getCommitTree =<< readCommit repo revision +    root <- maybe (fail $ T.unpack $ "revision `" <> revision <> "' not found") getCommitTree =<< readCommit repo revision +    tree <- case coSubtree of +        Nothing -> return root +        Just subtree -> maybe (fail $ "subtree `" <> subtree <> "' not found in revision `" <> T.unpack revision <> "'") return =<< getSubtree subtree root      checkoutAt tree $ maybe "." id coPath |