From bb7571aeb4d4cd4920a7fe4b2538ce5a412f7603 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 12 Nov 2014 15:41:15 -0400 Subject: proxy: for all your direct mode repository munging needs This allows bypassing the direct mode guard in a safe way to do all sorts of things including git revert, git mv, git checkout ... This commit was sponsored by the WikiMedia Foundation. --- Annex/Direct.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'Annex/Direct.hs') diff --git a/Annex/Direct.hs b/Annex/Direct.hs index 9489b74f2..e4015dd16 100644 --- a/Annex/Direct.hs +++ b/Annex/Direct.hs @@ -225,9 +225,17 @@ mergeDirectCommit allowff old branch commitmode = do where canff = maybe (return False) (\o -> inRepo $ Git.Branch.fastForwardable o branch) old -{- Cleans up after a direct mode merge. The merge must have been staged - - in the index. Uses diff-index to compare the staged changes with - - the tree before the merge, and applies those changes to the work tree. +mergeDirectCleanup :: FilePath -> Git.Ref -> Annex () +mergeDirectCleanup d oldref = do + updateWorkTree d oldref + liftIO $ removeDirectoryRecursive d + +{- Updates the direct mode work tree to reflect the changes staged in the + - index by a git command, that was run in a temporary work tree. + - + - Uses diff-index to compare the staged changes with provided ref + - which should be the tree before the merge, and applies those + - changes to the work tree. - - There are really only two types of changes: An old item can be deleted, - or a new item added. Two passes are made, first deleting and then @@ -236,8 +244,8 @@ mergeDirectCommit allowff old branch commitmode = do - order, but we cannot add the directory until the file with the - same name is removed.) -} -mergeDirectCleanup :: FilePath -> Git.Ref -> Annex () -mergeDirectCleanup d oldref = do +updateWorkTree :: FilePath -> Git.Ref -> Annex () +updateWorkTree d oldref = do (items, cleanup) <- inRepo $ DiffTree.diffIndex oldref makeabs <- flip fromTopFilePath <$> gitRepo let fsitems = zip (map (makeabs . DiffTree.file) items) items @@ -246,7 +254,6 @@ mergeDirectCleanup d oldref = do forM_ fsitems $ go makeabs DiffTree.dstsha DiffTree.dstmode movein movein_raw void $ liftIO cleanup - liftIO $ removeDirectoryRecursive d where go makeabs getsha getmode a araw (f, item) | getsha item == nullSha = noop -- cgit v1.2.3