Added --no-check-gitignore option for finer grained control than using --force.
add, addurl, importfeed, import: Added --no-check-gitignore option for finer grained control than using --force. (--force is used for too many different things, and at least one of these also uses it for something else. I would like to reduce --force's footprint until it only forces drops or a few other data losses. For now, --force still disables checking ignores too.) addunused: Don't check .gitignores when adding files. This is a behavior change, but I justify it by analogy with git add of a gitignored file adding it, asking to add all unused files back should add them all back, not skip some. The old behavior was surprising. In Command.Lock and Command.ReKey, CheckGitIgnore False does not change behavior, it only makes explicit what is done. Since these commands are run on annexed files, the file is already checked into git, so git add won't check ignores.
This commit is contained in:
parent
500454935f
commit
d0b06c17c0
15 changed files with 140 additions and 89 deletions
|
@ -24,6 +24,7 @@ import Git.FilePath
|
|||
import Config.GitConfig
|
||||
import qualified Git.UpdateIndex
|
||||
import Utility.FileMode
|
||||
import Utility.OptParse
|
||||
import qualified Utility.RawFilePath as R
|
||||
|
||||
cmd :: Command
|
||||
|
@ -37,6 +38,7 @@ data AddOptions = AddOptions
|
|||
, batchOption :: BatchMode
|
||||
, updateOnly :: Bool
|
||||
, largeFilesOverride :: Maybe Bool
|
||||
, checkGitIgnoreOption :: CheckGitIgnore
|
||||
}
|
||||
|
||||
optParser :: CmdParamsDesc -> Parser AddOptions
|
||||
|
@ -49,6 +51,7 @@ optParser desc = AddOptions
|
|||
<> help "only update tracked files"
|
||||
)
|
||||
<*> (parseforcelarge <|> parseforcesmall)
|
||||
<*> checkGitIgnoreSwitch
|
||||
where
|
||||
parseforcelarge = flag Nothing (Just True)
|
||||
( long "force-large"
|
||||
|
@ -59,6 +62,11 @@ optParser desc = AddOptions
|
|||
<> help "add all files to git, ignoring other configuration"
|
||||
)
|
||||
|
||||
checkGitIgnoreSwitch :: Parser CheckGitIgnore
|
||||
checkGitIgnoreSwitch = CheckGitIgnore <$>
|
||||
invertableSwitch "check-gitignore" True
|
||||
(help "Do not check .gitignore when adding files")
|
||||
|
||||
seek :: AddOptions -> CommandSeek
|
||||
seek o = startConcurrency commandStages $ do
|
||||
largematcher <- largeFilesMatcher
|
||||
|
@ -68,14 +76,14 @@ seek o = startConcurrency commandStages $ do
|
|||
Nothing ->
|
||||
let file' = fromRawFilePath file
|
||||
in ifM (pure (annexdotfiles || not (dotfile file')) <&&> (checkFileMatcher largematcher file' <||> Annex.getState Annex.force))
|
||||
( start si file addunlockedmatcher
|
||||
( start o si file addunlockedmatcher
|
||||
, ifM (annexAddSmallFiles <$> Annex.getGitConfig)
|
||||
( startSmall si file
|
||||
( startSmall o si file
|
||||
, stop
|
||||
)
|
||||
)
|
||||
Just True -> start si file addunlockedmatcher
|
||||
Just False -> startSmallOverridden si file
|
||||
Just True -> start o si file addunlockedmatcher
|
||||
Just False -> startSmallOverridden o si file
|
||||
case batchOption o of
|
||||
Batch fmt
|
||||
| updateOnly o ->
|
||||
|
@ -95,26 +103,28 @@ seek o = startConcurrency commandStages $ do
|
|||
go withUnmodifiedUnlockedPointers
|
||||
|
||||
{- Pass file off to git-add. -}
|
||||
startSmall :: SeekInput -> RawFilePath -> CommandStart
|
||||
startSmall si file = starting "add" (ActionItemWorkTreeFile file) si $
|
||||
next $ addSmall file
|
||||
startSmall :: AddOptions -> SeekInput -> RawFilePath -> CommandStart
|
||||
startSmall o si file =
|
||||
starting "add" (ActionItemWorkTreeFile file) si $
|
||||
next $ addSmall (checkGitIgnoreOption o) file
|
||||
|
||||
addSmall :: RawFilePath -> Annex Bool
|
||||
addSmall file = do
|
||||
addSmall :: CheckGitIgnore -> RawFilePath -> Annex Bool
|
||||
addSmall ci file = do
|
||||
showNote "non-large file; adding content to git repository"
|
||||
addFile file
|
||||
addFile ci file
|
||||
|
||||
startSmallOverridden :: SeekInput -> RawFilePath -> CommandStart
|
||||
startSmallOverridden si file = starting "add" (ActionItemWorkTreeFile file) si $
|
||||
next $ addSmallOverridden file
|
||||
startSmallOverridden :: AddOptions -> SeekInput -> RawFilePath -> CommandStart
|
||||
startSmallOverridden o si file =
|
||||
starting "add" (ActionItemWorkTreeFile file) si $
|
||||
next $ addSmallOverridden o file
|
||||
|
||||
addSmallOverridden :: RawFilePath -> Annex Bool
|
||||
addSmallOverridden file = do
|
||||
addSmallOverridden :: AddOptions -> RawFilePath -> Annex Bool
|
||||
addSmallOverridden o file = do
|
||||
showNote "adding content to git repository"
|
||||
let file' = fromRawFilePath file
|
||||
s <- liftIO $ getSymbolicLinkStatus file'
|
||||
if not (isRegularFile s)
|
||||
then addFile file
|
||||
then addFile (checkGitIgnoreOption o) file
|
||||
else do
|
||||
-- Can't use addFile because the clean filter will
|
||||
-- honor annex.largefiles and it has been overridden.
|
||||
|
@ -127,14 +137,14 @@ addSmallOverridden file = do
|
|||
inRepo (Git.UpdateIndex.stageFile sha ty file')
|
||||
return True
|
||||
|
||||
addFile :: RawFilePath -> Annex Bool
|
||||
addFile file = do
|
||||
ps <- forceParams
|
||||
addFile :: CheckGitIgnore -> RawFilePath -> Annex Bool
|
||||
addFile ci file = do
|
||||
ps <- gitAddParams ci
|
||||
Annex.Queue.addCommand "add" (ps++[Param "--"]) [fromRawFilePath file]
|
||||
return True
|
||||
|
||||
start :: SeekInput -> RawFilePath -> AddUnlockedMatcher -> CommandStart
|
||||
start si file addunlockedmatcher = do
|
||||
start :: AddOptions -> SeekInput -> RawFilePath -> AddUnlockedMatcher -> CommandStart
|
||||
start o si file addunlockedmatcher = do
|
||||
mk <- liftIO $ isPointerFile file
|
||||
maybe go fixuppointer mk
|
||||
where
|
||||
|
@ -146,8 +156,8 @@ start si file addunlockedmatcher = do
|
|||
| otherwise ->
|
||||
starting "add" (ActionItemWorkTreeFile file) si $
|
||||
if isSymbolicLink s
|
||||
then next $ addFile file
|
||||
else perform file addunlockedmatcher
|
||||
then next $ addFile (checkGitIgnoreOption o) file
|
||||
else perform o file addunlockedmatcher
|
||||
addpresent key =
|
||||
liftIO (catchMaybeIO $ R.getSymbolicLinkStatus file) >>= \case
|
||||
Just s | isSymbolicLink s -> fixuplink key
|
||||
|
@ -155,16 +165,16 @@ start si file addunlockedmatcher = do
|
|||
fixuplink key = starting "add" (ActionItemWorkTreeFile file) si $ do
|
||||
-- the annexed symlink is present but not yet added to git
|
||||
liftIO $ removeFile (fromRawFilePath file)
|
||||
addLink (fromRawFilePath file) key Nothing
|
||||
addLink (checkGitIgnoreOption o) (fromRawFilePath file) key Nothing
|
||||
next $
|
||||
cleanup key =<< inAnnex key
|
||||
fixuppointer key = starting "add" (ActionItemWorkTreeFile file) si $ do
|
||||
-- the pointer file is present, but not yet added to git
|
||||
Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath file)
|
||||
next $ addFile file
|
||||
next $ addFile (checkGitIgnoreOption o) file
|
||||
|
||||
perform :: RawFilePath -> AddUnlockedMatcher -> CommandPerform
|
||||
perform file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
|
||||
perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
|
||||
perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
|
||||
lockingfile <- not <$> addUnlocked addunlockedmatcher
|
||||
(MatchingFile (FileInfo file file))
|
||||
let cfg = LockDownConfig
|
||||
|
@ -174,7 +184,7 @@ perform file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
|
|||
ld <- lockDown cfg (fromRawFilePath file)
|
||||
let sizer = keySource <$> ld
|
||||
v <- metered Nothing sizer $ \_meter meterupdate ->
|
||||
ingestAdd meterupdate ld
|
||||
ingestAdd (checkGitIgnoreOption o) meterupdate ld
|
||||
finish v
|
||||
where
|
||||
finish (Just key) = next $ cleanup key True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue