@@ -46,6 +46,11 @@ The following combinations are supported by this version of Git:
format. Loose references are preferred, and the `packed-refs` file
is updated only when deleting a reference that is stored in the
`packed-refs` file or during a `git pack-refs` command.
+
+`files`;;
+ When only this value is present, Git will ignore the `packed-refs`
+ file and refuse to write one during `git pack-refs`. All references
+ will be read from and written to loose reference files.
--
extensions.worktreeConfig::
@@ -1198,6 +1198,12 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
struct strbuf err = STRBUF_INIT;
struct ref_transaction *transaction;
+ if (!packed_refs_enabled(refs->store_flags)) {
+ warning(_("refusing to create '%s' file because '%s' is not set"),
+ "packed-refs", "extensions.refFormat=packed");
+ return -1;
+ }
+
transaction = ref_store_transaction_begin(refs->packed_ref_store, &err);
if (!transaction)
return -1;
@@ -478,6 +478,9 @@ static int load_contents(struct snapshot *snapshot)
size_t size;
ssize_t bytes_read;
+ if (!packed_refs_enabled(snapshot->refs->store_flags))
+ return 0;
+
fd = open(snapshot->refs->path, O_RDONLY);
if (fd < 0) {
if (errno == ENOENT) {
@@ -524,6 +524,11 @@ struct ref_store;
#define REF_STORE_FORMAT_FILES (1 << 8) /* can use loose ref files */
#define REF_STORE_FORMAT_PACKED (1 << 9) /* can use packed-refs file */
+static inline int packed_refs_enabled(int flags)
+{
+ return flags & REF_STORE_FORMAT_PACKED;
+}
+
/*
* Initialize the ref_store for the specified gitdir. These functions
* should call base_ref_store_init() to initialize the shared part of
@@ -36,4 +36,24 @@ test_expect_success 'extensions.refFormat=packed only' '
)
'
+test_expect_success 'extensions.refFormat=files only' '
+ test_commit T &&
+ git pack-refs --all &&
+ git init only-loose &&
+ (
+ cd only-loose &&
+ git config core.repositoryFormatVersion 1 &&
+ git config extensions.refFormat files &&
+ test_commit A &&
+ test_commit B &&
+ test_must_fail git pack-refs 2>err &&
+ grep "refusing to create" err &&
+ test_path_is_missing .git/packed-refs &&
+
+ # Refuse to parse a packed-refs file.
+ cp ../.git/packed-refs .git/packed-refs &&
+ test_must_fail git rev-parse refs/tags/T
+ )
+'
+
test_done