Skip to contentSkip to conversation

t1900: cover linked worktrees and separate git dirs

PATCH In review Jialong Wang 2 participants 2 messages Mar 18 – Mar 21 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 t1900: cover linked worktrees and separate git dirs

Add repo-info coverage for repositories accessed through a linked\nworktree and through a worktree created with --separate-git-dir.\n\nThese layouts are already supported by the current implementation, but\nare not exercised by t1900-repo-info.sh yet. Cover both the lines and\nnul output formats for layout.bare and layout.shallow in these cases.

---
 t/t1900-repo-info.sh | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
t/t1900-repo-info.sh +39 -0
index a9eb07abe8..f85ed232c2 100755
@@ -69,6 +69,45 @@ test_repo_info 'object.format = sha1 is retrieved correctly' \
 test_repo_info 'object.format = sha256 is retrieved correctly' \
 	'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
 
+test_expect_success 'setup linked worktree' '
+	git init main &&
+	git -C main worktree add ../linked
+'
+
+test_expect_success 'linked worktree layout values are retrieved correctly in lines format' '
+	cat >expect <<-\EOF &&
+	layout.bare=false
+	layout.shallow=false
+	EOF
+	git -C linked repo info layout.bare layout.shallow >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'linked worktree layout values are retrieved correctly in nul format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expect &&
+	git -C linked repo info --format=nul layout.bare layout.shallow >actual &&
+	test_cmp_bin expect actual
+'
+
+test_expect_success 'setup repository created with --separate-git-dir' '
+	git init --separate-git-dir=separate.git separate-worktree
+'
+
+test_expect_success 'separate-git-dir layout values are retrieved correctly in lines format' '
+	cat >expect <<-\EOF &&
+	layout.bare=false
+	layout.shallow=false
+	EOF
+	git -C separate-worktree repo info layout.bare layout.shallow >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'separate-git-dir layout values are retrieved correctly in nul format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expect &&
+	git -C separate-worktree repo info --format=nul layout.bare layout.shallow >actual &&
+	test_cmp_bin expect actual
+'
+
 test_expect_success 'values returned in order requested' '
 	cat >expect <<-\EOF &&
 	layout.bare=false
Signature · 1 line
2.51.0
#2 lore raw

Hi Jialong,

Thanks for the patch.

Quoted 4 lines · Jialong Wang

Add repo-info coverage for repositories accessed through a linked\nworktree and through a worktree created with --separate-git-dir.\n\nThese layouts are already supported by the current implementation, but\nare not exercised by t1900-repo-info.sh yet. Cover both the lines and\nnul output formats for layout.bare and layout.shallow in these cases.

---

I noticed that line breaks in the submitted data are escaped as \n characters. Even if you send the patch using a different tool, you should still check the mailing list to see how it looks, right? ;)

Quoted 43 lines
  t/t1900-repo-info.sh | 39 +++++++++++++++++++++++++++++++++++++++
  1 file changed, 39 insertions(+)
t/t1900-repo-info.sh +32 -0
index a9eb07abe8..f85ed232c2 100755
@@ -69,6 +69,45 @@ test_repo_info 'object.format = sha1 is retrieved correctly' \
  test_repo_info 'object.format = sha256 is retrieved correctly' \
  	'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
 
+test_expect_success 'setup linked worktree' '
+	git init main &&
+	git -C main worktree add ../linked
+'
+
+test_expect_success 'linked worktree layout values are retrieved correctly in lines format' '
+	cat >expect <<-\EOF &&
+	layout.bare=false
+	layout.shallow=false
+	EOF
+	git -C linked repo info layout.bare layout.shallow >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'linked worktree layout values are retrieved correctly in nul format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expect &&
+	git -C linked repo info --format=nul layout.bare layout.shallow >actual &&
+	test_cmp_bin expect actual
+'
+
+test_expect_success 'setup repository created with --separate-git-dir' '
+	git init --separate-git-dir=separate.git separate-worktree
+'
+
+test_expect_success 'separate-git-dir layout values are retrieved correctly in lines format' '
+	cat >expect <<-\EOF &&
+	layout.bare=false
+	layout.shallow=false
+	EOF
+	git -C separate-worktree repo info layout.bare layout.shallow >actual &&
+	test_cmp expect actual
+'

t/t1900-repo-info.sh test_repo_info 'object.format = sha1 is retrieved correctly' \ · line 113

Quoted 10 lines
t/t1900-repo-info.sh +7 -0
+
+test_expect_success 'separate-git-dir layout values are retrieved correctly in nul format' '
+	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expect &&
+	git -C separate-worktree repo info --format=nul layout.bare layout.shallow >actual &&
+	test_cmp_bin expect actual
+'
+
  test_expect_success 'values returned in order requested' '
  	cat >expect <<-\EOF &&
  	layout.bare=false

The patch itself looks fine. The 'git repo info' command seems to be a relatively new one, so I think adding a test script is necessary...

...except one thing to mention:

t/t1900-repo-info.sh test_repo_info 'object.format = sha1 is retrieved correctly' \ · line 74

Quoted 3 lines
t/t1900-repo-info.sh +3 -0
+test_expect_success 'setup linked worktree' '
+	git init main &&
+	git -C main worktree add ../linked

Since the main repo here is an empty, can a linked worktree be created? Here, HEAD does not point to a valid object, and there is no commit available checkout. I think it would be better to create a commit using test_commit first.

Regards,

Yuchen