git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Reinstate the old behaviour when GIT_DIR is set and GIT_WORK_TREE is unset

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 11, 2007, 05:17 UTC
Message-ID
<7vhcn6ps4j.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vk5s3ry0v.fsf@assigned-by-dhcp.cox.net>
Subject: [PATCH] Revert 4465f410 and add tests

checkout-index --prefix=<path> does not need a working tree, even when run from inside a bare repository.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Junio C Hamano <gitster@pobox.com> writes:
 > Uwe Kleine-König  <ukleinek@informatik.uni-freiburg.de> writes:
 >
 >> I don't know if you planed to make 
 >>
 >> 	git checkout-index --prefix=/tmp/tra -a
 >>
 >> work (again) in a bare repo.  Probably not, so it's no surprise that it
 >> still doesn't work.
 >
 > I think it is now safe to revert that NEED_WORK_TREE change
 > in git.c for checkout-index.
 How does this look?  I think the second test (no GIT_DIR, just
 being in a bare repository and specifying --prefix to redirect
 the output elsewhere) never worked even before the current
 work-tree feature was started (none of v1.4.4.4, v1.5.0, nor
 v1.5.2 worked that way), so this is not even "work again", but
 more like "now works".  Later tests with exported GIT_DIR would
 work with or without reverting the NEED_WORK_TREE change in
 git.c, so in that sense reverting is probably not such a good
 idea to begin with.  I dunno.
 git.c                            |    3 +-
 t/t2008-checkout-index-prefix.sh |   78 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100755 t/t2008-checkout-index-prefix.sh
diff --git a/git.c b/git.c
index f8c4545..bafbb4b 100644
--- a/git.c
+++ b/git.c
@@ -315,8 +315,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "branch", cmd_branch, RUN_SETUP },
 		{ "bundle", cmd_bundle },
 		{ "cat-file", cmd_cat_file, RUN_SETUP },
-		{ "checkout-index", cmd_checkout_index,
-			RUN_SETUP | NEED_WORK_TREE},
+		{ "checkout-index", cmd_checkout_index, RUN_SETUP},
 		{ "check-ref-format", cmd_check_ref_format },
 		{ "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE },
 		{ "cherry", cmd_cherry, RUN_SETUP },
diff --git a/t/t2008-checkout-index-prefix.sh b/t/t2008-checkout-index-prefix.sh
new file mode 100755
index 0000000..7727f07
--- /dev/null
+++ b/t/t2008-checkout-index-prefix.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+test_description='checkout-index --prefix=foo/'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+	mkdir filfre &&
+	>frotz &&
+	>filfre/nitfol &&
+	git update-index --add frotz filfre/nitfol
+
+'
+
+rm -fr f*
+
+mv .git repo.git || exit ;# very bad
+GIT_DIR="$(pwd)/repo.git"
+GIT_CONFIG="$GIT_DIR/config" git config core.bare true
+
+test_expect_success 'checkout with --prefix' '
+
+	(
+		cd repo.git &&
+		git checkout-index --prefix=../f- -a
+	) &&
+	test -f f-frotz &&
+	test -d f-filfre &&
+	test -f f-filfre/nitfol
+
+'
+
+export GIT_DIR
+
+rm -fr f*
+
+test_expect_success 'checkout with --prefix and GIT_DIR (0)' '
+
+	(
+		cd repo.git &&
+		git checkout-index --prefix=../f/ -a
+	) &&
+	test -d f &&
+	test -f f/frotz &&
+	test -d f/filfre &&
+	test -f f/filfre/nitfol
+
+'
+
+rm -fr f*
+
+test_expect_success 'checkout with --prefix and GIT_DIR (1)' '
+
+	git checkout-index --prefix=f/ -a &&
+	test -d f &&
+	test -f f/frotz &&
+	test -d f/filfre &&
+	test -f f/filfre/nitfol
+
+'
+
+rm -fr f*
+
+test_expect_success 'checkout with --prefix and GIT_DIR (2)' '
+
+	mkdir f &&
+	(
+		cd f && git checkout-index --prefix=../f1/ -a
+	) &&
+	test -d f1 &&
+	test -f f1/frotz &&
+	test -d f1/filfre &&
+	test -f f1/filfre/nitfol
+
+'
+
+test_done
Previous: Junio C HamanoNext: Uwe Kleine-König
Message 11 of 12 in “checkout-index needs a working tree”
  1. checkout-index needs a working treeJohannes Schindelin, Aug 4, 2007
  2. Junio C HamanoAug 4, 2007
  3. Johannes SchindelinAug 5, 2007
  4. Uwe Kleine-KönigAug 9, 2007
  5. Johannes SchindelinAug 10, 2007
  6. Junio C HamanoAug 10, 2007
  7. Johannes SchindelinAug 10, 2007
  8. Reinstate the old behaviour when GIT_DIR is set and GIT_WORK_TREE is unsetJunio C Hamano, Aug 10, 2007
  9. Uwe Kleine-KönigAug 10, 2007
  10. Junio C HamanoAug 10, 2007
  11. Junio C HamanoAug 11, 2007
  12. checkout-index doc: use --work-dir in the export exampleUwe Kleine-König, Aug 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.