summaryrefslogtreecommitdiff
path: root/Command/Unannex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-09 13:07:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-09 13:07:31 -0400
commit14e9b87d44831fe0b6510422ffb4266f253496d7 (patch)
treeebcd80e5e838a88b40f043e8b82eddd8c3109d13 /Command/Unannex.hs
parent3f5f28b48754bc91620a6354ca70afe4c61c9894 (diff)
unannex improvements
Added files don't have to be committed before they can be unannexed. unannex no longer commits existing staged changes unannex of the last file in a directory now works, before it failed because git rm deleted the directory out from under it,
Diffstat (limited to 'Command/Unannex.hs')
-rw-r--r--Command/Unannex.hs30
1 files changed, 12 insertions, 18 deletions
diff --git a/Command/Unannex.hs b/Command/Unannex.hs
index 263ff88b4..aafc189d0 100644
--- a/Command/Unannex.hs
+++ b/Command/Unannex.hs
@@ -23,17 +23,8 @@ def = [command "unannex" paramPaths seek "undo accidential add command"]
seek :: [CommandSeek]
seek = [withFilesInGit $ whenAnnexed start]
-{- The unannex subcommand undoes an add. -}
start :: FilePath -> (Key, Backend Annex) -> CommandStart
start file (key, _) = stopUnless (inAnnex key) $ do
- force <- Annex.getState Annex.force
- unless force $ do
- top <- fromRepo Git.workTree
- staged <- inRepo $ LsFiles.staged [top]
- unless (null staged) $
- error "This command cannot be run when there are already files staged for commit."
- Annex.changeState $ \s -> s { Annex.force = True }
-
showStart "unannex" file
next $ perform file key
@@ -43,9 +34,17 @@ perform file key = next $ cleanup file key
cleanup :: FilePath -> Key -> CommandCleanup
cleanup file key = do
liftIO $ removeFile file
- inRepo $ Git.run "rm" [Params "--quiet --", File file]
- -- git rm deletes empty directories; put them back
- liftIO $ createDirectoryIfMissing True (parentDir file)
+ -- git rm deletes empty directory without --cached
+ inRepo $ Git.run "rm" [Params "--cached --quiet --", File file]
+
+ -- If the file was already committed, it is now staged for removal.
+ -- Commit that removal now, to avoid later confusing the
+ -- pre-commit hook if this file is later added back to
+ -- git as a normal, non-annexed file.
+ whenM (not . null <$> inRepo (LsFiles.staged [file])) $ do
+ inRepo $ Git.run "commit" [
+ Param "-m", Param "content removed from git annex",
+ Param "--", File file]
fast <- Annex.getState Annex.fast
if fast
@@ -58,10 +57,5 @@ cleanup file key = do
else do
fromAnnex key file
logStatus key InfoMissing
-
- -- Commit staged changes at end to avoid confusing the
- -- pre-commit hook if this file is later added back to
- -- git as a normal, non-annexed file.
- Annex.Queue.add "commit" [Param "-m", Param "content removed from git annex"] []
-
+
return True