summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
Diffstat (limited to 'Command')
-rw-r--r--Command/PreCommit.hs24
-rw-r--r--Command/Sync.hs32
2 files changed, 25 insertions, 31 deletions
diff --git a/Command/PreCommit.hs b/Command/PreCommit.hs
index f10ac628e..eed2f491c 100644
--- a/Command/PreCommit.hs
+++ b/Command/PreCommit.hs
@@ -11,12 +11,7 @@ import Common.Annex
import Command
import qualified Command.Add
import qualified Command.Fix
-import qualified Git.DiffTree
-import qualified Git.Ref
-import Annex.CatFile
-import Annex.Content.Direct
-import Git.Sha
-import Git.FilePath
+import Annex.Direct
def :: [Command]
def = [command "pre-commit" paramPaths seek SectionPlumbing
@@ -39,19 +34,4 @@ startIndirect file = next $ do
next $ return True
startDirect :: [String] -> CommandStart
-startDirect _ = next $ do
- (diffs, clean) <- inRepo $ Git.DiffTree.diffIndex Git.Ref.headRef
- makeabs <- flip fromTopFilePath <$> gitRepo
- forM_ diffs (go makeabs)
- next $ liftIO clean
- where
- go makeabs diff = do
- withkey (Git.DiffTree.srcsha diff) (Git.DiffTree.srcmode diff) removeAssociatedFile
- withkey (Git.DiffTree.dstsha diff) (Git.DiffTree.dstmode diff) addAssociatedFile
- where
- withkey sha mode a = when (sha /= nullSha) $ do
- k <- catKey sha mode
- case k of
- Nothing -> noop
- Just key -> void $ a key $
- makeabs $ Git.DiffTree.file diff
+startDirect _ = next $ next $ preCommitDirect
diff --git a/Command/Sync.hs b/Command/Sync.hs
index c41f46f8a..14c79e99d 100644
--- a/Command/Sync.hs
+++ b/Command/Sync.hs
@@ -103,19 +103,33 @@ syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
commit :: CommandStart
commit = next $ next $ ifM isDirect
( do
+ showStart "commit" ""
void stageDirect
- runcommit []
- , runcommit [Param "-a"]
- )
- where
- runcommit ps = do
+ void preCommitDirect
+ commitStaged commitmessage
+ , do
showStart "commit" ""
- showOutput
Annex.Branch.commit "update"
-- Commit will fail when the tree is clean, so ignore failure.
- let params = Param "commit" : ps ++
- [Param "-m", Param "git-annex automatic sync"]
- _ <- inRepo $ tryIO . Git.Command.runQuiet params
+ _ <- inRepo $ tryIO . Git.Command.runQuiet
+ [ Param "commit"
+ , Param "-a"
+ , Param "-m"
+ , Param commitmessage
+ ]
+ return True
+ )
+ where
+ commitmessage = "git-annex automatic sync"
+
+commitStaged :: String -> Annex Bool
+commitStaged commitmessage = go =<< inRepo Git.Branch.currentUnsafe
+ where
+ go Nothing = return False
+ go (Just branch) = do
+ parent <- inRepo $ Git.Ref.sha branch
+ void $ inRepo $ Git.Branch.commit False commitmessage branch
+ (maybe [] (:[]) parent)
return True
mergeLocal :: Maybe Git.Ref -> CommandStart