From bf933867dce7211e116ef27cad7c7fa7bf49f648 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 25 Feb 2014 12:48:04 -0400 Subject: handle swap with self case --- Git/Destroyer.hs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Git/Destroyer.hs b/Git/Destroyer.hs index a84bc60..57d8ad5 100644 --- a/Git/Destroyer.hs +++ b/Git/Destroyer.hs @@ -60,7 +60,7 @@ instance Arbitrary Damage where - are enumerated, sorted, and this is used as an index - into the list. (Wrapping around if higher than the length.) -} data FileSelector = FileSelector Int - deriving (Read, Show) + deriving (Read, Show, Eq) instance Arbitrary FileSelector where arbitrary = FileSelector <$> oneof @@ -129,13 +129,15 @@ applyDamage ds r = do ScrambleFileMode s mode -> withfile s $ \f -> setFileMode f mode - SwapFiles a b -> - withfile a $ \fa -> - withfile b $ \fb -> - withTmpFile "swap" $ \tmp _ -> do - moveFile fa tmp - moveFile fb fa - moveFile tmp fa + SwapFiles a b + | a == b -> noop + | otherwise -> + withfile a $ \fa -> + withfile b $ \fb -> + withTmpFile "swap" $ \tmp _ -> do + moveFile fa tmp + moveFile fb fa + moveFile tmp fa where -- A broken .git/config is not recoverable. skipped f = f `elem` [ "config" ] -- cgit v1.2.3