improve smudge --clean behavior on outside work tree files

smudge: When passed a file located outside the working tree, eg by git
diff, avoid erroring out.

This commit was sponsored by Ewen McNeill on Patreon.
This commit is contained in:
Joey Hess 2018-11-15 13:04:40 -04:00
parent ac27c29490
commit 71cc9cfaa2
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 20 additions and 5 deletions

View file

@ -14,6 +14,8 @@ git-annex (7.20181106) UNRELEASED; urgency=medium
be clearer about what the problem is and how to resolve it.
* export, sync --content: Avoid unnecessarily trying to upload files
to an exporttree remote that already contains the files.
* smudge: When passed a file located outside the working tree, eg by git
diff, avoid erroring out.
-- Joey Hess <id@joeyh.name> Tue, 06 Nov 2018 12:44:27 -0400

View file

@ -18,6 +18,7 @@ import Logs.Location
import qualified Database.Keys
import qualified Git.BuildVersion
import Git.FilePath
import qualified Git
import qualified Git.Ref
import Backend
@ -77,11 +78,14 @@ smudge file = do
clean :: FilePath -> CommandStart
clean file = do
b <- liftIO $ B.hGetContents stdin
case parseLinkOrPointer b of
Just k -> do
getMoveRaceRecovery k file
liftIO $ B.hPut stdout b
Nothing -> go b =<< catKeyFile file
ifM fileoutsiderepo
( liftIO $ B.hPut stdout b
, case parseLinkOrPointer b of
Just k -> do
getMoveRaceRecovery k file
liftIO $ B.hPut stdout b
Nothing -> go b =<< catKeyFile file
)
stop
where
go b oldkey = ifM (shouldAnnex file oldkey)
@ -130,6 +134,13 @@ clean file = do
, hardlinkFileTmp = False
}
-- git diff can run the clean filter on files outside the
-- repository; can't annex those
fileoutsiderepo = do
repopath <- liftIO . absPath =<< fromRepo Git.repoPath
filepath <- liftIO $ absPath file
return $ not $ dirContains repopath filepath
-- New files are annexed as configured by annex.largefiles, with a default
-- of annexing them.
--

View file

@ -22,3 +22,5 @@ $ git diff ../file1.txt ../file2.txt
### What version of git-annex are you using? On what operating system?
6.20180913-1~bpo9+1 on Debian Stretch + backports.
> [[fixed|done]] --[[Joey]]