Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,19 @@ protected async Task<NativePath> PrepareCloneInternal(string remoteUri, string d
else
{
_logger.LogDebug("Clone of {repo} found in {clonePath}", remoteUri, clonePath);
var remote = await _localGitRepo.AddRemoteIfMissingAsync(clonePath, remoteUri, cancellationToken);

string remote;

try
{
remote = await _localGitRepo.AddRemoteIfMissingAsync(clonePath, remoteUri, cancellationToken);
}
catch (Exception e) when (e.Message.Contains("fatal: not a git repository"))
{
_logger.LogWarning("Clone at {clonePath} is not a git repository, re-cloning", clonePath);
_fileSystem.DeleteDirectory(clonePath, recursive: true);
return await PrepareCloneInternal(remoteUri, dirName, cancellationToken);
}

// We cannot do `fetch --all` as tokens might be needed but fetch +refs/heads/*:+refs/remotes/origin/* doesn't fetch new refs
// So we need to call `remote update origin` to fetch everything
Expand Down