Skip to content

Commit 4d3c390

Browse files
jdxclaude
andcommitted
test(git): cover bare-repo dotfile manager scenario
Regression test for the GIT_DIR/GIT_WORK_TREE support, exercising both the libgit2 and shell-git code paths. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent d955d1b commit 4d3c390

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

test/bare_repo_env_vars.bats

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bats
2+
3+
# Regression tests for #831 — support bare-repo dotfile managers (YADM, etc.)
4+
# that set GIT_DIR and GIT_WORK_TREE instead of using a `.git` in the worktree.
5+
6+
setup() {
7+
load 'test_helper/common_setup'
8+
_common_setup
9+
10+
BARE_DIR="$TEST_TEMP_DIR/bare.git"
11+
WORK_TREE="$TEST_TEMP_DIR/home"
12+
git init --bare "$BARE_DIR"
13+
mkdir -p "$WORK_TREE"
14+
15+
export GIT_DIR="$BARE_DIR"
16+
export GIT_WORK_TREE="$WORK_TREE"
17+
cd "$WORK_TREE"
18+
19+
echo "initial" > file.txt
20+
git add file.txt
21+
git commit -m "initial commit"
22+
}
23+
24+
teardown() {
25+
unset GIT_DIR
26+
unset GIT_WORK_TREE
27+
_common_teardown
28+
}
29+
30+
_write_hk_config() {
31+
cat <<EOF > hk.pkl
32+
amends "$PKL_PATH/Config.pkl"
33+
hooks {
34+
["check"] { steps { ["echo"] { check = "echo checked {{files}}" } } }
35+
["pre-commit"] { steps { ["echo"] { check = "echo pre-commit {{files}}" } } }
36+
}
37+
EOF
38+
}
39+
40+
@test "hk builtins works with no repo config" {
41+
# Outside any repo, with no hk.pkl, should not panic
42+
cd "$TEST_TEMP_DIR"
43+
unset GIT_DIR
44+
unset GIT_WORK_TREE
45+
run hk builtins
46+
assert_success
47+
assert_output --partial "prettier"
48+
}
49+
50+
@test "hk check honors GIT_DIR/GIT_WORK_TREE" {
51+
_write_hk_config
52+
git add hk.pkl
53+
git commit -m "add hk config"
54+
55+
run hk check --all
56+
assert_success
57+
assert_output --partial "checked"
58+
}
59+
60+
@test "hk check with HK_LIBGIT2=0 honors GIT_DIR/GIT_WORK_TREE" {
61+
_write_hk_config
62+
git add hk.pkl
63+
git commit -m "add hk config"
64+
65+
HK_LIBGIT2=0 run hk check --all
66+
assert_success
67+
assert_output --partial "checked"
68+
}
69+
70+
@test "hk install writes hooks to the bare-repo hooks dir" {
71+
_write_hk_config
72+
73+
run hk install
74+
assert_success
75+
assert_file_exists "$BARE_DIR/hooks/pre-commit"
76+
}
77+
78+
@test "hk uninstall removes hooks from the bare-repo hooks dir" {
79+
_write_hk_config
80+
81+
hk install
82+
assert_file_exists "$BARE_DIR/hooks/pre-commit"
83+
84+
run hk uninstall
85+
assert_success
86+
assert_file_not_exists "$BARE_DIR/hooks/pre-commit"
87+
}

0 commit comments

Comments
 (0)