Subject: [WIP PATCH 05/18] t1510: setup case #2

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Sun, 24 Oct 2010 19:11:37 +0700

---
 t/t1510-repo-setup.sh |   63 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh
index d450b4a..20ad6d4 100755
--- a/t/t1510-repo-setup.sh
+++ b/t/t1510-repo-setup.sh
@@ -139,4 +139,67 @@ EOF
 	GIT_WORK_TREE=non-existent test_repo 1/sub
 '
 
+#
+# case #2
+#
+############################################################
+#
+# Input:
+#
+#  - GIT_WORK_TREE is not set
+#  - GIT_DIR is set
+#  - core.worktree is not set
+#  - .git is a directory
+#  - core.bare is not set, cwd is outside .git
+#
+# Output:
+#
+#  - worktree is at original cwd
+#  - cwd is unchanged
+#  - prefix is NULL
+#  - git_dir is set to $GIT_DIR
+#  - cwd can't be outside worktree
+
+test_expect_success '#2: setup' '
+	unset GIT_DIR GIT_WORK_TREE &&
+	mkdir 2 2/sub &&
+	cd 2 && git init && cd ..
+'
+
+test_expect_success '#2: at root' '
+	cat >2/expected <<EOF &&
+$TRASH_DIRECTORY/2/.git
+$TRASH_DIRECTORY/2
+$TRASH_DIRECTORY/2
+EOF
+	GIT_DIR="$TRASH_DIRECTORY/2/.git" test_repo 2
+'
+
+test_expect_success '#2: in subdir' '
+	cat >2/sub/expected <<EOF &&
+$TRASH_DIRECTORY/2/.git
+$TRASH_DIRECTORY/2/sub
+$TRASH_DIRECTORY/2/sub
+EOF
+	GIT_DIR="$TRASH_DIRECTORY/2/.git" test_repo 2/sub
+'
+
+test_expect_success '#2: relative GIT_DIR at root' '
+	cat >2/expected <<EOF &&
+.git
+$TRASH_DIRECTORY/2
+$TRASH_DIRECTORY/2
+EOF
+	GIT_DIR=.git test_repo 2
+'
+
+test_expect_success '#2: relative GIT_DIR in subdir' '
+	cat >2/sub/expected <<EOF &&
+../.git
+$TRASH_DIRECTORY/2/sub
+$TRASH_DIRECTORY/2/sub
+EOF
+	GIT_DIR=../.git test_repo 2/sub
+'
+
 test_done
-- 
1.7.0.2.445.gcbdb3