From e77201b37083c3055e8abaf6c6a0d2852a047f51 Mon Sep 17 00:00:00 2001 From: Andrew Oberstar Date: Mon, 9 Dec 2024 18:53:46 -0600 Subject: [PATCH] patch: Don't use reference repo if it's shallow Shallow repos can't meaningfully be used as a reference, so don't try to use at as an "alternates" object store. Fixes #114 --- .../git/publish/tasks/GitPublishReset.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/ajoberstar/gradle/git/publish/tasks/GitPublishReset.java b/src/main/java/org/ajoberstar/gradle/git/publish/tasks/GitPublishReset.java index 73aaf9a..e9ce809 100644 --- a/src/main/java/org/ajoberstar/gradle/git/publish/tasks/GitPublishReset.java +++ b/src/main/java/org/ajoberstar/gradle/git/publish/tasks/GitPublishReset.java @@ -94,19 +94,25 @@ public void reset() throws IOException { }); } - // set alternate object store if reference used - if (getReferenceRepoUri().isPresent()) { + // set alternate object store if reference used and not using fetch depth + if (getReferenceRepoUri().isPresent() && !getFetchDepth().isPresent()) { Path repoObjectsPath = repoDir.toPath().resolve(".git").resolve("objects"); Path alternatesPath = repoObjectsPath.resolve("info").resolve("alternates"); Path referenceRepoPath = Path.of(getReferenceRepoUri().get()); + Path referenceRepoGitPath = referenceRepoPath.resolve(".git"); + if (Files.exists(referenceRepoGitPath)) { + // not a bare repo + referenceRepoPath = referenceRepoGitPath; + } + + Path referenceRepoShallowPath = referenceRepoPath.resolve("shallow"); + Path referenceRepoObjectsPath = referenceRepoPath.resolve("objects"); - Path referenceRepoObjectsPath = referenceRepoPath.resolve(".git").resolve("objects"); - Path referenceBareRepoObjectsPath = referenceRepoPath.resolve("objects"); - if (Files.exists(referenceRepoObjectsPath)) { + if (Files.exists(referenceRepoShallowPath)) { + getLogger().info("Reference repo is shallow. Cannot use as a reference."); + } else if (Files.exists(referenceRepoObjectsPath)) { Files.writeString(alternatesPath, referenceRepoObjectsPath + "\n", StandardCharsets.UTF_8); - } else if (Files.exists(referenceBareRepoObjectsPath)) { - Files.writeString(alternatesPath, referenceBareRepoObjectsPath + "\n", StandardCharsets.UTF_8); } else { getLogger().warn("Reference repo doesn't seem to have an objects database: {}", referenceRepoPath); }