Skip to content
Snippets Groups Projects
Commit 91ff0971 authored by Matthew Pickering's avatar Matthew Pickering Committed by Marge Bot
Browse files

Submodule linter: Allow references to tags

We modify the submodule linter so that if the bumped commit is a
specific tag then the commit is accepted.

Fixes #24241
parent 36b9a38c
No related branches found
No related tags found
No related merge requests found
...@@ -18,12 +18,12 @@ import System.Exit ...@@ -18,12 +18,12 @@ import System.Exit
-- text -- text
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
( putStrLn ) ( putStrLn, putStr )
-- linters-common -- linters-common
import Linters.Common import Linters.Common
( GitType(..) ( GitType(..)
, gitBranchesContain, gitCatCommit, gitDiffTree, gitNormCid , gitBranchesContain, gitIsTagged, gitCatCommit, gitDiffTree, gitNormCid
) )
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
...@@ -51,16 +51,18 @@ main = do ...@@ -51,16 +51,18 @@ main = do
exitWith (ExitFailure 1) exitWith (ExitFailure 1)
bad <- fmap or $ forM smDeltas $ \(smPath,smCid) -> do bad <- fmap or $ forM smDeltas $ \(smPath,smCid) -> do
T.putStrLn $ " - " <> smPath <> " => " <> smCid T.putStr $ " - " <> smPath <> " => " <> smCid
let smAbsPath = dir ++ "/" ++ T.unpack smPath let smAbsPath = dir ++ "/" ++ T.unpack smPath
remoteBranches <- gitBranchesContain smAbsPath smCid remoteBranches <- gitBranchesContain smAbsPath smCid
isTagged <- gitIsTagged smAbsPath smCid
let (wip, nonWip) = partition ("wip/" `T.isPrefixOf`) originBranches let (wip, nonWip) = partition ("wip/" `T.isPrefixOf`) originBranches
originBranches = mapMaybe isOriginTracking remoteBranches originBranches = mapMaybe isOriginTracking remoteBranches
isOriginTracking = T.stripPrefix "origin/" isOriginTracking = T.stripPrefix "origin/"
let bad = null nonWip case (nonWip ++ isTagged) of
when bad $ do [] -> do
T.putStrLn " ... BAD"
T.putStrLn $ " *FAIL* commit not found in submodule repo" T.putStrLn $ " *FAIL* commit not found in submodule repo"
T.putStrLn " or not reachable from persistent branches" T.putStrLn " or not reachable from persistent branches"
T.putStrLn "" T.putStrLn ""
...@@ -70,8 +72,15 @@ main = do ...@@ -70,8 +72,15 @@ main = do
commit <- gitNormCid smAbsPath ("origin/" <> branch) commit <- gitNormCid smAbsPath ("origin/" <> branch)
T.putStrLn $ " - " <> branch <> " -> " <> commit T.putStrLn $ " - " <> branch <> " -> " <> commit
T.putStrLn "" T.putStrLn ""
pure bad return True
(b:bs) -> do
let more = case bs of
[] -> ")"
rest -> " and " <> T.pack (show (length rest)) <> " more)"
T.putStrLn $ "... OK (" <> b <> more
return False
if bad if bad
then exitWith (ExitFailure 1) then exitWith (ExitFailure 1)
else T.putStrLn " OK" else T.putStrLn "OK"
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
...@@ -105,6 +106,10 @@ gitBranchesContain d ref = do ...@@ -105,6 +106,10 @@ gitBranchesContain d ref = do
return $!! map (T.drop 2) tmp return $!! map (T.drop 2) tmp
gitIsTagged :: FilePath -> GitRef -> Sh [Text]
gitIsTagged d ref =
T.lines <$> runGit d "tag" ["--points-at", ref]
-- | returns @[(path, (url, key))]@ -- | returns @[(path, (url, key))]@
-- --
-- may throw exception -- may throw exception
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment