Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
submodules: recursive
- name: Run BATS tests
run: ./tests/bats/bin/bats tests/*.bats
run: ./bats/bin/bats tests/*.bats

lua:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[submodule "tests/bats"]
path = tests/bats
[submodule "bats"]
path = bats
url = https://github.com/bats-core/bats-core.git
[submodule "tests/test_helper/bats-support"]
path = tests/test_helper/bats-support
Expand Down
15 changes: 10 additions & 5 deletions shell/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,16 @@ _project_open_root() {
_project_open_scan() {
local root
root="$(_project_open_root)"
# Projects live at <root>/<category>/<project> and always hold a .git, so one
# find at that fixed depth lists them; submodules sit deeper and fall out.
find "${root}" -mindepth 3 -maxdepth 3 -name '.git' 2>/dev/null |
sed 's#/\.git$##' |
LC_ALL=C sort
{
# Direct repos: root/cat/proj/.git
find "${root}" -mindepth 3 -maxdepth 3 -name '.git' 2>/dev/null |
sed 's#/\.git$##'
# Nested repos: root/cat/proj/sub/.git → root/cat/proj
# Handles WordPress projects where bedrock/trellis hold the .git instead.
# Submodules at depth 5+ are still excluded.
find "${root}" -mindepth 4 -maxdepth 4 -name '.git' 2>/dev/null |
sed 's#/[^/]*/\.git$##'
} | LC_ALL=C sort -u
}

_project_open_cache_file() {
Expand Down
21 changes: 18 additions & 3 deletions tests/project_open.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ setup() {

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

# shell/aliases sources ${HOME}/.dotfiles/shell/os.sh, so point HOME at a
# temp dir whose .dotfiles symlinks to this repo. That lets the suite run
Expand All @@ -46,7 +49,7 @@ teardown() {
@test "scan finds category/project dirs and excludes nested submodules" {
local out
out="$(_project_open_scan | sed "s#^${ROOT}/##" | LC_ALL=C sort | tr '\n' ',')"
assert_equal "${out}" "misc/khuey,mods/HoldFast,wordpress/acme,wordpress/beta,"
assert_equal "${out}" "misc/khuey,mods/HoldFast,wordpress/acme,wordpress/beta,wordpress/clinimed,"
}

@test "po_refresh creates the cache file" {
Expand Down Expand Up @@ -106,6 +109,11 @@ teardown() {
assert_output "${ROOT}/wordpress/acme"
}

@test "resolve maps a nested-git project (no root .git) to its path" {
run _project_open_resolve clinimed
assert_output "${ROOT}/wordpress/clinimed"
}

@test "resolve of an unknown name is empty" {
run _project_open_resolve nope
assert_output ''
Expand All @@ -115,7 +123,7 @@ teardown() {
po_refresh
local out
out="$(_project_open_projects | LC_ALL=C sort | tr '\n' ',')"
assert_equal "${out}" "HoldFast,acme,beta,khuey,"
assert_equal "${out}" "HoldFast,acme,beta,clinimed,khuey,"
}

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

@test "project_open descends into bedrock for a nested-git project" {
po_refresh
local dir
dir="$(cd / && project_open clinimed >/dev/null 2>&1 && pwd)"
assert_equal "${dir}" "${ROOT}/wordpress/clinimed/bedrock"
}

@test "project_open <name> <subdir> cds into the subdir" {
po_refresh
local dir
Expand Down
Loading