add warning on add of annex link
Warn when adding a annex symlink or pointer file that uses a key that is not known to the repository, to prevent confusion if the user has copied it from some other repository. This commit was sponsored by Jake Vosloo on Patreon.
This commit is contained in:
parent
9e8eae20e2
commit
92b7b1964d
5 changed files with 36 additions and 14 deletions
|
@ -21,6 +21,7 @@ module Annex.Ingest (
|
||||||
CheckGitIgnore(..),
|
CheckGitIgnore(..),
|
||||||
gitAddParams,
|
gitAddParams,
|
||||||
addAnnexedFile,
|
addAnnexedFile,
|
||||||
|
addingExistingLink,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Annex.Common
|
import Annex.Common
|
||||||
|
@ -387,3 +388,19 @@ addAnnexedFile ci matcher file key mtmp = ifM (addUnlocked matcher mi)
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
|
|
||||||
writepointer mode = liftIO $ writePointerFile file key mode
|
writepointer mode = liftIO $ writePointerFile file key mode
|
||||||
|
|
||||||
|
{- Use with actions that add an already existing annex symlink or pointer
|
||||||
|
- file. The warning avoids a confusing situation where the file got copied
|
||||||
|
- from another git-annex repo, probably by accident. -}
|
||||||
|
addingExistingLink :: RawFilePath -> Key -> Annex a -> Annex a
|
||||||
|
addingExistingLink f k a = do
|
||||||
|
unlessM (isKnownKey k <||> inAnnex k) $ do
|
||||||
|
islink <- isJust <$> isAnnexLink f
|
||||||
|
warning $ unwords
|
||||||
|
[ fromRawFilePath f
|
||||||
|
, "is a git-annex"
|
||||||
|
, if islink then "symlink." else "pointer file."
|
||||||
|
, "Its content is not available in this repository."
|
||||||
|
, "(Maybe " ++ fromRawFilePath f ++ " was copied from another repository?)"
|
||||||
|
]
|
||||||
|
a
|
||||||
|
|
|
@ -3,6 +3,9 @@ git-annex (8.20201104) UNRELEASED; urgency=medium
|
||||||
* sync --content: Fix a bug where a file that was not preferred content
|
* sync --content: Fix a bug where a file that was not preferred content
|
||||||
could be transferred to a remote. This happened when the file got deleted
|
could be transferred to a remote. This happened when the file got deleted
|
||||||
after the sync started running.
|
after the sync started running.
|
||||||
|
* Warn when adding a annex symlink or pointer file that uses a key that
|
||||||
|
is not known to the repository, to prevent confusion if the user has
|
||||||
|
copied it from some other repository.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Mon, 09 Nov 2020 15:15:20 -0400
|
-- Joey Hess <id@joeyh.name> Mon, 09 Nov 2020 15:15:20 -0400
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,6 @@ import Utility.FileMode
|
||||||
import Utility.OptParse
|
import Utility.OptParse
|
||||||
import qualified Utility.RawFilePath as R
|
import qualified Utility.RawFilePath as R
|
||||||
|
|
||||||
import System.Log.Logger (debugM)
|
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = notBareRepo $
|
cmd = notBareRepo $
|
||||||
withGlobalOptions opts $
|
withGlobalOptions opts $
|
||||||
|
@ -171,16 +169,17 @@ start o si file addunlockedmatcher = do
|
||||||
liftIO (catchMaybeIO $ R.getSymbolicLinkStatus file) >>= \case
|
liftIO (catchMaybeIO $ R.getSymbolicLinkStatus file) >>= \case
|
||||||
Just s | isSymbolicLink s -> fixuplink key
|
Just s | isSymbolicLink s -> fixuplink key
|
||||||
_ -> add
|
_ -> add
|
||||||
fixuplink key = starting "add" (ActionItemWorkTreeFile file) si $ do
|
fixuplink key =
|
||||||
liftIO $ debugM "add" "adding existing annex symlink to git"
|
starting "add" (ActionItemWorkTreeFile file) si $
|
||||||
liftIO $ removeFile (fromRawFilePath file)
|
addingExistingLink file key $ do
|
||||||
addLink (checkGitIgnoreOption o) file key Nothing
|
liftIO $ removeFile (fromRawFilePath file)
|
||||||
next $
|
addLink (checkGitIgnoreOption o) file key Nothing
|
||||||
cleanup key =<< inAnnex key
|
next $ cleanup key =<< inAnnex key
|
||||||
fixuppointer key = starting "add" (ActionItemWorkTreeFile file) si $ do
|
fixuppointer key =
|
||||||
liftIO $ debugM "add" "adding pointer file to git"
|
starting "add" (ActionItemWorkTreeFile file) si $
|
||||||
Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath file)
|
addingExistingLink file key $ do
|
||||||
next $ addFile (checkGitIgnoreOption o) file
|
Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath file)
|
||||||
|
next $ addFile (checkGitIgnoreOption o) file
|
||||||
|
|
||||||
perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
|
perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
|
||||||
perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
|
perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
|
||||||
|
|
|
@ -98,8 +98,9 @@ clean file = do
|
||||||
where
|
where
|
||||||
go b = case parseLinkTargetOrPointerLazy b of
|
go b = case parseLinkTargetOrPointerLazy b of
|
||||||
Just k -> do
|
Just k -> do
|
||||||
getMoveRaceRecovery k file
|
addingExistingLink file k $ do
|
||||||
liftIO $ L.hPut stdout b
|
getMoveRaceRecovery k file
|
||||||
|
liftIO $ L.hPut stdout b
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
let fileref = Git.Ref.fileRef file
|
let fileref = Git.Ref.fileRef file
|
||||||
indexmeta <- catObjectMetaData fileref
|
indexmeta <- catObjectMetaData fileref
|
||||||
|
|
|
@ -219,3 +219,5 @@ $ tree -a
|
||||||
|
|
||||||
### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
|
### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
|
||||||
It used to work before. It seem to be broken since a system update. I have tried reinstalling `git-annex` as well as all dependencies, bit without any luck.
|
It used to work before. It seem to be broken since a system update. I have tried reinstalling `git-annex` as well as all dependencies, bit without any luck.
|
||||||
|
|
||||||
|
> Added warning. [[done]] --[[Joey]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue