From 8d58a2354809866f7a6097dc8981f736dd69cf93 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 7 May 2024 14:22:04 -0400 Subject: [PATCH] add git for-each-ref binding Sponsored-by: Luke T. Shumaker on Patreon --- Git/Ref.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Git/Ref.hs b/Git/Ref.hs index 2d2874a7ef..72e8b15cd4 100644 --- a/Git/Ref.hs +++ b/Git/Ref.hs @@ -1,6 +1,6 @@ {- git ref stuff - - - Copyright 2011-2020 Joey Hess + - Copyright 2011-2024 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -165,6 +165,15 @@ matchingUniq refs repo = nubBy uniqref <$> matching refs repo list :: Repo -> IO [(Sha, Ref)] list = matching' [] [] +{- Lists refs using for-each-ref. -} +forEachRef :: [CommandParam] -> Repo -> IO [(Sha, Branch)] +forEachRef ps repo = map gen . S8.lines <$> + pipeReadStrict (Param "for-each-ref" : ps ++ [format]) repo + where + format = Param "--format=%(objectname) %(refname)" + gen l = let (r, b) = separate' (== fromIntegral (ord ' ')) l + in (Ref r, Ref b) + {- Deletes a ref. This can delete refs that are not branches, - which git branch --delete refuses to delete. -} delete :: Sha -> Ref -> Repo -> IO ()