From 4f38f6b5bafb1f7f85c7b54d0bb0a0e977cd947c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 28 Aug 2008 20:02:12 +0700 Subject: diff*: fix worktree setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes "git diff", "git diff-files" and "git diff-index" to work correctly under worktree setup. Because diff* family works in many modes and not all of them require worktree, Junio made a nice summary (with a little modification from me): * diff-files is about comparing with work tree, so it obviously needs a work tree; * diff-index also does, except "diff-index --cached" or "diff --cached TREE" * no-index is about random files outside git context, so it obviously doesn't need any work tree; * comparing two (or more) trees doesn't; * comparing two blobs doesn't; * comparing a blob with a random file doesn't; Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- t/t1501-worktree.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 't/t1501-worktree.sh') diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index 2ee88d8a06..8244b3a86f 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -28,6 +28,7 @@ test_rev_parse() { [ $# -eq 0 ] && return } +EMPTY_TREE=$(git write-tree) mkdir -p work/sub/dir || exit 1 mv .git repo.git || exit 1 @@ -106,12 +107,66 @@ test_expect_success 'repo finds its work tree from work tree, too' ' ' test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' ' - cd repo.git/work/sub/dir && + (cd repo.git/work/sub/dir && GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \ git diff --exit-code tracked && echo changed > tracked && ! GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \ - git diff --exit-code tracked + git diff --exit-code tracked) +' +cat > diff-index-cached.expected <<\EOF +:000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A sub/dir/tracked +EOF +cat > diff-index.expected <<\EOF +:000000 100644 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 A sub/dir/tracked +EOF + + +test_expect_success 'git diff-index' ' + GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-index $EMPTY_TREE > result && + test_cmp diff-index.expected result && + GIT_DIR=repo.git git diff-index --cached $EMPTY_TREE > result && + test_cmp diff-index-cached.expected result +' +cat >diff-files.expected <<\EOF +:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M sub/dir/tracked +EOF + +test_expect_success 'git diff-files' ' + GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff-files > result && + test_cmp diff-files.expected result +' + +cat >diff-TREE.expected <<\EOF +diff --git a/sub/dir/tracked b/sub/dir/tracked +new file mode 100644 +index 0000000..5ea2ed4 +--- /dev/null ++++ b/sub/dir/tracked +@@ -0,0 +1 @@ ++changed +EOF +cat >diff-TREE-cached.expected <<\EOF +diff --git a/sub/dir/tracked b/sub/dir/tracked +new file mode 100644 +index 0000000..e69de29 +EOF +cat >diff-FILES.expected <<\EOF +diff --git a/sub/dir/tracked b/sub/dir/tracked +index e69de29..5ea2ed4 100644 +--- a/sub/dir/tracked ++++ b/sub/dir/tracked +@@ -0,0 +1 @@ ++changed +EOF + +test_expect_success 'git diff' ' + GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff $EMPTY_TREE > result && + test_cmp diff-TREE.expected result && + GIT_DIR=repo.git git diff --cached $EMPTY_TREE > result && + test_cmp diff-TREE-cached.expected result && + GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work git diff > result && + test_cmp diff-FILES.expected result ' test_done -- cgit v1.2.3 From 6577f542b3ab64594c7d7a7db752e96be7234fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 28 Aug 2008 20:04:30 +0700 Subject: grep: fix worktree setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unless used with --cached or grepping on a tree, "git grep" will search on working directory, so set up worktree properly Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- t/t1501-worktree.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't/t1501-worktree.sh') diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index 8244b3a86f..c039ee3fd8 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -169,4 +169,9 @@ test_expect_success 'git diff' ' test_cmp diff-FILES.expected result ' +test_expect_success 'git grep' ' + (cd repo.git/work/sub && + GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked) +' + test_done -- cgit v1.2.3 From 87539416fd25bfa62122ddf4f7a7b8794d5d5aa2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 30 Sep 2008 04:03:55 -0400 Subject: tests: grep portability fixes We try to avoid using the "-q" or "-e" options, as they are largely useless, as explained in aadbe44f. There is one exception for "-e" here, which is in t7701 used to produce an "or" of patterns. This can be rewritten as an egrep pattern. This patch also removes use of "grep -F" in favor of the more widely available "fgrep". [sp: Tested on AIX 5.3 by Mike Ralphson, Tested on MinGW by Johannes Sixt] Signed-off-by: Jeff King Tested-by: Mike Ralphson Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce --- t/t1501-worktree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t1501-worktree.sh') diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index c039ee3fd8..f6a6f839a1 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -171,7 +171,7 @@ test_expect_success 'git diff' ' test_expect_success 'git grep' ' (cd repo.git/work/sub && - GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked) + GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked) ' test_done -- cgit v1.2.3 From 72183cb297f614dc2df1c0ed08afac1be27ec35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Fri, 16 Jan 2009 16:37:33 +0100 Subject: Fix gitdir detection when in subdir of gitdir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the current working directory is a subdirectory of the gitdir (e.g. /.git/refs/), then setup_git_directory_gently() will climb its parent directories until it finds itself in a gitdir. However, no matter how many parent directories it climbs, it sets 'GIT_DIR_ENVIRONMENT' to ".", which is obviously wrong. This behaviour affected at least 'git rev-parse --git-dir' and hence caused some errors in bash completion (e.g. customized command prompt when on a detached head and completion of refs). To fix this, we set the absolute path of the found gitdir instead. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- t/t1501-worktree.sh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't/t1501-worktree.sh') diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index c039ee3fd8..1bcadf3eb6 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -92,6 +92,13 @@ cd sub/dir || exit 1 test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/ cd ../../../.. || exit 1 +test_expect_success 'detecting gitdir when cwd is in a subdir of gitdir' ' + (expected=$(pwd)/repo.git && + cd repo.git/refs && + unset GIT_DIR && + test "$expected" = "$(git rev-parse --git-dir)") +' + test_expect_success 'repo finds its work tree' ' (cd repo.git && : > work/sub/dir/untracked && -- cgit v1.2.3 From 8fb3c00d2ea4dad96fe977f8983ba0376e0c4986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Sat, 14 Feb 2009 17:16:28 +0100 Subject: Move 'rev-parse --git-dir' test to t1500 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 72183cb2 (Fix gitdir detection when in subdir of gitdir, 2009-01-16) added a test to 't1501-worktree' to check the behaviour of 'git rev-parse --git-dir' in a special case. However, t1501 is about testing separate work tree setups, and not about basic 'rev-parse' functionality, which is tested in t1500-rev-parse. Therefore, this patch moves that test to t1500. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- t/t1501-worktree.sh | 7 ------- 1 file changed, 7 deletions(-) (limited to 't/t1501-worktree.sh') diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index 27dc6c55d5..f6a6f839a1 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -92,13 +92,6 @@ cd sub/dir || exit 1 test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/ cd ../../../.. || exit 1 -test_expect_success 'detecting gitdir when cwd is in a subdir of gitdir' ' - (expected=$(pwd)/repo.git && - cd repo.git/refs && - unset GIT_DIR && - test "$expected" = "$(git rev-parse --git-dir)") -' - test_expect_success 'repo finds its work tree' ' (cd repo.git && : > work/sub/dir/untracked && -- cgit v1.2.3 From b3100fd5557dbaad4eeb5690336758ef21bb08bb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 16 Dec 2009 10:50:09 -0800 Subject: worktree: don't segfault with an absolute pathspec without a work tree If a command is run with an absolute path as a pathspec inside a bare repository, e.g. "rev-list HEAD -- /home", the code tried to run strlen() on NULL, which is the result of get_git_work_tree(), and segfaulted. It should just fail instead. Currently the function returns NULL even inside .git/ in a repository with a work tree, but that is a separate issue. Signed-off-by: Junio C Hamano --- t/t1501-worktree.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 't/t1501-worktree.sh') diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index f6a6f839a1..74e6443664 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -174,4 +174,19 @@ test_expect_success 'git grep' ' GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked) ' +test_expect_success 'git commit' ' + ( + cd repo.git && + GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done + ) +' + +test_expect_success 'absolute pathspec should fail gracefully' ' + ( + cd repo.git || exit 1 + git config --unset core.worktree + test_must_fail git log HEAD -- /home + ) +' + test_done -- cgit v1.2.3 From 288123f01cb1b835edbf6e2e188159c2ff858aca Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 21 Jan 2010 19:05:19 -0800 Subject: ignore duplicated slashes in make_relative_path() The function takes two paths, an early part of abs is supposed to match base; otherwise abs is not a path under base and the function returns the full path of abs. The caller can easily confuse the implementation by giving duplicated and needless slashes in these path arguments. Credit for test script, motivation and initial patch goes to Thomas Rast. A follow-up fix (squashed) is by Hannes. Signed-off-by: Junio C Hamano --- t/t1501-worktree.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 't/t1501-worktree.sh') diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index 74e6443664..9df301211c 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -189,4 +189,10 @@ test_expect_success 'absolute pathspec should fail gracefully' ' ) ' +test_expect_success 'make_relative_path handles double slashes in GIT_DIR' ' + : > dummy_file + echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file && + git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file +' + test_done -- cgit v1.2.3