check whether the remote tracking branch exists

This commit is contained in:
Filip Gralinski 2018-09-01 14:39:34 +02:00
parent eaa791cf2f
commit e2c3102cc4

View File

@ -101,16 +101,26 @@ checkRemoteSynced = do
(_, _, _, pr) <- createProcess (shell "git fetch")
waitForProcess pr
localHash <- runCommand "git rev-parse HEAD"
remoteTrackingBranch <- runCommand "git rev-parse --abbrev-ref --symbolic-full-name @{u}"
mRemoteTrackingBranch <- getRemoteTrackingBranch
case mRemoteTrackingBranch of
Just remoteTrackingBranch -> do
remoteHash <- runCommand $ "git rev-parse " ++ remoteTrackingBranch
if localHash == remoteHash then
return ()
else
failWith "Changes are not merged with remote branch."
Nothing -> failWith "No tracking branch found, use `git push -u origin BRANCH_NAME`"
getCurrentBranch :: IO String
getCurrentBranch = runCommand "git rev-parse --abbrev-ref HEAD"
getRemoteTrackingBranch :: IO (Maybe String)
getRemoteTrackingBranch = do
(code, content, _) <- readCreateProcessWithExitCode (shell "git rev-parse --abbrev-ref --symbolic-full-name @{u}") ""
case code of
ExitSuccess -> return $ Just $ takeWhile (/= '\n') content
ExitFailure _ -> return Nothing
getRemoteUrl :: String -> IO String
getRemoteUrl remote = runCommand $ "git config --get remote." ++ remote ++ ".url"