@@ -158,16 +158,16 @@ getNixSha256ForUriUnpacked
159 -> m NixSha256
159 -> m NixSha256
160getNixSha256ForUriUnpacked uri =
160getNixSha256ForUriUnpacked uri =
161− withExitFailMessage ("nix-prefetch-url: Failed to determine sha256 hash of URL " <> T.pack (show uri)) $ do
161+ withExitFailMessage ("nix-prefetch-url: Failed to determine sha256 hash of URL " <> render uri) $ do
162− withNixRemoteCheck $ readProcessAndLogStderr Debug $
162+ withNixRemoteCheck $ readProcessAndLogOutput (Debug, Debug) $
163− proc "nix-prefetch-url" ["--unpack" , "--type" , "sha256" , show uri]
163+ proc "nix-prefetch-url" ["--unpack" , "--type" , "sha256" , T.unpack $ render uri]
165nixPrefetchGit :: MonadObelisk m => URI -> Text -> Bool -> m NixSha256
165nixPrefetchGit :: MonadObelisk m => URI -> Text -> Bool -> m NixSha256
166nixPrefetchGit uri rev fetchSubmodules =
166nixPrefetchGit uri rev fetchSubmodules =
167− withExitFailMessage ("nix-prefetch-git: Failed to determine sha256 hash of Git repo " <> T.pack (show uri) <> " at " <> rev) $ do
167+ withExitFailMessage ("nix-prefetch-git: Failed to determine sha256 hash of Git repo " <> render uri <> " at " <> rev) $ do
168 out <- withNixRemoteCheck $ readProcessAndLogStderr Debug $
168 out <- withNixRemoteCheck $ readProcessAndLogStderr Debug $
169 proc "nix-prefetch-git" $ filter (/="")
169 proc "nix-prefetch-git" $ filter (/="")
170− [ "--url", show uri
170+ [ "--url", T.unpack $ render uri
171 , "--rev", T.unpack rev
171 , "--rev", T.unpack rev
172 , if fetchSubmodules then "--fetch-submodules" else ""
172 , if fetchSubmodules then "--fetch-submodules" else ""
173 , "--quiet"
173 , "--quiet"
@@ -578,7 +578,9 @@ unpackThunk' noTrail thunkDir = readThunk thunkDir >>= \case
578 withSpinner' ("Fetching thunk " <> T.pack thunkName)
578 withSpinner' ("Fetching thunk " <> T.pack thunkName)
579 (finalMsg noTrail $ const $ "Fetched thunk " <> T.pack thunkName) $ do
579 (finalMsg noTrail $ const $ "Fetched thunk " <> T.pack thunkName) $ do
580 let git = callProcessAndLogOutput (Notice, Notice) . gitProc tmpRepo
580 let git = callProcessAndLogOutput (Notice, Notice) . gitProc tmpRepo
581− git ["clone", if _gitSource_fetchSubmodules s then "--recursive" else "", show (_gitSource_url s)]
581+ git $ [ "clone" ]
582+ ++ ("--recursive" <$ guard (_gitSource_fetchSubmodules s))
583+ ++ [ T.unpack $ render $ _gitSource_url s ]
582 git ["reset", "--hard", Ref.toHexString $ _thunkRev_commit $ _thunkPtr_rev tptr]
584 git ["reset", "--hard", Ref.toHexString $ _thunkRev_commit $ _thunkPtr_rev tptr]
583 when (_gitSource_fetchSubmodules s) $
585 when (_gitSource_fetchSubmodules s) $
584 git ["submodule", "update", "--recursive", "--init"]
586 git ["submodule", "update", "--recursive", "--init"]
@@ -632,23 +634,29 @@ getThunkPtr' checkClean thunkDir = do
632 -- correspondents
634 -- correspondents
633 (headDump :: [Text]) <- T.lines <$> readGitProcess thunkDir
635 (headDump :: [Text]) <- T.lines <$> readGitProcess thunkDir
634 [ "for-each-ref"
636 [ "for-each-ref"
635− , "--format=%(refname:short) %(upstream:short)"
637+ , "--format=%(refname:short) %(upstream:short) %(upstream:remotename)"
636 , "refs/heads/"
638 , "refs/heads/"
641+ (headInfo :: Map Text (Maybe (Text, Text)))
638− (headInfo :: Map Text (Maybe Text)) <- fmap Map.fromList $ forM headDump $ \line -> do
642+ <- fmap Map.fromList $ forM headDump $ \line -> do
639− (branch : restOfLine) <- pure $ T.words line
643+ (branch : restOfLine) <- pure $ T.words line
640− mUpstream <- case restOfLine of
644+ mUpstream <- case restOfLine of
641− [] -> pure Nothing
645+ [] -> pure Nothing
642− [u] -> pure $ Just u
646+ [u, r] -> pure $ Just (u, r)
643− (_:_) -> failWith "git for-each-ref invalid output"
647+ (_:_) -> failWith "git for-each-ref invalid output"
644− pure (branch, mUpstream)
648+ pure (branch, mUpstream)
650+ putLog Debug $ "branches: " <> T.pack (show headInfo)
646 let errorMap :: Map Text ()
652 let errorMap :: Map Text ()
647− headUpstream :: Map Text Text
653+ headUpstream :: Map Text (Text, Text)
648 (errorMap, headUpstream) = flip Map.mapEither headInfo $ \case
654 (errorMap, headUpstream) = flip Map.mapEither headInfo $ \case
649 Nothing -> Left ()
655 Nothing -> Left ()
650 Just b -> Right b
656 Just b -> Right b
658+ putLog Debug $ "branches with upstream branch set: " <> T.pack (show headUpstream)
652 -- Check that every branch has a remote equivalent
660 -- Check that every branch has a remote equivalent
653 when checkClean $ do
661 when checkClean $ do
654 let untrackedBranches = Map.keys errorMap
662 let untrackedBranches = Map.keys errorMap
@@ -670,7 +678,7 @@ getThunkPtr' checkClean thunkDir = do
672 -- loosely by https://stackoverflow.com/questions/7773939/show-git-ahead-and-behind-info-for-all-branches-including-remotes
680 -- loosely by https://stackoverflow.com/questions/7773939/show-git-ahead-and-behind-info-for-all-branches-including-remotes
673− stats <- iforM headUpstream $ \branch upstream -> do
681+ stats <- iforM headUpstream $ \branch (upstream, _remote) -> do
674 (stat :: [Text]) <- T.lines <$> readGitProcess thunkDir
682 (stat :: [Text]) <- T.lines <$> readGitProcess thunkDir
675 [ "rev-list", "--left-right"
683 [ "rev-list", "--left-right"
676 , T.unpack branch <> "..." <> T.unpack upstream
684 , T.unpack branch <> "..." <> T.unpack upstream
@@ -695,13 +703,12 @@ getThunkPtr' checkClean thunkDir = do
696 -- We assume it's safe to pack the thunk at this point
704 -- We assume it's safe to pack the thunk at this point
698− -- Get current branch `git rev-parse --abbrev-ref HEAD`
706+ -- Get current branch ``
699 mCurrentBranch <- listToMaybe
707 mCurrentBranch <- listToMaybe
700 <$> T.lines
708 <$> T.lines
701 <$> readGitProcess thunkDir ["rev-parse", "--abbrev-ref", "HEAD"]
709 <$> readGitProcess thunkDir ["rev-parse", "--abbrev-ref", "HEAD"]
703− let remote = maybe "origin" id $
704− flip Map.lookup headUpstream =<< mCurrentBranch
711+ let remote = maybe "origin" snd $ flip Map.lookup headUpstream =<< mCurrentBranch
706 [remoteUri'] <- fmap T.lines $ readGitProcess thunkDir
713 [remoteUri'] <- fmap T.lines $ readGitProcess thunkDir
707 [ "config"
714 [ "config"
@@ -740,9 +747,10 @@ uriThunkPtr uri mbranch = do
740 case rev of
747 case rev of
741 Right r -> pure (ThunkSource_GitHub s, r)
748 Right r -> pure (ThunkSource_GitHub s, r)
742 Left e -> do
749 Left e -> do
743− putLog Alert $ " \
750+ putLog Warning $ " \
744−\ Failed to fetch archive from GitHub. This is probably a private repo. \
751+\Failed to fetch archive from GitHub. This is probably a private repo. \
745−\ Falling back on normal fetchgit. Original failure:\n\n" <> T.pack (show e)
752+\Falling back on normal fetchgit. Original failure:\n\n"
746 let s' = forgetGithub s
754 let s' = forgetGithub s
747 (,) (ThunkSource_Git s') <$> gitThunkRev s' commit
755 (,) (ThunkSource_Git s') <$> gitThunkRev s' commit
748 ThunkSource_Git s -> (,) (ThunkSource_Git s) <$> gitThunkRev s commit
756 ThunkSource_Git s -> (,) (ThunkSource_Git s) <$> gitThunkRev s commit
@@ -846,7 +854,9 @@ gitThunkRev s commit = do
846gitGetCommitBranch
854gitGetCommitBranch
847 :: MonadObelisk m => URI -> Maybe Text -> m (Text, CommitId)
855 :: MonadObelisk m => URI -> Maybe Text -> m (Text, CommitId)
848gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote " <> uriMsg) $ do
856gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote " <> uriMsg) $ do
857+ bothMaps <- gitLsRemote
858+ (T.unpack $ render uri)
849− bothMaps <- rethrowE =<< liftIO (gitLsRemote (show uri) (GitRef_Branch <$> mbranch))
859+ (GitRef_Branch <$> mbranch)
850 branch <- case mbranch of
860 branch <- case mbranch of
851 Nothing -> withExitFailMessage "Failed to find default branch" $ do
861 Nothing -> withExitFailMessage "Failed to find default branch" $ do
852 b <- rethrowE $ gitLookupDefaultBranch bothMaps
862 b <- rethrowE $ gitLookupDefaultBranch bothMaps
@@ -860,10 +870,10 @@ gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote "
860 pure (branch, commit)
870 pure (branch, commit)
862 rethrowE = either failWith pure
872 rethrowE = either failWith pure
863− uriMsg = T.pack $ show uri
873+ uriMsg = render uri
865parseGitUri :: Text -> Maybe URI
875parseGitUri :: Text -> Maybe URI
866−parseGitUri x = mkURI x <|> parseSshShorthand x
876+parseGitUri x = parseSshShorthand x <|> mkURI x
868parseSshShorthand :: Text -> Maybe URI
878parseSshShorthand :: Text -> Maybe URI
869parseSshShorthand uri = do
879parseSshShorthand uri = do