@@ -28,6 +28,7 @@ test_rev_parse() {
2828 [ $# -eq 0 ] && return
2929}
3030
31+ EMPTY_TREE=$( git write-tree)
3132mkdir -p work/sub/dir || exit 1
3233mv .git repo.git || exit 1
3334
@@ -106,12 +107,71 @@ test_expect_success 'repo finds its work tree from work tree, too' '
106107'
107108
108109test_expect_success ' _gently() groks relative GIT_DIR & GIT_WORK_TREE' '
109- cd repo.git/work/sub/dir &&
110+ ( cd repo.git/work/sub/dir &&
110111 GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
111112 git diff --exit-code tracked &&
112113 echo changed > tracked &&
113114 ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
114- git diff --exit-code tracked
115+ git diff --exit-code tracked)
116+ '
117+ cat > diff-index-cached.expected << \EOF
118+ :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A sub/dir/tracked
119+ EOF
120+ cat > diff-index.expected << \EOF
121+ :000000 100644 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 A sub/dir/tracked
122+ EOF
123+
124+
125+ test_expect_success ' git diff-index' '
126+ GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-index $EMPTY_TREE > result &&
127+ test_cmp diff-index.expected result &&
128+ GIT_DIR=repo.git git diff-index --cached $EMPTY_TREE > result &&
129+ test_cmp diff-index-cached.expected result
130+ '
131+ cat > diff-files.expected << \EOF
132+ :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M sub/dir/tracked
133+ EOF
134+
135+ test_expect_success ' git diff-files' '
136+ GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-files > result &&
137+ test_cmp diff-files.expected result
138+ '
139+
140+ cat > diff-TREE.expected << \EOF
141+ diff --git a/sub/dir/tracked b/sub/dir/tracked
142+ new file mode 100644
143+ index 0000000..5ea2ed4
144+ --- /dev/null
145+ +++ b/sub/dir/tracked
146+ @@ -0,0 +1 @@
147+ +changed
148+ EOF
149+ cat > diff-TREE-cached.expected << \EOF
150+ diff --git a/sub/dir/tracked b/sub/dir/tracked
151+ new file mode 100644
152+ index 0000000..e69de29
153+ EOF
154+ cat > diff-FILES.expected << \EOF
155+ diff --git a/sub/dir/tracked b/sub/dir/tracked
156+ index e69de29..5ea2ed4 100644
157+ --- a/sub/dir/tracked
158+ +++ b/sub/dir/tracked
159+ @@ -0,0 +1 @@
160+ +changed
161+ EOF
162+
163+ test_expect_success ' git diff' '
164+ GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff $EMPTY_TREE > result &&
165+ test_cmp diff-TREE.expected result &&
166+ GIT_DIR=repo.git git diff --cached $EMPTY_TREE > result &&
167+ test_cmp diff-TREE-cached.expected result &&
168+ GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff > result &&
169+ test_cmp diff-FILES.expected result
170+ '
171+
172+ test_expect_success ' git grep' '
173+ (cd repo.git/work/sub &&
174+ GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked)
115175'
116176
117177test_done
0 commit comments