aboutsummaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs31
1 files changed, 24 insertions, 7 deletions
diff --git a/Main.hs b/Main.hs
index 6473ecc..fde7707 100644
--- a/Main.hs
+++ b/Main.hs
@@ -61,9 +61,22 @@ import System.IO (hPutStrLn, stderr)
import System.Posix.Signals (Handler(Catch), installHandler, sigINT)
import System.Process (rawSystem)
+data WatchType
+ = UpdateOnly
+ | Add
+ | AddAndRemove
+ deriving (Show, Eq, Ord)
+
+watchGitOption :: WatchType -> String
+watchGitOption x =
+ case x of
+ UpdateOnly -> "--update"
+ Add -> "--ignore-removal"
+ AddAndRemove -> "--no-ignore-removal"
+
data Watch = Watch
{ watchPath :: FilePath
- , watchWithRemoval :: Bool
+ , watchWithRemoval :: WatchType
} deriving (Show, Eq, Ord)
data Opts = Opts
@@ -101,13 +114,19 @@ opts = do
optWatches <-
some
$ asum
- [ fmap (`Watch` False) . strOption
+ [ fmap (`Watch` UpdateOnly) . strOption
+ ~~ [ short 'u'
+ , long "update"
+ , metavar "PATH"
+ , help "like `--add' but does not add new files"
+ ]
+ , fmap (`Watch` Add) . strOption
~~ [ short 'a'
, long "add"
, metavar "PATH"
, help "paths to auto-add"
]
- , fmap (`Watch` True) . strOption
+ , fmap (`Watch` AddAndRemove) . strOption
~~ [ short 'A'
, long "add-all"
, metavar "PATH"
@@ -228,11 +247,9 @@ mainLoop git dbg chan done o = loop
| not (S.null stWatch)
, stAddsPending == 1 {- protection against triggering too early -}
|| intervalPassed (optAddCommitDelay o) now stLastAdd = do
- for_ stWatch $ \w@(Watch p addAll) -> do
+ for_ stWatch $ \w@(Watch p wtype) -> do
dbg $ "will add: " ++ show w
- if addAll
- then runCmd git ["add", p]
- else runCmd git ["add", "--ignore-removal", p]
+ runCmd git ["add", watchGitOption wtype, p]
dbg "commit!"
runCmd git ["commit", "--message", mkMsg stCommitSeries $ optMsg o]
loop