Skip to content

Commit

Permalink
refactor(downloader): Pass the working tree to a private function
Browse files Browse the repository at this point in the history
Pass the Git `WorkingTree` to the `updateWorkingTreeWithoutSubmodules`
function. The working tree will be required by the next commit and also
allows to simplify the code a bit.

Signed-off-by: Martin Nonnenmacher <[email protected]>
  • Loading branch information
mnonnenmacher committed Sep 22, 2023
1 parent 4338904 commit 8863163
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions downloader/src/main/kotlin/vcs/Git.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Git : VersionControlSystem(), CommandLineTool {
Git(this).use { git ->
logger.info { "Updating working tree from '${workingTree.getRemoteUrl()}'." }

updateWorkingTreeWithoutSubmodules(git, revision).mapCatching {
updateWorkingTreeWithoutSubmodules(workingTree, git, revision).mapCatching {
// In case this throws the exception gets encapsulated as a failure.
if (recursive) updateSubmodules(workingTree)

Expand All @@ -183,7 +183,11 @@ class Git : VersionControlSystem(), CommandLineTool {
}
}

private fun updateWorkingTreeWithoutSubmodules(git: Git, revision: String): Result<String> =
private fun updateWorkingTreeWithoutSubmodules(
workingTree: WorkingTree,
git: Git,
revision: String
): Result<String> =
runCatching {
logger.info { "Trying to fetch only revision '$revision' with depth limited to $GIT_HISTORY_DEPTH." }

Expand Down Expand Up @@ -222,7 +226,6 @@ class Git : VersionControlSystem(), CommandLineTool {
logger.info { "Could not fetch everything using JGit: ${it.collectMessages()}" }
logger.info { "Falling back to Git CLI." }

val workingTree = GitWorkingTree(git.repository.workTree, VcsType.GIT)
if (workingTree.isShallow()) {
workingTree.runGit("fetch", "--unshallow", "--tags", "origin")
} else {
Expand All @@ -234,7 +237,7 @@ class Git : VersionControlSystem(), CommandLineTool {
logger.warn { "Failed to fetch everything: ${it.collectMessages()}" }
}.mapCatching {
// TODO: Migrate this to JGit once https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772 is implemented.
run("checkout", revision, workingDir = git.repository.workTree)
run("checkout", revision, workingDir = workingTree.workingDir)

revision
}
Expand Down

0 comments on commit 8863163

Please sign in to comment.