From 04a256a0f84bf8f44e9bc82b5976192cc022e664 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 24 May 2024 15:49:53 -0400 Subject: [PATCH] work around git "defense in depth" breakage with git clone checking for hooks This git bug also broke git-lfs, and I am confident it will be reverted in the next release. For now, cloning from an annex:: url wastes some bandwidth on the next pull by not caching bundles locally. If git doesn't fix this in the next version, I'd be tempted to rethink whether bundle objects need to be cached locally. It would be possible to instead remember which bundles have been seen and their heads, and respond to the list command with the heads, and avoid unbundling them agian in fetch. This might even be a useful performance improvement in the latter case. It would be quite a complication to a currently simple implementation though. --- CmdLine/GitRemoteAnnex.hs | 21 ++++++++++++++++++- Git/Version.hs | 2 +- ...l_with_git_fsck_symlinkPointsToGitDir.mdwn | 7 ------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CmdLine/GitRemoteAnnex.hs b/CmdLine/GitRemoteAnnex.hs index dd9abf7999..d7a75c9f16 100644 --- a/CmdLine/GitRemoteAnnex.hs +++ b/CmdLine/GitRemoteAnnex.hs @@ -20,6 +20,7 @@ import qualified Git.Branch import qualified Git.Bundle import qualified Git.Remote import qualified Git.Remote.Remove +import qualified Git.Version import qualified Annex.SpecialRemote as SpecialRemote import qualified Annex.Branch import qualified Annex.BranchState @@ -1010,6 +1011,12 @@ specialRemoteFromUrl sab a = withTmpDir "journal" $ \tmpdir -> do -- When there is now a sibling git-annex branch, this handles -- initialization. When the initialized git-annex branch has Differences, -- the git bundle objects are in the wrong place, so have to be deleted. +-- +-- Unfortunately, git 2.45.1 and related releases added a +-- "defense in depth" check that a freshly cloned repository +-- does not contain any hooks. Since initialization installs +-- hooks, have to work around that by not initializing, and +-- delete the git bundle objects. cleanupInitialization :: StartAnnexBranch -> Annex () cleanupInitialization sab = do case sab of @@ -1019,7 +1026,7 @@ cleanupInitialization sab = do inRepo $ Git.Branch.delete Annex.Branch.fullname indexfile <- fromRepo gitAnnexIndex liftIO $ removeWhenExistsWith R.removeLink indexfile - ifM Annex.Branch.hasSibling + ifM (Annex.Branch.hasSibling <&&> nonbuggygitversion) ( do autoInitialize' (pure True) remoteList differences <- allDifferences <$> recordedDifferences @@ -1035,3 +1042,15 @@ cleanupInitialization sab = do GitBundleKey -> lockContentForRemoval k noop removeAnnex _ -> noop void $ liftIO $ tryIO $ removeDirectory (decodeBS annexobjectdir) + + nonbuggygitversion = liftIO $ + flip notElem buggygitversions <$> Git.Version.installed + buggygitversions = map Git.Version.normalize + [ "2.45.1" + , "2.44.1" + , "2.43.4" + , "2.42.2" + , "2.41.1" + , "2.40.2" + , "2.39.4" + ] diff --git a/Git/Version.hs b/Git/Version.hs index 9119f5dac8..0e31dce8eb 100644 --- a/Git/Version.hs +++ b/Git/Version.hs @@ -29,4 +29,4 @@ installed = normalize . extract <$> readProcess "git" ["--version"] older :: String -> IO Bool older n = do v <- installed - return $ v < normalize n + return $ v < normalize n diff --git a/doc/todo/deal_with_git_fsck_symlinkPointsToGitDir.mdwn b/doc/todo/deal_with_git_fsck_symlinkPointsToGitDir.mdwn index 454c3ece28..9c2f2e0a06 100644 --- a/doc/todo/deal_with_git_fsck_symlinkPointsToGitDir.mdwn +++ b/doc/todo/deal_with_git_fsck_symlinkPointsToGitDir.mdwn @@ -40,10 +40,3 @@ If git-annex wanted to also avoid this breakage, it could set: git config fsck.symlinkTargetLength ignore git config receive.fsck.symlinkTargetLength ignore git config fetch.fsck.symlinkTargetLength ignore - ----- - -Also this version of git added checks for hooks created at clone -time, which breaks git clone using git-remote-annex when the special -remote contains a git-annex branch. This is similar to how it broke git-lfs -and I'm sure this part of the breakage will be reverted.