Skip to content

Commit 6810053

Browse files
committed
Merge branch 'lr/init-bare'
* lr/init-bare: git-init: accept --bare option
2 parents 32d8050 + 74d3b23 commit 6810053

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Documentation/git-init.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-init - Create an empty git repository or reinitialize an existing one
88

99
SYNOPSIS
1010
--------
11-
'git-init' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
11+
'git-init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
1212

1313

1414
OPTIONS
@@ -20,6 +20,11 @@ OPTIONS
2020

2121
Only print error and warning messages, all other output will be suppressed.
2222

23+
--bare::
24+
25+
Create a bare repository. If GIT_DIR environment is not set, it is set to the
26+
current working directory.
27+
2328
--template=<template_directory>::
2429

2530
Provide the directory from which templates will be used. The default template

builtin-init-db.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static int guess_repository_type(const char *git_dir)
364364
}
365365

366366
static const char init_db_usage[] =
367-
"git-init [-q | --quiet] [--template=<template-directory>] [--shared]";
367+
"git-init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
368368

369369
/*
370370
* If you want to, you can share the DB area with any number of branches.
@@ -383,7 +383,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
383383
const char *arg = argv[1];
384384
if (!prefixcmp(arg, "--template="))
385385
template_dir = arg+11;
386-
else if (!strcmp(arg, "--shared"))
386+
else if (!strcmp(arg, "--bare")) {
387+
static char git_dir[PATH_MAX+1];
388+
is_bare_repository_cfg = 1;
389+
setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
390+
sizeof(git_dir)), 0);
391+
} else if (!strcmp(arg, "--shared"))
387392
shared_repository = PERM_GROUP;
388393
else if (!prefixcmp(arg, "--shared="))
389394
shared_repository = git_config_perm("arg", arg+9);

t/t0001-init.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ test_expect_success 'GIT_DIR bare' '
7979
check_config git-dir-bare.git true unset
8080
'
8181

82+
test_expect_success 'init --bare' '
83+
84+
(
85+
unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
86+
mkdir git-init-bare.git &&
87+
cd git-init-bare.git &&
88+
git init --bare
89+
) &&
90+
check_config git-init-bare.git true unset
91+
'
92+
8293
test_expect_success 'GIT_DIR non-bare' '
8394
8495
(

0 commit comments

Comments
 (0)