add --include-dotfiles: New option, perhaps useful for backups.

This commit is contained in:
Joey Hess 2014-03-26 14:52:07 -04:00
parent 6038875ebe
commit 2f538dd65c
6 changed files with 36 additions and 16 deletions

View file

@ -30,14 +30,15 @@ withFilesInGit :: (FilePath -> CommandStart) -> CommandSeek
withFilesInGit a params = seekActions $ prepFiltered a $
seekHelper LsFiles.inRepo params
withFilesNotInGit :: (FilePath -> CommandStart) -> CommandSeek
withFilesNotInGit a params = do
{- dotfiles are not acted on unless explicitly listed -}
files <- filter (not . dotfile) <$>
seekunless (null ps && not (null params)) ps
dotfiles <- seekunless (null dotps) dotps
seekActions $ prepFiltered a $
return $ concat $ segmentPaths params (files++dotfiles)
withFilesNotInGit :: Bool -> (FilePath -> CommandStart) -> CommandSeek
withFilesNotInGit skipdotfiles a params
| skipdotfiles = do
{- dotfiles are not acted on unless explicitly listed -}
files <- filter (not . dotfile) <$>
seekunless (null ps && not (null params)) ps
dotfiles <- seekunless (null dotps) dotps
go (files++dotfiles)
| otherwise = go =<< seekunless False params
where
(dotps, ps) = partition dotfile params
seekunless True _ = return []
@ -45,6 +46,8 @@ withFilesNotInGit a params = do
force <- Annex.getState Annex.force
g <- gitRepo
liftIO $ Git.Command.leaveZombie <$> LsFiles.notInRepo force l g
go l = seekActions $ prepFiltered a $
return $ concat $ segmentPaths params l
withPathContents :: ((FilePath, FilePath) -> CommandStart) -> CommandSeek
withPathContents a params = seekActions $

View file

@ -34,8 +34,12 @@ import Annex.ReplaceFile
import Utility.Tmp
def :: [Command]
def = [notBareRepo $ command "add" paramPaths seek SectionCommon
"add files to annex"]
def = [notBareRepo $ withOptions [includeDotFilesOption] $
command "add" paramPaths seek SectionCommon
"add files to annex"]
includeDotFilesOption :: Option
includeDotFilesOption = flagOption [] "include-dotfiles" "don't skip dotfiles"
{- Add acts on both files not checked into git yet, and unlocked files.
-
@ -47,7 +51,8 @@ seek ps = do
( start file
, stop
)
go withFilesNotInGit
skipdotfiles <- not <$> Annex.getFlag (optionName includeDotFilesOption)
go $ withFilesNotInGit skipdotfiles
ifM isDirect
( go withFilesMaybeModified
, go withFilesUnlocked

View file

@ -36,7 +36,7 @@ check = do
seek :: CommandSeek
seek ps = do
withFilesNotInGit (whenAnnexed startCheckIncomplete) ps
withFilesNotInGit False (whenAnnexed startCheckIncomplete) ps
withFilesInGit (whenAnnexed Command.Unannex.start) ps
finish

1
debian/changelog vendored
View file

@ -19,6 +19,7 @@ git-annex (5.20140321) UNRELEASED; urgency=medium
a remote git repository, as long as a git-annex branch has
been pushed to it, to simplify setup of remote git repositories,
including via gitolite.
* add --include-dotfiles: New option, perhaps useful for backups.
-- Joey Hess <joeyh@debian.org> Fri, 21 Mar 2014 14:08:41 -0400

View file

@ -5,3 +5,10 @@ AFAICT there's no way to tell git annex add to add all dotfiles in a given direc
This can be worked around with find and xargs, but this is more work than it should be, I think.
It might also be nice if git annex add displayed a warning when adding a directory with dotfiles; something like "Warning, N files ignored; pass --whatever to add them."
> [[!commit 34abd7bca80a8cc012f92d64116014449b1b2392]] explains
> the rationalle for dotfiles to be skipped. Such as it was.
>
> I don't think it makes sense for --force to be the flag to override
> this, because you may want to add dotfiles, but not .gitignored
> files. So, made a new --include-dotfiles option. [[done]] --[[Joey]]

View file

@ -62,10 +62,14 @@ subdirectories).
* `add [path ...]`
Adds files in the path to the annex. Files that are already checked into
git, or that git has been configured to ignore will be silently skipped.
(Use `--force` to add ignored files.) Dotfiles are skipped unless explicitly
listed.
Adds files in the path to the annex. If no path is specified, adds
files from the current directory and below.
Files that are already checked into git, or that git has been configured
to ignore will be silently skipped. (Use `--force` to add ignored files.)
Dotfiles are skipped unless explicitly listed, or the --include-dotfiles
option is used.
* `get [path ...]`