Skip to content

Commit

Permalink
patch: Don't use reference repo if it's shallow
Browse files Browse the repository at this point in the history
Shallow repos can't meaningfully be used as a reference, so don't try
to use at as an "alternates" object store.

Fixes #114
  • Loading branch information
ajoberstar committed Dec 10, 2024
1 parent b1ea705 commit e77201b
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e77201b

Please sign in to comment.