diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-27 20:44:28 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-27 20:44:28 +0200 |
commit | bdd1d73969ff9015f444239099ed4cdd6afff910 (patch) | |
tree | d3a7332cdde0e549dca9da48d1576f761da448bb | |
parent | a56d5c3c753241d205ed2f3e28618d18bf8eb1d9 (diff) |
Test repo subtree
-rw-r--r-- | minici.cabal | 1 | ||||
-rw-r--r-- | src/Command/Subtree.hs | 46 | ||||
-rw-r--r-- | src/Main.hs | 2 | ||||
-rw-r--r-- | test/script/repo.et | 65 |
4 files changed, 114 insertions, 0 deletions
diff --git a/minici.cabal b/minici.cabal index 4854367..c8d0fe5 100644 --- a/minici.cabal +++ b/minici.cabal @@ -53,6 +53,7 @@ executable minici Command.JobId Command.Log Command.Run + Command.Subtree Config Eval Job diff --git a/src/Command/Subtree.hs b/src/Command/Subtree.hs new file mode 100644 index 0000000..8d42d73 --- /dev/null +++ b/src/Command/Subtree.hs @@ -0,0 +1,46 @@ +module Command.Subtree ( + SubtreeCommand, +) where + +import Data.Text (Text) +import Data.Text qualified as T + +import Command +import Output +import Repo + + +data SubtreeCommand = SubtreeCommand SubtreeOptions [ Text ] + +data SubtreeOptions = SubtreeOptions + +instance Command SubtreeCommand where + commandName _ = "subtree" + commandDescription _ = "Resolve subdirectory of given repo tree" + + type CommandArguments SubtreeCommand = [ Text ] + + commandUsage _ = T.pack $ unlines $ + [ "Usage: minici subtree <tree> <path>" + ] + + type CommandOptions SubtreeCommand = SubtreeOptions + defaultCommandOptions _ = SubtreeOptions + + commandInit _ opts = SubtreeCommand opts + commandExec = cmdSubtree + + +cmdSubtree :: SubtreeCommand -> CommandExec () +cmdSubtree (SubtreeCommand SubtreeOptions args) = do + [ treeParam, path ] <- return args + out <- getOutput + repo <- getDefaultRepo + + let ( tree, subdir ) = + case T.splitOn "(" treeParam of + (t : param : _) -> ( t, T.unpack $ T.takeWhile (/= ')') param ) + _ -> ( treeParam, "" ) + + subtree <- getSubtree Nothing (T.unpack path) =<< readTree repo subdir tree + outputMessage out $ textTreeId $ treeId subtree diff --git a/src/Main.hs b/src/Main.hs index e273715..ec03acb 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -25,6 +25,7 @@ import Command.Extract import Command.JobId import Command.Log import Command.Run +import Command.Subtree import Config import Output import Repo @@ -92,6 +93,7 @@ commands = , SC $ Proxy @ExtractCommand , SC $ Proxy @JobIdCommand , SC $ Proxy @LogCommand + , SC $ Proxy @SubtreeCommand ] lookupCommand :: String -> Maybe SomeCommandType diff --git a/test/script/repo.et b/test/script/repo.et new file mode 100644 index 0000000..7a34a1c --- /dev/null +++ b/test/script/repo.et @@ -0,0 +1,65 @@ +test RepoSubtree: + node n + shell on n as git_init: + mkdir -p work + git -C work -c init.defaultBranch=master init -q + git -C work -c user.name=test -c user.email=test commit -q --allow-empty -m 'initial commit' + + mkdir -p work/first/second + touch work/first/second/file + git -C work add first + git -C work -c user.name=test -c user.email=test commit -q -m 'commit' + git -C work rev-parse HEAD^{commit} + git -C work rev-parse HEAD^{tree} + git -C work rev-parse HEAD:first + git -C work rev-parse HEAD:first/second + + expect /([0-9a-f]+)/ from git_init capture commit + expect /([0-9a-f]+)/ from git_init capture root + expect /([0-9a-f]+)/ from git_init capture sub1 + expect /([0-9a-f]+)/ from git_init capture sub2 + + for repo in [ "./work" ]: + local: + spawn as p on n args [ repo, "subtree", commit, "" ] + expect from p /msg $root/ + + local: + spawn as p on n args [ repo, "subtree", commit, "." ] + expect from p /msg $root/ + + local: + spawn as p on n args [ repo, "subtree", commit, "/" ] + expect from p /msg $root/ + + local: + spawn as p on n args [ repo, "subtree", commit, "first" ] + expect from p /msg $sub1/ + + local: + spawn as p on n args [ repo, "subtree", commit, "./first" ] + expect from p /msg $sub1/ + + local: + spawn as p on n args [ repo, "subtree", commit, "/first" ] + expect from p /msg $sub1/ + + local: + spawn as p on n args [ repo, "subtree", commit, "./first/second" ] + expect from p /msg $sub2/ + + local: + spawn as p on n args [ repo, "subtree", commit, "/first/second" ] + expect from p /msg $sub2/ + + local: + spawn as p on n args [ repo, "subtree", "$sub1(first)", "second" ] + expect from p /msg $sub2/ + + local: + spawn as p on n args [ repo, "subtree", "$sub1(first)", "./second" ] + expect from p /msg $sub2/ + + local: + spawn as p on n args [ repo, "subtree", "$sub1(first)", "/second/" ] + expect from p /msg $sub2/ |