clone: fail gracefully when cloning filtered bundle
Users can create a new repository using 'git clone <bundle-file>'. The new "@filter" capability for bundles means that we can generate a bundle that does not contain all reachable objects, even if the header has no negative commit OIDs. It is feasible to think that we could make a filtered bundle work with the command git clone --filter=$filter --bare <bundle-file> or possibly replacing --bare with --no-checkout. However, this requires having some repository-global config that specifies the specified object filter and notifies Git about the existence of promisor pack-files. Without a remote, that is currently impossible. As a stop-gap, parse the bundle header during 'git clone' and die() with a helpful error message instead of the current behavior of failing due to "missing objects". Most of the existing logic for handling bundle clones actually happens in fetch-pack.c, but that logic is the same as if the user specified 'git fetch <bundle>', so we want to avoid failing to fetch a filtered bundle when in an existing repository that has the proper config set up for at least one remote. Carefully comment around the test that this is not the desired long-term behavior of 'git clone' in this case, but instead that we need to do more work before that is possible. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
4f39eb031a
commit
86fdd94d72
@ -33,6 +33,7 @@
|
|||||||
#include "packfile.h"
|
#include "packfile.h"
|
||||||
#include "list-objects-filter-options.h"
|
#include "list-objects-filter-options.h"
|
||||||
#include "hook.h"
|
#include "hook.h"
|
||||||
|
#include "bundle.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Overall FIXMEs:
|
* Overall FIXMEs:
|
||||||
@ -1138,6 +1139,18 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
|||||||
warning(_("--local is ignored"));
|
warning(_("--local is ignored"));
|
||||||
transport->cloning = 1;
|
transport->cloning = 1;
|
||||||
|
|
||||||
|
if (is_bundle) {
|
||||||
|
struct bundle_header header = BUNDLE_HEADER_INIT;
|
||||||
|
int fd = read_bundle_header(path, &header);
|
||||||
|
int has_filter = header.filter.choice != LOFC_DISABLED;
|
||||||
|
|
||||||
|
if (fd > 0)
|
||||||
|
close(fd);
|
||||||
|
bundle_header_release(&header);
|
||||||
|
if (has_filter)
|
||||||
|
die(_("cannot clone from filtered bundle"));
|
||||||
|
}
|
||||||
|
|
||||||
transport_set_option(transport, TRANS_OPT_KEEP, "yes");
|
transport_set_option(transport, TRANS_OPT_KEEP, "yes");
|
||||||
|
|
||||||
if (reject_shallow)
|
if (reject_shallow)
|
||||||
|
@ -537,4 +537,16 @@ do
|
|||||||
'
|
'
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# NEEDSWORK: 'git clone --bare' should be able to clone from a filtered
|
||||||
|
# bundle, but that requires a change to promisor/filter config options.
|
||||||
|
# For now, we fail gracefully with a helpful error. This behavior can be
|
||||||
|
# changed in the future to succeed as much as possible.
|
||||||
|
test_expect_success 'cloning from filtered bundle has useful error' '
|
||||||
|
git bundle create partial.bdl \
|
||||||
|
--all \
|
||||||
|
--filter=blob:none &&
|
||||||
|
test_must_fail git clone --bare partial.bdl partial 2>err &&
|
||||||
|
grep "cannot clone from filtered bundle" err
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user