summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 337e51c)
raw | patch | inline | side by side (parent: 337e51c)
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | |
Fri, 26 Nov 2010 15:32:35 +0000 (22:32 +0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 22 Dec 2010 22:34:24 +0000 (14:34 -0800) |
get_git_work_tree() takes input as core.worktree, core.bare,
GIT_WORK_TREE and decides correct worktree setting.
Unfortunately it does not do its job well. core.worktree and
GIT_WORK_TREE should only be taken into account, if GIT_DIR is set
(which is handled by setup_explicit_git_dir). For other setup cases,
only core.bare matters.
Add a temporary variable setup_explicit to adjust get_git_work_tree()
behavior as such. This variable will be gone once setup_* rework is
done.
Also remove is_bare_repository_cfg check in set_git_work_tree() to
ease the rework. We are going to check for core.bare and core.worktree
early before setting worktree. For example, if core.bare is true, no
need to set worktree.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
GIT_WORK_TREE and decides correct worktree setting.
Unfortunately it does not do its job well. core.worktree and
GIT_WORK_TREE should only be taken into account, if GIT_DIR is set
(which is handled by setup_explicit_git_dir). For other setup cases,
only core.bare matters.
Add a temporary variable setup_explicit to adjust get_git_work_tree()
behavior as such. This variable will be gone once setup_* rework is
done.
Also remove is_bare_repository_cfg check in set_git_work_tree() to
ease the rework. We are going to check for core.bare and core.worktree
early before setting worktree. For example, if core.bare is true, no
need to set worktree.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/init-db.c | patch | blob | history | |
cache.h | patch | blob | history | |
environment.c | patch | blob | history | |
setup.c | patch | blob | history | |
t/t1510-repo-setup.sh | patch | blob | history |
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 9d4886c71675f2bc50671ea284875ebae9a34735..ea064784dbe0dc06527f8836e286059069ca1050 100644 (file)
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
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, '/');
index 123dd4bb93ebfd387a79bd6a4ccf012257a8b0b0..b2cdda71427b6b33b236019b772c064f171bdb97 100644 (file)
--- a/cache.h
+++ b/cache.h
/* git.c */
struct startup_info {
int have_repository;
+ int setup_explicit;
};
extern struct startup_info *startup_info;
diff --git a/environment.c b/environment.c
index de5581fe51d532231b0121bd2ef2e46669015bda..d811049a7deca61326224dadcc3e98d84235fefe 100644 (file)
--- a/environment.c
+++ b/environment.c
*/
void set_git_work_tree(const char *new_work_tree)
{
- if (is_bare_repository_cfg >= 0)
- die("cannot set work tree after initialization");
git_work_tree_initialized = 1;
free(work_tree);
work_tree = xstrdup(make_absolute_path(new_work_tree));
const char *get_git_work_tree(void)
{
+ if (startup_info && !startup_info->setup_explicit) {
+ if (is_bare_repository_cfg == 1)
+ return NULL;
+ if (work_tree)
+ is_bare_repository_cfg = 0;
+ return work_tree;
+ }
+
if (!git_work_tree_initialized) {
work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
/* core.bare = true overrides implicit and config work tree */
index 49a1a2525a871ba408146cd57e6b82cc43898f5e..c7d71986c016fea52169a807d7d61f3aaa73dee8 100644 (file)
--- a/setup.c
+++ b/setup.c
static char buffer[1024 + 1];
const char *retval;
+ if (startup_info)
+ startup_info->setup_explicit = 1;
if (PATH_MAX - 40 < strlen(gitdirenv))
die("'$%s' too big", GIT_DIR_ENVIRONMENT);
if (!is_git_directory(gitdirenv)) {
char *cwd, int *nongit_ok)
{
int root_len;
+ char *work_tree;
inside_git_dir = 0;
if (!work_tree_env)
inside_work_tree = 1;
root_len = offset_1st_component(cwd);
- git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
+ work_tree = xstrndup(cwd, offset > root_len ? offset : root_len);
+ set_git_work_tree(work_tree);
+ free(work_tree);
if (check_repository_format_gently(gitdir, nongit_ok))
return NULL;
if (offset == len)
const char *retval = setup_git_directory_gently(NULL);
/* If the work tree is not the default one, recompute prefix */
- if (inside_work_tree < 0) {
+ if ((!startup_info || startup_info->setup_explicit) &&
+ inside_work_tree < 0) {
static char buffer[PATH_MAX + 1];
char *rel;
if (retval && chdir(retval))
diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh
index fbab9c7e685294758fd2d2d46947e238e2775779..a5f10a5878e8f50132e4508512ab1ac723f27d29 100755 (executable)
--- a/t/t1510-repo-setup.sh
+++ b/t/t1510-repo-setup.sh
cd ..
'
-test_expect_failure '#1: at root' '
+test_expect_success '#1: at root' '
cat >1/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/1
test_repo 1
'
-test_expect_failure '#1: in subdir' '
+test_expect_success '#1: in subdir' '
cat >1/sub/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/1
cd ..
'
-test_expect_failure '#4: at root' '
+test_expect_success '#4: at root' '
cat >4/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/4
test_repo 4
'
-test_expect_failure '#4: in subdir' '
+test_expect_success '#4: in subdir' '
cat >4/sub/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/4
cd ..
'
-test_expect_failure '#5: at root' '
+test_expect_success '#5: at root' '
cat >5/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/5
test_repo 5
'
-test_expect_failure '#5: in subdir' '
+test_expect_success '#5: in subdir' '
cat >5/sub/expected <<EOF &&
setup: git_dir: .git
setup: worktree: $TRASH_DIRECTORY/5
cd ..
'
-test_expect_failure '#9: at root' '
+test_expect_success '#9: at root' '
cat >9/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/9.git
setup: worktree: $TRASH_DIRECTORY/9
test_repo 9
'
-test_expect_failure '#9: in subdir' '
+test_expect_success '#9: in subdir' '
cat >9/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/9.git
setup: worktree: $TRASH_DIRECTORY/9
cd ..
'
-test_expect_failure '#12: at root' '
+test_expect_success '#12: at root' '
cat >12/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/12.git
setup: worktree: $TRASH_DIRECTORY/12
test_repo 12
'
-test_expect_failure '#12: in subdir' '
+test_expect_success '#12: in subdir' '
cat >12/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/12.git
setup: worktree: $TRASH_DIRECTORY/12
cd ..
'
-test_expect_failure '#13: at root' '
+test_expect_success '#13: at root' '
cat >13/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/13.git
setup: worktree: $TRASH_DIRECTORY/13
test_repo 13
'
-test_expect_failure '#13: in subdir' '
+test_expect_success '#13: in subdir' '
cat >13/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/13.git
setup: worktree: $TRASH_DIRECTORY/13
cd ..
'
-test_expect_failure '#17.1: at .git' '
+test_expect_success '#17.1: at .git' '
cat >17/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
test_repo 17/.git
'
-test_expect_failure '#17.1: in .git/wt' '
+test_expect_success '#17.1: in .git/wt' '
cat >17/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
test_repo 17/.git/wt
'
-test_expect_failure '#17.1: in .git/wt/sub' '
+test_expect_success '#17.1: in .git/wt/sub' '
cat >17/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
git config --file="$TRASH_DIRECTORY/17/.git/config" core.bare true
'
-test_expect_failure '#17.2: at .git' '
+test_expect_success '#17.2: at .git' '
cat >17/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
test_repo 17/.git
'
-test_expect_failure '#17.2: in .git/wt' '
+test_expect_success '#17.2: in .git/wt' '
cat >17/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
test_repo 17/.git/wt
'
-test_expect_failure '#17.2: in .git/wt/sub' '
+test_expect_success '#17.2: in .git/wt/sub' '
cat >17/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/17/.git
setup: worktree: (null)
test_repo 17/.git/wt/sub
'
-test_expect_failure '#17.2: at root' '
+test_expect_success '#17.2: at root' '
cat >17/expected <<EOF &&
setup: git_dir: .git
setup: worktree: (null)
cd ..
'
-test_expect_failure '#20.1: at .git' '
+test_expect_success '#20.1: at .git' '
cat >20/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
test_repo 20/.git
'
-test_expect_failure '#20.1: in .git/wt' '
+test_expect_success '#20.1: in .git/wt' '
cat >20/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/20/.git
setup: worktree: (null)
test_repo 20/.git/wt
'
-test_expect_failure '#20.1: in .git/wt/sub' '
+test_expect_success '#20.1: in .git/wt/sub' '
cat >20/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/20/.git
setup: worktree: (null)
cd ..
'
-test_expect_failure '#21.1: at .git' '
+test_expect_success '#21.1: at .git' '
cat >21/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
test_repo 21/.git
'
-test_expect_failure '#21.1: in .git/wt' '
+test_expect_success '#21.1: in .git/wt' '
cat >21/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
test_repo 21/.git/wt
'
-test_expect_failure '#21.1: in .git/wt/sub' '
+test_expect_success '#21.1: in .git/wt/sub' '
cat >21/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
git config --file="$TRASH_DIRECTORY/21/.git/config" core.bare true
'
-test_expect_failure '#21.2: at .git' '
+test_expect_success '#21.2: at .git' '
cat >21/.git/expected <<EOF &&
setup: git_dir: .
setup: worktree: (null)
test_repo 21/.git
'
-test_expect_failure '#21.2: in .git/wt' '
+test_expect_success '#21.2: in .git/wt' '
cat >21/.git/wt/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
test_repo 21/.git/wt
'
-test_expect_failure '#21.2: in .git/wt/sub' '
+test_expect_success '#21.2: in .git/wt/sub' '
cat >21/.git/wt/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/21/.git
setup: worktree: (null)
test_repo 21/.git/wt/sub
'
-test_expect_failure '#21.2: at root' '
+test_expect_success '#21.2: at root' '
cat >21/expected <<EOF &&
setup: git_dir: .git
setup: worktree: (null)
cd ..
'
-test_expect_success '#24: at root' '
+test_expect_failure '#24: at root' '
cat >24/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/24.git
setup: worktree: (null)
test_repo 24
'
-test_expect_success '#24: in subdir' '
+test_expect_failure '#24: in subdir' '
cat >24/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/24.git
setup: worktree: (null)
cd ..
'
-test_expect_success '#28: at root' '
+test_expect_failure '#28: at root' '
cat >28/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/28.git
setup: worktree: (null)
test_repo 28
'
-test_expect_success '#28: in subdir' '
+test_expect_failure '#28: in subdir' '
cat >28/sub/expected <<EOF &&
setup: git_dir: $TRASH_DIRECTORY/28.git
setup: worktree: (null)