diff options
-rw-r--r-- | builtin/init-db.c | 5 | ||||
-rwxr-xr-x | t/t0001-init.sh | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c index cee64823cb..60e5c14169 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -568,6 +568,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0); + if (real_git_dir && is_bare_repository_cfg == 1) + die(_("--separate-git-dir and --bare are mutually exclusive")); + if (real_git_dir && !is_absolute_path(real_git_dir)) real_git_dir = real_pathdup(real_git_dir, 1); @@ -663,6 +666,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) get_git_work_tree()); } else { + if (real_git_dir) + die(_("--separate-git-dir incompatible with bare repository")); if (work_tree) set_git_work_tree(work_tree); } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 6d2467995e..5c585f7fcb 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -316,6 +316,19 @@ test_expect_success 'init with separate gitdir' ' test_path_is_dir realgitdir/refs ' +test_expect_success 'explicit bare & --separate-git-dir incompatible' ' + test_must_fail git init --bare --separate-git-dir goop.git bare.git 2>err && + test_i18ngrep "mutually exclusive" err +' + +test_expect_success 'implicit bare & --separate-git-dir incompatible' ' + test_when_finished "rm -rf bare.git" && + mkdir -p bare.git && + test_must_fail env GIT_DIR=. \ + git -C bare.git init --separate-git-dir goop.git 2>err && + test_i18ngrep "incompatible" err +' + test_lazy_prereq GETCWD_IGNORES_PERMS ' base=GETCWD_TEST_BASE_DIR && mkdir -p $base/dir && |