check whether the remote tracking branch exists
This commit is contained in:
parent
eaa791cf2f
commit
e2c3102cc4
@ -101,16 +101,26 @@ checkRemoteSynced = do
|
|||||||
(_, _, _, pr) <- createProcess (shell "git fetch")
|
(_, _, _, pr) <- createProcess (shell "git fetch")
|
||||||
waitForProcess pr
|
waitForProcess pr
|
||||||
localHash <- runCommand "git rev-parse HEAD"
|
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
|
remoteHash <- runCommand $ "git rev-parse " ++ remoteTrackingBranch
|
||||||
if localHash == remoteHash then
|
if localHash == remoteHash then
|
||||||
return ()
|
return ()
|
||||||
else
|
else
|
||||||
failWith "Changes are not merged with remote branch."
|
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 :: IO String
|
||||||
getCurrentBranch = runCommand "git rev-parse --abbrev-ref HEAD"
|
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 :: String -> IO String
|
||||||
getRemoteUrl remote = runCommand $ "git config --get remote." ++ remote ++ ".url"
|
getRemoteUrl remote = runCommand $ "git config --get remote." ++ remote ++ ".url"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user