@matheusbsbs / matheus-bagliano / commits / 74d3b23fe3
Fork 0

git-init: accept --bare option

It is unfortunate that "git init --bare" does not work and the only reason why "init" did not learn its own "--bare" option is because "git --bare init" already does the job (and as an option to the git 'potty', it is more generic solution). This teaches "git init" its own "--bare" option, so that both "git --bare init" and "git init --bare" works mostly the same way. [jc: rewrote the log message and added test] Signed-off-by: Luciano Rocha <strange@nsk.pt> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Luciano Rocha committed May 28, 2008 at 19:53 UTC 74d3b23fe3771c769ccd5c97f6a46682b4061577
3 files changed +24 -3
Documentation/git-init.txt
+6 -1
@@ -8,7 +8,7 @@ git-init - Create an empty git repository or reinitialize an existing one
8
9 SYNOPSIS
10 --------
11 -'git-init' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
11 +'git-init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
12
13
14 OPTIONS
@@ -20,6 +20,11 @@ OPTIONS
20
21 Only print error and warning messages, all other output will be suppressed.
22
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 +
28 --template=<template_directory>::
29
30 Provide the directory from which templates will be used. The default template
builtin-init-db.c
+7 -2
@@ -364,7 +364,7 @@ static int guess_repository_type(const char *git_dir)
364 }
365
366 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>]]";
368
369 /*
370 * 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)
383 const char *arg = argv[1];
384 if (!prefixcmp(arg, "--template="))
385 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"))
392 shared_repository = PERM_GROUP;
393 else if (!prefixcmp(arg, "--shared="))
394 shared_repository = git_config_perm("arg", arg+9);
t/t0001-init.sh
+11
@@ -79,6 +79,17 @@ test_expect_success 'GIT_DIR bare' '
79 check_config git-dir-bare.git true unset
80 '
81
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 +
93 test_expect_success 'GIT_DIR non-bare' '
94
95 (