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

[PATCH v2 6/8] environment.c: fix incorrect git_graft_file initialization

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jul 29, 2014, 13:50 UTC
Message-ID
<1406641831-2390-7-git-send-email-pclouds@gmail.com>
In-Reply-To
<1406641831-2390-1-git-send-email-pclouds@gmail.com>

"info/grafts" should be part of the "common repository" when accessed from a linked checkout (iow $GIT_COMMON_DIR/info/grafts, not $GIT_DIR/info/grafts).

git_path("info/grafts") returns correctly, even without this fix, because it detects that $GIT_GRAFT_FILE is not set, so it goes with the common rule: anything except sparse-checkout in 'info' belongs to common repo. But get_graft_file() would return a wrong value and that one is used for setting grafts up.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 environment.c          |  2 +-
 t/t0060-path-utils.sh  |  1 +
 t/t2025-checkout-to.sh | 18 ++++++++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/environment.c b/environment.c
index 50ed40a..d5b0788 100644
--- a/environment.c
+++ b/environment.c
@@ -157,7 +157,7 @@ static void setup_git_env(void)
 					   "objects", &git_db_env);
 	git_index_file = git_path_from_env(INDEX_ENVIRONMENT, git_dir,
 					   "index", &git_index_env);
-	git_graft_file = git_path_from_env(GRAFT_ENVIRONMENT, git_dir,
+	git_graft_file = git_path_from_env(GRAFT_ENVIRONMENT, git_common_dir,
 					   "info/grafts", &git_graft_env);
 	if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
 		check_replace_refs = 0;
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index da82aab..93605f4 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -269,6 +269,7 @@ test_git_path GIT_COMMON_DIR=bar logs/HEAD                .git/logs/HEAD
 test_git_path GIT_COMMON_DIR=bar objects                  bar/objects
 test_git_path GIT_COMMON_DIR=bar objects/bar              bar/objects/bar
 test_git_path GIT_COMMON_DIR=bar info/exclude             bar/info/exclude
+test_git_path GIT_COMMON_DIR=bar info/grafts              bar/info/grafts
 test_git_path GIT_COMMON_DIR=bar info/sparse-checkout     .git/info/sparse-checkout
 test_git_path GIT_COMMON_DIR=bar remotes/bar              bar/remotes/bar
 test_git_path GIT_COMMON_DIR=bar branches/bar             bar/branches/bar
diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh
index 8a00310..508993f 100755
--- a/t/t2025-checkout-to.sh
+++ b/t/t2025-checkout-to.sh
@@ -81,4 +81,22 @@ test_expect_success 'checkout from a bare repo without --to' '
 	)
 '
 
+test_expect_success 'checkout with grafts' '
+	test_when_finished rm .git/info/grafts &&
+	test_commit abc &&
+	SHA1=`git rev-parse HEAD` &&
+	test_commit def &&
+	test_commit xyz &&
+	echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
+	cat >expected <<-\EOF &&
+	xyz
+	abc
+	EOF
+	git log --format=%s -2 >actual &&
+	test_cmp expected actual &&
+	git checkout --detach --to grafted master &&
+	git --git-dir=grafted/.git log --format=%s -2 >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.1.0.rc0.78.gc0d8480
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 29 of 36 in “nd/multiple-work-trees follow-ups”
  1. 0/5 nd/multiple-work-trees follow-upsNguyễn Thái Ngọc Duy, Jul 23, 2014
  2. 1/5 gitrepository-layout.txt: s/ignored/ignored if/Nguyễn Thái Ngọc Duy, Jul 23, 2014
  3. 2/5 prune --repos: fix uninitialized accessNguyễn Thái Ngọc Duy, Jul 23, 2014
  4. Junio C HamanoJul 23, 2014
  5. Duy NguyenJul 24, 2014
  6. 3/5 checkout --to: no auto-detach if the ref is already checked outNguyễn Thái Ngọc Duy, Jul 23, 2014
  7. Michael J GruberJul 23, 2014
  8. Junio C HamanoJul 23, 2014
  9. Duy NguyenJul 24, 2014
  10. Junio C HamanoJul 24, 2014
  11. Michael J GruberJul 25, 2014
  12. Junio C HamanoJul 30, 2014
  13. Junio C HamanoJul 30, 2014
  14. Duy NguyenAug 27, 2014
  15. Junio C HamanoAug 27, 2014
  16. Junio C HamanoJul 23, 2014
  17. Duy NguyenJul 24, 2014
  18. Junio C HamanoJul 24, 2014
  19. Junio C HamanoJul 24, 2014
  20. 4/5 checkout --to: fix dangling pointers in remove_junk()Nguyễn Thái Ngọc Duy, Jul 23, 2014
  21. 5/5 environment.c: fix incorrect git_graft_file initializationNguyễn Thái Ngọc Duy, Jul 23, 2014
  22. Junio C HamanoJul 23, 2014
  23. 0/8 nd/multiple-work-trees follow-upsNguyễn Thái Ngọc Duy, Jul 29, 2014
  24. 1/8 gitrepository-layout.txt: s/ignored/ignored if/Nguyễn Thái Ngọc Duy, Jul 29, 2014
  25. 2/8 checkout: no need to call check_linked_checkouts if head_ref is NULLNguyễn Thái Ngọc Duy, Jul 29, 2014
  26. 3/8 prune --repos: fix uninitialized accessNguyễn Thái Ngọc Duy, Jul 29, 2014
  27. 4/8 checkout: no auto-detach if the ref is already checked outNguyễn Thái Ngọc Duy, Jul 29, 2014
  28. 5/8 checkout --to: fix dangling pointers in remove_junk()Nguyễn Thái Ngọc Duy, Jul 29, 2014
  29. 6/8 environment.c: fix incorrect git_graft_file initializationNguyễn Thái Ngọc Duy, Jul 29, 2014
  30. 7/8 checkout: prefix --to argument properly when cwd is movedNguyễn Thái Ngọc Duy, Jul 29, 2014
  31. Junio C HamanoJul 29, 2014
  32. Duy NguyenJul 30, 2014
  33. 8/8 checkout --to: do not touch existing target directoryNguyễn Thái Ngọc Duy, Jul 29, 2014
  34. Junio C HamanoJul 30, 2014
  35. Duy NguyenJul 31, 2014
  36. Junio C HamanoJul 31, 2014

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.