aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-11-26 22:32:40 +0700
committerJunio C Hamano <gitster@pobox.com>2010-12-22 14:34:24 -0800
commit835183603b4aed84797f60c91c5ebd79be7b2e11 (patch)
tree26185e62bc8382a154dad39d39ca544c43b79f77 /builtin
parentb3f66fd3e3abeb9183f33f023727e3a53868849d (diff)
downloadgit-835183603b4aed84797f60c91c5ebd79be7b2e11.tar.gz
git-835183603b4aed84797f60c91c5ebd79be7b2e11.tar.xz
Remove all logic from get_git_work_tree()
This logic is now only used by cmd_init_db(). setup_* functions do not rely on it any more. Move all the logic to cmd_init_db() and turn get_git_work_tree() into a simple function. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/init-db.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index ea064784d..e3af9eaa8 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -414,6 +414,7 @@ static const char *const init_db_usage[] = {
int cmd_init_db(int argc, const char **argv, const char *prefix)
{
const char *git_dir;
+ const char *work_tree;
const char *template_dir = NULL;
unsigned int flags = 0;
const struct option init_db_options[] = {
@@ -480,8 +481,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
* without --bare. Catch the error early.
*/
git_dir = getenv(GIT_DIR_ENVIRONMENT);
- if ((!git_dir || is_bare_repository_cfg == 1)
- && getenv(GIT_WORK_TREE_ENVIRONMENT))
+ work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
+ if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
die("%s (or --work-tree=<directory>) not allowed without "
"specifying %s (or --git-dir=<directory>)",
GIT_WORK_TREE_ENVIRONMENT,
@@ -496,7 +497,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
if (is_bare_repository_cfg < 0)
is_bare_repository_cfg = guess_repository_type(git_dir);
- startup_info->setup_explicit = 1;
if (!is_bare_repository_cfg) {
if (git_dir) {
const char *git_dir_parent = strrchr(git_dir, '/');
@@ -511,10 +511,18 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
if (!getcwd(git_work_tree_cfg, PATH_MAX))
die_errno ("Cannot access current working directory");
}
+ if (work_tree)
+ set_git_work_tree(make_absolute_path(work_tree));
+ else
+ set_git_work_tree(git_work_tree_cfg);
if (access(get_git_work_tree(), X_OK))
die_errno ("Cannot access work tree '%s'",
get_git_work_tree());
}
+ else {
+ if (work_tree)
+ set_git_work_tree(make_absolute_path(work_tree));
+ }
set_git_dir(make_absolute_path(git_dir));