Skip to content

Commit a654836

Browse files
committed
Merge branch 'es/init-no-separate-git-dir-in-bare'
The purpose of "git init --separate-git-dir" is to initialize a new project with the repository separate from the working tree, or, in the case of an existing project, to move the repository (the .git/ directory) out of the working tree. It does not make sense to use --separate-git-dir with a bare repository for which there is no working tree, so disallow its use with bare repositories. * es/init-no-separate-git-dir-in-bare: init: disallow --separate-git-dir with bare repository
2 parents 675a4aa + ccf236a commit a654836

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

builtin/init-db.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
563563

564564
argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
565565

566+
if (real_git_dir && is_bare_repository_cfg == 1)
567+
die(_("--separate-git-dir and --bare are mutually exclusive"));
568+
566569
if (real_git_dir && !is_absolute_path(real_git_dir))
567570
real_git_dir = real_pathdup(real_git_dir, 1);
568571

@@ -658,6 +661,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
658661
get_git_work_tree());
659662
}
660663
else {
664+
if (real_git_dir)
665+
die(_("--separate-git-dir incompatible with bare repository"));
661666
if (work_tree)
662667
set_git_work_tree(work_tree);
663668
}

t/t0001-init.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ test_expect_success 'init with separate gitdir' '
316316
test_path_is_dir realgitdir/refs
317317
'
318318

319+
test_expect_success 'explicit bare & --separate-git-dir incompatible' '
320+
test_must_fail git init --bare --separate-git-dir goop.git bare.git 2>err &&
321+
test_i18ngrep "mutually exclusive" err
322+
'
323+
324+
test_expect_success 'implicit bare & --separate-git-dir incompatible' '
325+
test_when_finished "rm -rf bare.git" &&
326+
mkdir -p bare.git &&
327+
test_must_fail env GIT_DIR=. \
328+
git -C bare.git init --separate-git-dir goop.git 2>err &&
329+
test_i18ngrep "incompatible" err
330+
'
331+
319332
test_lazy_prereq GETCWD_IGNORES_PERMS '
320333
base=GETCWD_TEST_BASE_DIR &&
321334
mkdir -p $base/dir &&

0 commit comments

Comments
 (0)