diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-11 21:06:16 +0100 | 
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-11 21:06:16 +0100 | 
| commit | 387d63dfbc9cf5b71819461fac2397b57caeb3e4 (patch) | |
| tree | 1f0f416f38d27a1bcfa7979c51ae9d24507c0c92 /src/Command | |
| parent | 8e8cbbd3bd15d6557a25ca83ec31cdec8acfdba6 (diff) | |
Checkout unstaged changes in working directory
Diffstat (limited to 'src/Command')
| -rw-r--r-- | src/Command/Checkout.hs | 19 | ||||
| -rw-r--r-- | src/Command/Run.hs | 2 | 
2 files changed, 12 insertions, 9 deletions
| diff --git a/src/Command/Checkout.hs b/src/Command/Checkout.hs index 65857b8..397db79 100644 --- a/src/Command/Checkout.hs +++ b/src/Command/Checkout.hs @@ -2,6 +2,7 @@ module Command.Checkout (      CheckoutCommand,  ) where +import Data.Maybe  import Data.Text (Text)  import Data.Text qualified as T @@ -11,7 +12,7 @@ import Command  import Repo -data CheckoutCommand = CheckoutCommand CheckoutOptions (Maybe RepoName) Text +data CheckoutCommand = CheckoutCommand CheckoutOptions (Maybe RepoName) (Maybe Text)  data CheckoutOptions = CheckoutOptions      { coPath :: Maybe FilePath @@ -43,17 +44,19 @@ instance Command CheckoutCommand where              "repository subtree to checkout"          ] -    commandInit _ co = uncurry (CheckoutCommand co) . \case -        (name : revision : _) -> ( Just (RepoName name), revision ) -        [ name ]              -> ( Just (RepoName name), "HEAD" ) -        []                    -> ( Nothing, "HEAD" ) +    commandInit _ co args = CheckoutCommand co +        (RepoName <$> listToMaybe args) +        (listToMaybe $ drop 1 args)      commandExec = cmdCheckout  cmdCheckout :: CheckoutCommand -> CommandExec () -cmdCheckout (CheckoutCommand CheckoutOptions {..} name revision) = do +cmdCheckout (CheckoutCommand CheckoutOptions {..} name mbrev) = do      repo <- maybe getDefaultRepo getRepo name -    root <- maybe (fail $ T.unpack $ "revision `" <> revision <> "' not found") getCommitTree =<< readCommit repo revision +    root <- getCommitTree =<< case mbrev of +        Just revision -> readCommit repo revision +        Nothing -> createWipCommit repo      tree <- case coSubtree of          Nothing -> return root -        Just subtree -> maybe (fail $ "subtree `" <> subtree <> "' not found in revision `" <> T.unpack revision <> "'") return =<< getSubtree subtree root +        Just subtree -> maybe (fail $ "subtree `" <> subtree <> "' not found in " <> maybe "current worktree" (("revision `" <>) . (<> "'") . T.unpack) mbrev) return =<< +            getSubtree subtree root      checkoutAt tree $ maybe "." id coPath diff --git a/src/Command/Run.hs b/src/Command/Run.hs index 3968196..383276d 100644 --- a/src/Command/Run.hs +++ b/src/Command/Run.hs @@ -129,7 +129,7 @@ argumentJobSource names = do          case find ((name ==) . jobName) (configJobs config) of              Just job -> return job              Nothing -> tfail $ "job `" <> textJobName name <> "' not found" -    Just jobsetCommit <- flip readCommit "HEAD" =<< getDefaultRepo +    jobsetCommit <- createWipCommit =<< getDefaultRepo      oneshotJobSource [ JobSet {..} ]  rangeSource :: Repo -> Text -> Text -> IO JobSource |