Skip to content

fetch() writes tag refs without fetching the tag objects #24

Closed

Description

@dnnsjsk

Repository::fetch() writes every advertised refs/tags/* ref (

pitmaster/src/Repository.php

Lines 1883 to 1887 in 5beb97d

foreach ($remoteRefs as $refName => $refId) {
if (str_starts_with($refName, 'refs/tags/') && !str_ends_with($refName, '^{}')) {
$this->refs->update($refName, $refId);
}
}
), but only asks the server for the objects of the refs matched by remote.<name>.fetch (by default refs/heads/*,

pitmaster/src/Repository.php

Lines 1789 to 1830 in 5beb97d

private function plannedFetchRefs(string $remote, array $remoteRefs): array
{
$refspecs = $this->config->getAll("remote.{$remote}.fetch");
if ($refspecs === []) {
$refspecs = ["+refs/heads/*:refs/remotes/{$remote}/*"];
}
$negativePatterns = [];
foreach ($refspecs as $refspec) {
if (str_starts_with($refspec, '^')) {
$negativePatterns[] = substr($refspec, 1);
}
}
$planned = [];
foreach ($refspecs as $refspec) {
if (str_starts_with($refspec, '^')) {
continue;
}
if (str_starts_with($refspec, '+')) {
$refspec = substr($refspec, 1);
}
[$srcPattern, $dstPattern] = array_pad(explode(':', $refspec, 2), 2, null);
if ($srcPattern === null || $dstPattern === null) {
continue;
}
foreach ($remoteRefs as $src => $id) {
if ($this->matchesRefspecPattern($negativePatterns, $src)) {
continue;
}
$dst = $this->mapFetchRefspec($srcPattern, $dstPattern, $src);
if ($dst === null) {
continue;
}
), and it does not request the include-tag capability (
public const DEFAULT_FETCH_CAPABILITIES = [
'multi_ack_detailed',
'no-done',
'side-band-64k',
'thin-pack',
'no-progress',
'ofs-delta',
'deepen-since',
'deepen-not',
'agent=Pitmaster/1.0',
];
).

An annotated tag created on the remote since the last fetch therefore becomes a local refs/tags/<name> that points to a tag object which was never downloaded. resolve('<tag>') returns that ID, and show('<tag>') / readObject() fail with a missing object, while git fsck reports a broken ref. The same applies to tags that point at commits outside the fetched branches.

Found by reading the code; the full network path was not run.

Expected

Either request include-tag (and want tag objects that are missing), or only write tag refs whose objects exist locally, as git's tag following does.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions