add git for-each-ref binding

Sponsored-by: Luke T. Shumaker on Patreon
This commit is contained in:
Joey Hess 2024-05-07 14:22:04 -04:00
parent c7731cdbd9
commit 8d58a23548
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -1,6 +1,6 @@
{- git ref stuff {- git ref stuff
- -
- Copyright 2011-2020 Joey Hess <id@joeyh.name> - Copyright 2011-2024 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - 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 :: Repo -> IO [(Sha, Ref)]
list = matching' [] [] 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, {- Deletes a ref. This can delete refs that are not branches,
- which git branch --delete refuses to delete. -} - which git branch --delete refuses to delete. -}
delete :: Sha -> Ref -> Repo -> IO () delete :: Sha -> Ref -> Repo -> IO ()