From 75591eb2e8ebd08362d91e42038098db852333eb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Nov 2014 15:43:00 -0400 Subject: avoid pulling when there is no origin --- src/Propellor/CmdLine.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index 2d4ae403..c79b2592 100644 --- a/src/Propellor/CmdLine.hs +++ b/src/Propellor/CmdLine.hs @@ -142,7 +142,10 @@ getCurrentBranch = takeWhile (/= '\n') <$> readProcess "git" ["symbolic-ref", "--short", "HEAD"] updateFirst :: CmdLine -> IO () -> IO () -updateFirst cmdline next = do +updateFirst cmdline next = ifM hasOrigin (updateFirst' cmdline next, next) + +updateFirst' :: CmdLine -> IO () -> IO () +updateFirst' cmdline next = do branchref <- getCurrentBranch let originbranch = "origin" branchref @@ -319,11 +322,15 @@ gitPush hin hout = void $ fromstdin `concurrently` tostdout h <- fdToHandle hout B.hGetContents h >>= B.putStr +hasOrigin :: IO Bool +hasOrigin = do + rs <- lines <$> readProcess "git" ["remote"] + return $ "origin" `elem` rs + setRepoUrl :: String -> IO () setRepoUrl "" = return () setRepoUrl url = do - rs <- lines <$> readProcess "git" ["remote"] - let subcmd = if "origin" `elem` rs then "set-url" else "add" + subcmd <- ifM hasOrigin (pure "set-url", pure "add") void $ boolSystem "git" [Param "remote", Param subcmd, Param "origin", Param url] -- same as --set-upstream-to, except origin branch -- may not have been pulled yet -- cgit v1.2.3