Skip to content

Commit

Permalink
[starter] Add support of shallow git clone for project that don't nee…
Browse files Browse the repository at this point in the history
…d full VCS history

GitOrigin-RevId: bce958038eb54008dbc937e4374d678b9b3daaa0
  • Loading branch information
MaXal authored and intellij-monorepo-bot committed Jun 20, 2024
1 parent 8b3edbb commit e16a7a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ data class GitProjectInfo(
override val isReusable: Boolean = false,
override val downloadTimeout: Duration = 10.minutes,

/**
* Set to true if you test don't need full VCS history and branches and project doesn't use submodules.
*/
val shallow: Boolean = false,

/**
* Relative path inside Image file, where project home is located
*/
Expand All @@ -54,7 +59,7 @@ data class GitProjectInfo(
get() = repositoryRootDir.let(projectHomeRelativePath)

private fun cloneRepo(projectHome: Path) {
Git.clone(repoUrl = repositoryUrl, destinationDir = projectHome, branchName = branchName, timeout = downloadTimeout)
Git.clone(repoUrl = repositoryUrl, destinationDir = projectHome, branchName = branchName, shallow = false, timeout = downloadTimeout)
}

private fun setupRepositoryState(projectHome: Path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import com.intellij.ide.starter.process.exec.ExecOutputRedirect
import com.intellij.ide.starter.process.exec.ProcessExecutor
import com.intellij.ide.starter.runner.SetupException
import com.intellij.openapi.application.PathManager
import com.intellij.tools.ide.util.common.PrintFailuresMode
import com.intellij.tools.ide.util.common.logError
import com.intellij.tools.ide.util.common.logOutput
import com.intellij.tools.ide.util.common.withRetryBlocking
import java.io.File
import java.io.IOException
import java.nio.file.Path
Expand Down Expand Up @@ -95,11 +93,12 @@ object Git {
return Path(stdout.read().split("\n").first().trim()).toAbsolutePath()
}

fun clone(repoUrl: String, destinationDir: Path, branchName: String = "", timeout: Duration = 10.minutes) {
fun clone(repoUrl: String, destinationDir: Path, branchName: String = "", shallow: Boolean, timeout: Duration = 10.minutes) {
val cmdName = "git-clone"

val arguments = mutableListOf("git", "clone", repoUrl, destinationDir.toString())
if (branchName.isNotEmpty()) arguments.addAll(listOf("-b", branchName))
if (shallow) arguments.addAll(listOf("--depth", "1"))

withRetryBlocking("Git clone $repoUrl failed", rollback = {
logOutput("Deleting $destinationDir")
Expand Down

0 comments on commit e16a7a5

Please sign in to comment.