Skip to content

Commit 9a05bb9

Browse files
committed
fix(shell): extend project_open scan to find nested-git projects
1 parent 2b0f421 commit 9a05bb9

5 files changed

Lines changed: 31 additions & 11 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ setup() {
1515

1616
# Projects sit at <root>/<category>/<project> and always hold a .git.
1717
# wordpress projects carry a .git alongside their bedrock/site app dir;
18+
# clinimed-style projects have .git only inside bedrock/trellis subdirs;
1819
# vcpkg is a nested submodule (deeper) that must be excluded from scans.
1920
mkdir -p \
2021
"${ROOT}/mods/HoldFast/.git" \
@@ -24,7 +25,9 @@ setup() {
2425
"${ROOT}/wordpress/acme/.git" \
2526
"${ROOT}/wordpress/acme/site" \
2627
"${ROOT}/wordpress/beta/.git" \
27-
"${ROOT}/wordpress/beta/bedrock"
28+
"${ROOT}/wordpress/beta/bedrock" \
29+
"${ROOT}/wordpress/clinimed/bedrock/.git" \
30+
"${ROOT}/wordpress/clinimed/trellis/.git"
2831

2932
# shell/aliases sources ${HOME}/.dotfiles/shell/os.sh, so point HOME at a
3033
# temp dir whose .dotfiles symlinks to this repo. That lets the suite run
@@ -46,7 +49,7 @@ teardown() {
4649
@test "scan finds category/project dirs and excludes nested submodules" {
4750
local out
4851
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,"
52+
assert_equal "${out}" "misc/khuey,mods/HoldFast,wordpress/acme,wordpress/beta,wordpress/clinimed,"
5053
}
5154

5255
@test "po_refresh creates the cache file" {
@@ -106,6 +109,11 @@ teardown() {
106109
assert_output "${ROOT}/wordpress/acme"
107110
}
108111

112+
@test "resolve maps a nested-git project (no root .git) to its path" {
113+
run _project_open_resolve clinimed
114+
assert_output "${ROOT}/wordpress/clinimed"
115+
}
116+
109117
@test "resolve of an unknown name is empty" {
110118
run _project_open_resolve nope
111119
assert_output ''
@@ -115,7 +123,7 @@ teardown() {
115123
po_refresh
116124
local out
117125
out="$(_project_open_projects | LC_ALL=C sort | tr '\n' ',')"
118-
assert_equal "${out}" "HoldFast,acme,beta,khuey,"
126+
assert_equal "${out}" "HoldFast,acme,beta,clinimed,khuey,"
119127
}
120128

121129
@test "targets lists a project's subdirs" {
@@ -164,6 +172,13 @@ teardown() {
164172
assert_equal "${dir}" "${ROOT}/wordpress/acme/site"
165173
}
166174

175+
@test "project_open descends into bedrock for a nested-git project" {
176+
po_refresh
177+
local dir
178+
dir="$(cd / && project_open clinimed >/dev/null 2>&1 && pwd)"
179+
assert_equal "${dir}" "${ROOT}/wordpress/clinimed/bedrock"
180+
}
181+
167182
@test "project_open <name> <subdir> cds into the subdir" {
168183
po_refresh
169184
local dir

0 commit comments

Comments
 (0)