|
17 | 17 | package nextflow.scm |
18 | 18 |
|
19 | 19 | import nextflow.config.Manifest |
| 20 | +import org.eclipse.jgit.api.Git |
20 | 21 |
|
21 | 22 | import static MultiRevisionRepositoryStrategy.BARE_REPO |
22 | 23 | import static MultiRevisionRepositoryStrategy.REVISION_SUBDIR |
@@ -127,4 +128,87 @@ class MultiRevisionRepositoryStrategyTest extends Specification { |
127 | 128 | folder.resolve(REPOS_SUBDIR + '/nextflow-io/hello/' + REVISION_SUBDIR + '/1c3e9e7404127514d69369cd87f8036830f5cf64/.git/objects/info/alternates').text == folder.resolve(REPOS_SUBDIR + '/nextflow-io/hello/' + BARE_REPO + '/objects').toAbsolutePath().toString() |
128 | 129 | } |
129 | 130 |
|
| 131 | + def 'should create correct RefSpec for branches tags and commits'() { |
| 132 | + given: |
| 133 | + def folder = tempDir.getRoot() |
| 134 | + // Create a bare repo manually for testing |
| 135 | + def bareRepoPath = folder.resolve(REPOS_SUBDIR + '/test/project/' + BARE_REPO).toFile() |
| 136 | + bareRepoPath.mkdirs() |
| 137 | + def git = Git.init().setDirectory(bareRepoPath).setBare(true).call() |
| 138 | + // Configure origin to point to itself so lsRemote works (returns empty refs) |
| 139 | + def config = git.getRepository().getConfig() |
| 140 | + config.setString("remote", "origin", "url", bareRepoPath.absolutePath) |
| 141 | + config.save() |
| 142 | + git.close() |
| 143 | + |
| 144 | + def strategy = new MultiRevisionRepositoryStrategy('test/project') |
| 145 | + |
| 146 | + when: |
| 147 | + // Access the private method via Groovy's metaclass |
| 148 | + def refSpec = strategy.invokeMethod('refSpecForName', 'some-revision') |
| 149 | + |
| 150 | + then: |
| 151 | + // When revision is not found locally or remotely, it's treated as a commit |
| 152 | + refSpec.toString() == 'some-revision:refs/tags/some-revision' |
| 153 | + } |
| 154 | + |
| 155 | + @IgnoreIf({ System.getenv('NXF_SMOKE') }) |
| 156 | + @Requires({ System.getenv('NXF_GITHUB_ACCESS_TOKEN') }) |
| 157 | + def 'should fetch new remote branch not in local bare repo'() { |
| 158 | + given: |
| 159 | + def folder = tempDir.getRoot() |
| 160 | + def token = System.getenv('NXF_GITHUB_ACCESS_TOKEN') |
| 161 | + // Use a test repo with known branches |
| 162 | + def strategy = createStrategy('nextflow-io/hello', token) |
| 163 | + def manifest = Mock(Manifest) { |
| 164 | + getDefaultBranch() >> 'master' |
| 165 | + getRecurseSubmodules() >> false |
| 166 | + } |
| 167 | + |
| 168 | + when: |
| 169 | + // First, create bare repo with default branch only |
| 170 | + strategy.checkBareRepo(manifest) |
| 171 | + |
| 172 | + then: |
| 173 | + folder.resolve(REPOS_SUBDIR + '/nextflow-io/hello/' + BARE_REPO).isDirectory() |
| 174 | + |
| 175 | + when: |
| 176 | + // Now try to download 'mybranch' which exists remotely but wasn't fetched initially |
| 177 | + // Clear the local branch ref to simulate it not existing locally |
| 178 | + def bareGit = Git.open(strategy.getBareRepo()) |
| 179 | + def localBranchRef = bareGit.getRepository().findRef("refs/heads/mybranch") |
| 180 | + // If mybranch was fetched during clone, delete it to simulate fresh fetch scenario |
| 181 | + if (localBranchRef) { |
| 182 | + bareGit.branchDelete().setBranchNames("mybranch").setForce(true).call() |
| 183 | + } |
| 184 | + bareGit.close() |
| 185 | + |
| 186 | + // This should succeed by querying remote refs |
| 187 | + strategy.download('mybranch', 1, manifest) |
| 188 | + |
| 189 | + then: |
| 190 | + noExceptionThrown() |
| 191 | + // mybranch commit is 1c3e9e7404127514d69369cd87f8036830f5cf64 |
| 192 | + folder.resolve(REPOS_SUBDIR + '/nextflow-io/hello/' + REVISION_SUBDIR + '/1c3e9e7404127514d69369cd87f8036830f5cf64/.git').isDirectory() |
| 193 | + |
| 194 | + when: |
| 195 | + // Now try to download tag 'v1.2' which exists remotely but wasn't fetched initially |
| 196 | + // Clear the local tag ref to simulate it not existing locally |
| 197 | + bareGit = Git.open(strategy.getBareRepo()) |
| 198 | + def localTagRef = bareGit.getRepository().findRef("refs/tags/v1.2") |
| 199 | + // If v1.2 was fetched during clone, delete it to simulate fresh fetch scenario |
| 200 | + if (localTagRef) { |
| 201 | + bareGit.tagDelete().setTags("v1.2").call() |
| 202 | + } |
| 203 | + bareGit.close() |
| 204 | + |
| 205 | + // This should succeed by querying remote refs |
| 206 | + strategy.download('v1.2', 1, manifest) |
| 207 | + |
| 208 | + then: |
| 209 | + noExceptionThrown() |
| 210 | + // v1.2 ref is 1b420d060d3fad67027154ac48e3bdea06f058 |
| 211 | + folder.resolve(REPOS_SUBDIR + '/nextflow-io/hello/' + REVISION_SUBDIR + '/1b420d060d3fad67027154ac48e3bdea06f058da/.git').isDirectory() |
| 212 | + } |
| 213 | + |
130 | 214 | } |
0 commit comments