-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(downloader): Fix updating the Git working tree for a branch
The `Git.updateWorkingTree` function called only `git checkout $revision` after fetching. In case of a local branch that was already cloned before, this did not update the local branch. Fix this by calling `git reset --hard FETCH_HEAD` after the checkout if the revision is not a fixed revision. Signed-off-by: Martin Nonnenmacher <[email protected]>
- Loading branch information
1 parent
bd67313
commit 9c0d567
Showing
2 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
package org.ossreviewtoolkit.downloader.vcs | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.engine.spec.tempdir | ||
import io.kotest.matchers.result.shouldBeSuccess | ||
import io.kotest.matchers.shouldBe | ||
import org.ossreviewtoolkit.downloader.WorkingTree | ||
import org.ossreviewtoolkit.model.VcsInfo | ||
import org.ossreviewtoolkit.model.VcsType | ||
import java.io.File | ||
Check warning Code scanning / detekt Reports files that do not follow ORT's order for imports Warning
Imports in file '/home/runner/work/ort/ort/downloader/src/funTest/kotlin/vcs/GitFunTest.kt' are not sorted alphabetically or single blank lines are missing between different top-level packages
|
||
|
||
private val branches = mapOf( | ||
"main" to "6f09f276c4426c387c6663f54bbd45aea8d81dac", | ||
"branch1" to "0c58ea81d5c8112affab7a9cd6308deb4bc51589", | ||
"branch2" to "7a05ad3ad30b4ddbfac22e0b768fb91383f16d8d", | ||
"branch3" to "b798693a551e4d0e96d09409948327178a9abbce" | ||
) | ||
|
||
private val tags = mapOf( | ||
"tag1" to "0c58ea81d5c8112affab7a9cd6308deb4bc51589", | ||
"tag2" to "7a05ad3ad30b4ddbfac22e0b768fb91383f16d8d", | ||
"tag3" to "b798693a551e4d0e96d09409948327178a9abbce" | ||
) | ||
|
||
class GitFunTest : WordSpec({ | ||
val git = Git() | ||
val vcsInfo = VcsInfo( | ||
type = VcsType.GIT, | ||
url = "https://github.com/oss-review-toolkit/ort-test-data-git.git", | ||
revision = "main" | ||
) | ||
|
||
lateinit var repoDir: File | ||
lateinit var workingTree : WorkingTree | ||
Check warning Code scanning / detekt Reports spaces around colons Warning
Unexpected spacing before ":"
|
||
|
||
beforeEach { | ||
repoDir = tempdir() | ||
workingTree = git.initWorkingTree(repoDir, vcsInfo) | ||
} | ||
|
||
"updateWorkingTree" should { | ||
"update the working tree to the correct revision" { | ||
branches.values.forEach { revision -> | ||
git.updateWorkingTree(workingTree, revision) shouldBeSuccess revision | ||
workingTree.getRevision() shouldBe revision | ||
} | ||
} | ||
|
||
"update the working tree to the correct tag" { | ||
tags.forEach { (tag, revision) -> | ||
git.updateWorkingTree(workingTree, tag) shouldBeSuccess tag | ||
workingTree.getRevision() shouldBe revision | ||
} | ||
} | ||
|
||
"update the working tree to the correct branch" { | ||
branches.forEach { (branch, revision) -> | ||
git.updateWorkingTree(workingTree, branch) shouldBeSuccess branch | ||
workingTree.getRevision() shouldBe revision | ||
} | ||
} | ||
|
||
"update an outdated local branch" { | ||
val branch = "branch1" | ||
val revision = branches.getValue(branch) | ||
|
||
git.updateWorkingTree(workingTree, branch) | ||
git.run("reset", "--hard", "HEAD~1", workingDir = repoDir) | ||
|
||
git.updateWorkingTree(workingTree, branch) shouldBeSuccess branch | ||
workingTree.getRevision() shouldBe revision | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters