Skip to content

Commit 2322010

Browse files
committed
fix(shell): extend project_open scan to find nested-git projects
WordPress projects whose .git lives inside bedrock/ and trellis/ subdirectories (rather than at the project root) were invisible to the depth-3 scan. Add a depth-4 pass that maps sub-repo paths back to their parent project directory, deduplicated with sort -u. Move bats submodule into bin/ and add test fixtures and cases covering this nested-git structure.
1 parent 2b0f421 commit 2322010

5 files changed

Lines changed: 31 additions & 15 deletions

File tree

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
submodules: recursive
2727
- name: Run BATS tests
28-
run: ./tests/bats/bin/bats tests/*.bats
28+
run: ./bin/bats/bin/bats tests/*.bats
2929

3030
lua:
3131
runs-on: ubuntu-latest

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[submodule "tests/bats"]
2-
path = tests/bats
1+
[submodule "bin/bats"]
2+
path = bin/bats
33
url = https://github.com/bats-core/bats-core.git
44
[submodule "tests/test_helper/bats-support"]
55
path = tests/test_helper/bats-support

shell/aliases

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,16 @@ _project_open_root() {
275275
_project_open_scan() {
276276
local root
277277
root="$(_project_open_root)"
278-
# Projects live at <root>/<category>/<project> and always hold a .git, so one
279-
# find at that fixed depth lists them; submodules sit deeper and fall out.
280-
find "${root}" -mindepth 3 -maxdepth 3 -name '.git' 2>/dev/null |
281-
sed 's#/\.git$##' |
282-
LC_ALL=C sort
278+
{
279+
# Direct repos: root/cat/proj/.git
280+
find "${root}" -mindepth 3 -maxdepth 3 -name '.git' 2>/dev/null |
281+
sed 's#/\.git$##'
282+
# Nested repos: root/cat/proj/sub/.git → root/cat/proj
283+
# Handles WordPress projects where bedrock/trellis hold the .git instead.
284+
# Submodules at depth 5+ are still excluded.
285+
find "${root}" -mindepth 4 -maxdepth 4 -name '.git' 2>/dev/null |
286+
sed 's#/[^/]*/\.git$##'
287+
} | LC_ALL=C sort -u
283288
}
284289

285290
_project_open_cache_file() {

tests/project_open.bats

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ setup() {
1313
XDG_CACHE_HOME="$(temp_make)"
1414
export XDG_CACHE_HOME
1515

16-
# Projects sit at <root>/<category>/<project> and always hold a .git.
17-
# wordpress projects carry a .git alongside their bedrock/site app dir;
18-
# vcpkg is a nested submodule (deeper) that must be excluded from scans.
1916
mkdir -p \
2017
"${ROOT}/mods/HoldFast/.git" \
2118
"${ROOT}/mods/HoldFast/lib" \
@@ -24,7 +21,9 @@ setup() {
2421
"${ROOT}/wordpress/acme/.git" \
2522
"${ROOT}/wordpress/acme/site" \
2623
"${ROOT}/wordpress/beta/.git" \
27-
"${ROOT}/wordpress/beta/bedrock"
24+
"${ROOT}/wordpress/beta/bedrock" \
25+
"${ROOT}/wordpress/itineris/bedrock/.git" \
26+
"${ROOT}/wordpress/itineris/trellis/.git"
2827

2928
# shell/aliases sources ${HOME}/.dotfiles/shell/os.sh, so point HOME at a
3029
# temp dir whose .dotfiles symlinks to this repo. That lets the suite run
@@ -43,10 +42,10 @@ teardown() {
4342
temp_del "${TEST_HOME}"
4443
}
4544

46-
@test "scan finds category/project dirs and excludes nested submodules" {
45+
@test "scan finds category/project dirs and excludes itineris submodules" {
4746
local out
4847
out="$(_project_open_scan | sed "s#^${ROOT}/##" | LC_ALL=C sort | tr '\n' ',')"
49-
assert_equal "${out}" "misc/khuey,mods/HoldFast,wordpress/acme,wordpress/beta,"
48+
assert_equal "${out}" "misc/khuey,mods/HoldFast,wordpress/acme,wordpress/beta,wordpress/itineris,"
5049
}
5150

5251
@test "po_refresh creates the cache file" {
@@ -106,6 +105,11 @@ teardown() {
106105
assert_output "${ROOT}/wordpress/acme"
107106
}
108107

108+
@test "resolve maps a itineris-git project (no root .git) to its path" {
109+
run _project_open_resolve itineris
110+
assert_output "${ROOT}/wordpress/itineris"
111+
}
112+
109113
@test "resolve of an unknown name is empty" {
110114
run _project_open_resolve nope
111115
assert_output ''
@@ -115,7 +119,7 @@ teardown() {
115119
po_refresh
116120
local out
117121
out="$(_project_open_projects | LC_ALL=C sort | tr '\n' ',')"
118-
assert_equal "${out}" "HoldFast,acme,beta,khuey,"
122+
assert_equal "${out}" "HoldFast,acme,beta,itineris,khuey,"
119123
}
120124

121125
@test "targets lists a project's subdirs" {
@@ -164,6 +168,13 @@ teardown() {
164168
assert_equal "${dir}" "${ROOT}/wordpress/acme/site"
165169
}
166170

171+
@test "project_open descends into bedrock for a itineris-git project" {
172+
po_refresh
173+
local dir
174+
dir="$(cd / && project_open itineris >/dev/null 2>&1 && pwd)"
175+
assert_equal "${dir}" "${ROOT}/wordpress/itineris/bedrock"
176+
}
177+
167178
@test "project_open <name> <subdir> cds into the subdir" {
168179
po_refresh
169180
local dir

0 commit comments

Comments
 (0)