Skip to content

Commit 5ed860f

Browse files
pks-tgitster
authored andcommitted
builtin/clone: introduce --ref-format= value flag
Introduce a new `--ref-format` value flag for git-clone(1) that allows the user to specify the ref format that is to be used for a newly initialized repository. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48fa45f commit 5ed860f

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Documentation/git-clone.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ or `--mirror` is given)
311311
The result is Git repository can be separated from working
312312
tree.
313313

314+
--ref-format=<ref-format::
315+
316+
Specify the given ref storage format for the repository. The valid values are:
317+
+
318+
include::ref-storage-format.txt[]
319+
314320
-j <n>::
315321
--jobs <n>::
316322
The number of submodules fetched at the same time.

builtin/clone.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static char *remote_name = NULL;
7272
static char *option_branch = NULL;
7373
static struct string_list option_not = STRING_LIST_INIT_NODUP;
7474
static const char *real_git_dir;
75+
static const char *ref_format;
7576
static char *option_upload_pack = "git-upload-pack";
7677
static int option_verbosity;
7778
static int option_progress = -1;
@@ -157,6 +158,8 @@ static struct option builtin_clone_options[] = {
157158
N_("any cloned submodules will be shallow")),
158159
OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
159160
N_("separate git dir from working tree")),
161+
OPT_STRING(0, "ref-format", &ref_format, N_("format"),
162+
N_("specify the reference format to use")),
160163
OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
161164
N_("set config inside the new repository")),
162165
OPT_STRING_LIST(0, "server-option", &server_options,
@@ -932,6 +935,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
932935
int submodule_progress;
933936
int filter_submodules = 0;
934937
int hash_algo;
938+
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
935939
const int do_not_override_repo_unix_permissions = -1;
936940

937941
struct transport_ls_refs_options transport_ls_refs_options =
@@ -957,6 +961,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
957961
if (option_single_branch == -1)
958962
option_single_branch = deepen ? 1 : 0;
959963

964+
if (ref_format) {
965+
ref_storage_format = ref_storage_format_by_name(ref_format);
966+
if (ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
967+
die(_("unknown ref storage format '%s'"), ref_format);
968+
}
969+
960970
if (option_mirror)
961971
option_bare = 1;
962972

@@ -1108,7 +1118,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11081118
* their on-disk data structures.
11091119
*/
11101120
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
1111-
REF_STORAGE_FORMAT_UNKNOWN, NULL,
1121+
ref_storage_format, NULL,
11121122
do_not_override_repo_unix_permissions, INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
11131123

11141124
if (real_git_dir) {

t/t5601-clone.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ test_expect_success 'clone --mirror does not repeat tags' '
157157
158158
'
159159

160+
test_expect_success 'clone with files ref format' '
161+
test_when_finished "rm -rf ref-storage" &&
162+
git clone --ref-format=files --mirror src ref-storage &&
163+
echo files >expect &&
164+
git -C ref-storage rev-parse --show-ref-format >actual &&
165+
test_cmp expect actual
166+
'
167+
168+
test_expect_success 'clone with garbage ref format' '
169+
cat >expect <<-EOF &&
170+
fatal: unknown ref storage format ${SQ}garbage${SQ}
171+
EOF
172+
test_must_fail git clone --ref-format=garbage --mirror src ref-storage 2>err &&
173+
test_cmp expect err &&
174+
test_path_is_missing ref-storage
175+
'
176+
160177
test_expect_success 'clone to destination with trailing /' '
161178
162179
git clone src target-1/ &&

0 commit comments

Comments
 (0)