Skip to content
  • Gábor Szeder's avatar
    clone: respect additional configured fetch refspecs during initial fetch · 515be833
    Gábor Szeder authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The initial fetch during a clone doesn't transfer refs matching
    additional fetch refspecs given on the command line as configuration
    variables, e.g. '-c remote.origin.fetch=<refspec>'.  This contradicts
    the documentation stating that configuration variables specified via
    'git clone -c <key>=<value> ...' "take effect immediately after the
    repository is initialized, but before the remote history is fetched"
    and the given example specifically mentions "adding additional fetch
    refspecs to the origin remote".  Furthermore, one-shot configuration
    variables specified via 'git -c <key>=<value> clone ...', though not
    written to the newly created repository's config file, live during the
    lifetime of the 'clone' command, including the initial fetch.  All
    this implies that any fetch refspecs specified this way should already
    be taken into account during the initial fetch.
    
    The reason for this is that the initial fetch is not a fully fledged
    'git fetch' but a bunch of direct calls into the fetch/transport
    machinery with clone's own refs-to-refspec matching logic, which
    bypasses parts of 'git fetch' processing configured fetch refspecs.
    This logic only considers a single default refspec, potentially
    influenced by options like '--single-branch' and '--mirror'.  The
    configured refspecs are, however, already read and parsed properly
    when clone calls remote.c:remote_get(), but it never looks at the
    parsed refspecs in the resulting 'struct remote'.
    
    Modify clone to take the remote's configured fetch refspecs into
    account to retrieve all matching refs during the initial fetch.  Note
    that we have to explicitly add the default fetch refspec to the
    remote's refspecs, because at that point the remote only includes the
    fetch refspecs specified on the command line.
    
    Add tests to check that refspecs given both via 'git clone -c ...' and
    'git -c ... clone' retrieve all refs matching either the default or
    the additional refspecs, and that it works even when the user
    specifies an alternative remote name via '--origin=<name>'.
    
    Signed-off-by: default avatarSZEDER Gábor <szeder.dev@gmail.com>
    Reviewed-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    515be833