@@ -33,15 +33,15 @@ import System.Console.CmdArgs (
33
33
typ ,
34
34
(&=) ,
35
35
)
36
- import System.Directory (doesDirectoryExist , listDirectory )
36
+ import System.Directory (doesDirectoryExist , listDirectory , renameFile )
37
37
import System.Exit (ExitCode (.. ), exitFailure , exitSuccess )
38
38
import System.FilePath ((</>) )
39
- import System.IO (IOMode ( WriteMode ), hPutStrLn , hSetEncoding , stderr , withFile )
39
+ import System.IO (hPutStrLn , hSetEncoding , stderr )
40
40
import System.IO.Atomic (withOutputFile )
41
41
import System.IO.Utf8 (readFileUtf8 , withUtf8StdHandles )
42
42
import System.Posix.Process (exitImmediately )
43
43
import System.Posix.Signals (Handler (.. ), installHandler , keyboardSignal )
44
- import System.Process (CreateProcess ( std_out ), StdStream ( UseHandle ), proc , waitForProcess , withCreateProcess )
44
+ import System.Process (callProcess )
45
45
46
46
type Result = Either String ()
47
47
@@ -221,20 +221,13 @@ mergeToolJob opts@Nixfmt{files = [base, local, remote, merged]} = runExceptT $ d
221
221
<$> formatTarget formatter (fileTarget path)
222
222
)
223
223
224
- exitCode <- lift $ withFile merged WriteMode $ \ out -> do
225
- withCreateProcess
226
- (proc " git" [" merge-file" , " --stdout" , local, base, remote])
227
- { std_out = UseHandle out
228
- }
229
- $ \ _ _ _ -> waitForProcess
224
+ lift $ callProcess " git" [" merge-file" , local, base, remote]
225
+ -- git merge-file writes the result to the local version
230
226
231
- case exitCode of
232
- ExitFailure code -> do
233
- output <- lift $ readFile merged
234
- throwE $ output <> " `git merge-file` failed with exit code " <> show code <> " \n "
235
- ExitSuccess -> return ()
227
+ ExceptT $ formatTarget formatter (fileTarget local)
236
228
237
- ExceptT $ formatTarget formatter (fileTarget merged)
229
+ -- Atomic move at the end
230
+ lift $ renameFile local merged
238
231
mergeToolJob _ = return $ Left " --mergetool mode expects exactly 4 file arguments ($BASE, $LOCAL, $REMOTE, $MERGED)"
239
232
240
233
toJobs :: Nixfmt -> IO [IO Result ]
0 commit comments