avoid displaying error from git symbolic-ref -q HEAD

Usually this won't fail even if .git/HEAD is not set or points to a ref
that doesn't exist. However, early in clone, it contains
"ref: refs/heads/.invalid" which causes an error "fatal: No such ref: HEAD"

When cloning from a special remote, git-remote-annex output that once
per bundle.
This commit is contained in:
Joey Hess 2024-05-24 13:49:18 -04:00
parent 2670508b97
commit 0ba2b89c71
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -40,15 +40,19 @@ current r = do
{- The current branch, which may not really exist yet. -}
currentUnsafe :: Repo -> IO (Maybe Branch)
currentUnsafe r = parse . firstLine' <$> pipeReadStrict
[ Param "symbolic-ref"
, Param "-q"
, Param $ fromRef Git.Ref.headRef
] r
currentUnsafe r = withNullHandle $ \nullh ->
parse . firstLine' <$> pipeReadStrict'
(\p -> p { std_err = UseHandle nullh })
ps r
where
parse b
| B.null b = Nothing
| otherwise = Just $ Git.Ref b
ps =
[ Param "symbolic-ref"
, Param "-q"
, Param $ fromRef Git.Ref.headRef
]
{- Checks if the second branch has any commits not present on the first
- branch. -}