diff --git a/semantic.cabal b/semantic.cabal index d360dc1824..d0cb1fce5a 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -1,7 +1,7 @@ cabal-version: 2.4 name: semantic -version: 0.6.0.0 +version: 0.7.0.0 synopsis: Framework and executable for analyzing and diffing untrusted code. description: Semantic is a library for parsing, analyzing, and comparing source code across many languages. homepage: http://github.com/github/semantic#readme diff --git a/src/Semantic/Git.hs b/src/Semantic/Git.hs index 4923dcb0ce..903023c523 100644 --- a/src/Semantic/Git.hs +++ b/src/Semantic/Git.hs @@ -60,8 +60,8 @@ entryParser = TreeEntry <*> oidParser <* AP.char '\t' <*> (unpack <$> AP.takeWhile (/= '\NUL')) where - typeParser = AP.choice [BlobObject <$ "blob", TreeObject <$ "tree"] - modeParser = AP.choice [NormalMode <$ "100644", ExecutableMode <$ "100755", SymlinkMode <$ "120000", TreeMode <$ "040000"] + typeParser = AP.choice [BlobObject <$ "blob", TreeObject <$ "tree", OtherObjectType <$ AP.takeWhile isAlphaNum] + modeParser = AP.choice [NormalMode <$ "100644", ExecutableMode <$ "100755", SymlinkMode <$ "120000", TreeMode <$ "040000", OtherMode <$ AP.takeWhile isAlphaNum] oidParser = OID <$> AP.takeWhile isHexDigit newtype OID = OID Text diff --git a/test/Semantic/Spec.hs b/test/Semantic/Spec.hs index 91a3b1d254..a73c7233ec 100644 --- a/test/Semantic/Spec.hs +++ b/test/Semantic/Spec.hs @@ -44,5 +44,10 @@ spec = do let expected = [ TreeEntry NormalMode TreeObject (OID "abcdef") "/this/is/the/path", TreeEntry SymlinkMode BlobObject (OID "17776") "/dev/urandom"] parseEntries input `shouldBe` expected + it "parses submodules and other types" $ do + let input = "160000 commit 50865e8895c54037bf06c4c1691aa925d030a59d\tgemoji" + let expected = Right $ TreeEntry OtherMode OtherObjectType (OID "50865e8895c54037bf06c4c1691aa925d030a59d") "gemoji" + parseEntry input `shouldBe` expected + where methodsBlob = makeBlob "def foo\nend\n" "methods.rb" Ruby mempty