summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-10 13:05:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-10 13:05:58 -0400
commit5308b51ec0dce12849d8f4e5bc3f0adf6bf09a5f (patch)
treebe332b496290570b48445c697472fa1e84a25803
parent7f39415600a808c7664520a435eb45cf8d82f7ce (diff)
stage deletions directly using update-index
no need to run git-rm separately
-rw-r--r--Command/Watch.hs11
-rw-r--r--Git/UpdateIndex.hs8
2 files changed, 16 insertions, 3 deletions
diff --git a/Command/Watch.hs b/Command/Watch.hs
index f9daa1a99..d50a581a1 100644
--- a/Command/Watch.hs
+++ b/Command/Watch.hs
@@ -123,11 +123,16 @@ onAddSymlink file = go =<< Backend.lookupFile file
{- The file could reappear at any time, so --cached is used, to only delete
- it from the index. -}
onDel :: FilePath -> Annex ()
-onDel file = Annex.Queue.addCommand "rm"
- [Params "--quiet --cached --ignore-unmatch --"] [file]
+onDel file = Annex.Queue.addUpdateIndex =<<
+ inRepo (Git.UpdateIndex.unstageFile file)
{- A directory has been deleted, or moved, so tell git to remove anything
- - that was inside it from its cache. -}
+ - that was inside it from its cache. Since it could reappear at any time,
+ - use --cached to only delete it from the index.
+ -
+ - Note: This could use unstageFile, but would need to run another git
+ - command to get the recursive list of files in the directory, so rm is
+ - just as good. -}
onDelDir :: FilePath -> Annex ()
onDelDir dir = Annex.Queue.addCommand "rm"
[Params "--quiet -r --cached --ignore-unmatch --"] [dir]
diff --git a/Git/UpdateIndex.hs b/Git/UpdateIndex.hs
index faffeec66..07057ed98 100644
--- a/Git/UpdateIndex.hs
+++ b/Git/UpdateIndex.hs
@@ -13,6 +13,7 @@ module Git.UpdateIndex (
streamUpdateIndex,
lsTree,
updateIndexLine,
+ unstageFile,
stageSymlink
) where
@@ -24,6 +25,7 @@ import Git.Types
import Git.Command
import Git.FilePath
import Git.HashObject
+import Git.Sha
{- Streamers are passed a callback and should feed it lines in the form
- read by update-index, and generated by ls-tree. -}
@@ -61,6 +63,12 @@ updateIndexLine :: Sha -> BlobType -> TopFilePath -> String
updateIndexLine sha filetype file =
show filetype ++ " blob " ++ show sha ++ "\t" ++ getTopFilePath file
+{- A streamer that removes a file from the index. -}
+unstageFile :: FilePath -> Repo -> IO Streamer
+unstageFile file repo = do
+ p <- toTopFilePath file repo
+ return $ pureStreamer $ "0 " ++ show nullSha ++ "\t" ++ getTopFilePath p
+
{- A streamer that adds a symlink to the index. -}
stageSymlink :: FilePath -> String -> Repo -> IO Streamer
stageSymlink file linktext repo = do