die_errno(_("could not create work tree dir '%s'"),
work_tree);
junk_work_tree = work_tree;
- set_git_work_tree(the_repository, work_tree);
}
if (real_git_dir) {
* repository, and reference backends may persist that information into
* their on-disk data structures.
*/
- init_db(the_repository, git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
- ref_storage_format, NULL,
- do_not_override_repo_unix_permissions, INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
+ init_db(the_repository, git_dir, real_git_dir, work_tree, option_template,
+ GIT_HASH_UNKNOWN, ref_storage_format, NULL,
+ do_not_override_repo_unix_permissions,
+ INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
if (real_git_dir) {
free((char *)git_dir);
if (!bare) {
const char *git_dir_parent = strrchr(git_dir, '/');
- if (work_tree) {
- set_git_work_tree(the_repository, work_tree);
- } else {
- char *work_tree_cfg = NULL;
-
+ if (!work_tree) {
if (git_dir_parent) {
char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
- work_tree_cfg = real_pathdup(rel, 1);
+ work_tree = real_pathdup(rel, 1);
free(rel);
+ } else {
+ work_tree = xgetcwd();
}
-
- if (!work_tree_cfg)
- work_tree_cfg = xgetcwd();
-
- set_git_work_tree(the_repository, work_tree_cfg);
-
- free(work_tree_cfg);
}
- if (access(repo_get_work_tree(the_repository), X_OK))
- die_errno (_("Cannot access work tree '%s'"),
- repo_get_work_tree(the_repository));
- }
- else {
- if (real_git_dir)
- die(_("--separate-git-dir incompatible with bare repository"));
- if (work_tree)
- set_git_work_tree(the_repository, work_tree);
+ if (access(work_tree, X_OK))
+ die_errno (_("Cannot access work tree '%s'"), work_tree);
+ } else if (real_git_dir) {
+ die(_("--separate-git-dir incompatible with bare repository"));
}
flags |= INIT_DB_EXIST_OK;
- ret = init_db(the_repository, git_dir, real_git_dir, template_dir, hash_algo,
- ref_storage_format, initial_branch,
+ ret = init_db(the_repository, git_dir, real_git_dir, work_tree,
+ template_dir, hash_algo, ref_storage_format, initial_branch,
init_shared_repository, flags);
free(template_dir_to_free);
}
int init_db(struct repository *repo,
- const char *git_dir, const char *real_git_dir,
+ const char *git_dir,
+ const char *real_git_dir,
+ const char *worktree,
const char *template_dir, int hash,
enum ref_storage_format ref_storage_format,
const char *initial_branch,
git_dir = repo_get_git_dir(repo);
}
+ if (worktree)
+ set_git_work_tree(repo, worktree);
+
/*
* Check to see if the repository version is right.
* Note that a newly created repository does not have
#define INIT_DB_SKIP_REFDB (1 << 2)
int init_db(struct repository *repo,
- const char *git_dir, const char *real_git_dir,
+ const char *git_dir,
+ const char *real_git_dir,
+ const char *worktree,
const char *template_dir, int hash_algo,
enum ref_storage_format ref_storage_format,
const char *initial_branch, int init_shared_repository,