Skip to content

Commit 58a11b3

Browse files
authored
Allow oldPaper fetching from reachable sha1 (#287)
* Allow oldPaper fetching from reachable sha1 Git servers by default do not offer the capability to reach available sha1 hashes during a fetch request. Setting up the old paper repository hence only worked if the requested sha1 is the HEAD of a locally fetched branch. The commit temporarily enables the allowreachablesha1inwant git option for the local paper repository, enabling the single depth fetch of any reachable sha1 for the oldPaper git repo. * Revert config to previous value
1 parent 77eaa19 commit 58a11b3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/SetupMinecraftSources.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,30 @@ abstract class SetupMinecraftSources : JavaLauncherTask() {
216216
oldPaperGit.remoteAdd().setName("origin").setUri(URIish(rootProjectDir.absolutePathString())).call()
217217
}
218218

219-
oldPaperGit.fetch().setDepth(1).setRemote("origin").setRefSpecs(oldPaperCommit.get()).call()
220-
oldPaperGit.reset().setMode(ResetCommand.ResetType.HARD).setRef(oldPaperCommit.get()).call()
219+
val upstream = Git.open(rootProjectDir.toFile())
220+
val upstreamConfig = upstream.repository.config
221+
val upstreamReachableSHA1 = upstreamConfig.getString("uploadpack", null, "allowreachablesha1inwant")
222+
val upstreamConfigContainsUploadPack = upstreamConfig.sections.contains("uploadpack")
223+
try {
224+
// Temporarily allow fetching reachable sha1 refs from the "upstream" paper repository.
225+
upstreamConfig.setBoolean("uploadpack", null, "allowreachablesha1inwant", true)
226+
upstreamConfig.save()
227+
oldPaperGit.fetch().setDepth(1).setRemote("origin").setRefSpecs(oldPaperCommit.get()).call()
228+
oldPaperGit.reset().setMode(ResetCommand.ResetType.HARD).setRef(oldPaperCommit.get()).call()
229+
} finally {
230+
if (upstreamReachableSHA1 == null) {
231+
if (upstreamConfigContainsUploadPack) {
232+
upstreamConfig.unset("uploadpack", null, "allowreachablesha1inwant")
233+
} else {
234+
upstreamConfig.unsetSection("uploadpack", null)
235+
}
236+
} else {
237+
upstreamConfig.setString("uploadpack", null, "allowreachablesha1inwant", upstreamReachableSHA1)
238+
}
239+
upstreamConfig.save()
240+
upstream.close()
241+
}
242+
221243
oldPaperGit.close()
222244

223245
val isWindows = System.getProperty("os.name").lowercase().contains("win")

0 commit comments

Comments
 (0)