From a66175a7b9918e5190a2f09460ddfddb61f1b30d Mon Sep 17 00:00:00 2001 From: Ivan Uribe Date: Wed, 25 Feb 2026 09:49:54 -0500 Subject: [PATCH] feat: execute comand skip docker exec interactive --- .dev-hooks.yml | 4 ++++ src/dev_tools_hooks/hooks/pre-commit | 25 ++++++++++++++++++++----- src/dev_tools_hooks/hooks/pre-push | 25 ++++++++++++++++++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.dev-hooks.yml b/.dev-hooks.yml index 268b95f..2e5d4a4 100644 --- a/.dev-hooks.yml +++ b/.dev-hooks.yml @@ -13,6 +13,10 @@ pre-push: enabled: true skip_branch_validation: false + # Django smart tests - run tests only for modified apps + django_smart_tests: true + django_test_command: "pytest -n auto" + commands: - name: "Check CLI" run: "venv/bin/dev-hooks --version" diff --git a/src/dev_tools_hooks/hooks/pre-commit b/src/dev_tools_hooks/hooks/pre-commit index eab6902..ff7d388 100644 --- a/src/dev_tools_hooks/hooks/pre-commit +++ b/src/dev_tools_hooks/hooks/pre-commit @@ -77,11 +77,18 @@ yaml_get_commands() { fi awk -v section="$section" ' + function emit() { + if (name != "" && cmd != "") { + print name "|" cmd "|" cmd_docker + name=""; cmd=""; cmd_docker="" + } + } $0 ~ "^"section":" { in_section=1; next } - in_section && /^[a-zA-Z]/ { in_section=0 } + in_section && /^[a-zA-Z]/ { emit(); in_section=0; in_commands=0 } in_section && /^ commands:/ { in_commands=1; next } - in_commands && /^ [a-zA-Z]/ { in_commands=0 } + in_commands && /^ [a-zA-Z]/ { emit(); in_commands=0 } in_commands && /^ - name:/ { + emit() gsub(/^ - name:[ ]*/, "") gsub(/^["'\'']|["'\'']$/, "") name=$0 @@ -89,8 +96,14 @@ yaml_get_commands() { in_commands && /^ run:/ { gsub(/^ run:[ ]*/, "") gsub(/^["'\'']|["'\'']$/, "") - print name "|" $0 + cmd=$0 + } + in_commands && /^ docker:/ { + gsub(/^ docker:[ ]*/, "") + gsub(/^["'\'']|["'\'']$/, "") + cmd_docker=$0 } + END { emit() } ' "$file" } @@ -240,14 +253,16 @@ run_commands() { [ -z "$line" ] && continue local name="${line%%|*}" - local cmd="${line#*|}" + local rest="${line#*|}" + local cmd="${rest%%|*}" + local cmd_docker="${rest##*|}" echo -e "${BLUE}▶${NC} ${WHITE}${BOLD}${name}${NC}" echo -e " ${DIM}${cmd}${NC}" local full_cmd="$cmd" - if [ "$docker_enabled" = "true" ]; then + if [ "$docker_enabled" = "true" ] && [ "$cmd_docker" != "false" ]; then if [ "$docker_compose" = "true" ]; then full_cmd="docker-compose -f $compose_file exec -T $docker_container $cmd" else diff --git a/src/dev_tools_hooks/hooks/pre-push b/src/dev_tools_hooks/hooks/pre-push index 066c4ad..c1987f5 100755 --- a/src/dev_tools_hooks/hooks/pre-push +++ b/src/dev_tools_hooks/hooks/pre-push @@ -86,11 +86,18 @@ yaml_get_commands() { fi awk ' + function emit() { + if (name != "" && cmd != "") { + print name "|" cmd "|" cmd_docker + name=""; cmd=""; cmd_docker="" + } + } /^pre-push:/ { in_prepush=1; next } - in_prepush && /^[a-zA-Z]/ { in_prepush=0 } + in_prepush && /^[a-zA-Z]/ { emit(); in_prepush=0; in_commands=0 } in_prepush && /^ commands:/ { in_commands=1; next } - in_commands && /^ [a-zA-Z]/ { in_commands=0 } + in_commands && /^ [a-zA-Z]/ { emit(); in_commands=0 } in_commands && /^ - name:/ { + emit() gsub(/^ - name:[ ]*/, "") gsub(/^["'\'']|["'\'']$/, "") name=$0 @@ -98,8 +105,14 @@ yaml_get_commands() { in_commands && /^ run:/ { gsub(/^ run:[ ]*/, "") gsub(/^["'\'']|["'\'']$/, "") - print name "|" $0 + cmd=$0 + } + in_commands && /^ docker:/ { + gsub(/^ docker:[ ]*/, "") + gsub(/^["'\'']|["'\'']$/, "") + cmd_docker=$0 } + END { emit() } ' "$file" } @@ -374,14 +387,16 @@ run_commands() { [ -z "$line" ] && continue local name="${line%%|*}" - local cmd="${line#*|}" + local rest="${line#*|}" + local cmd="${rest%%|*}" + local cmd_docker="${rest##*|}" echo -e "${BLUE}▶${NC} ${WHITE}${BOLD}${name}${NC}" echo -e " ${DIM}${cmd}${NC}" local full_cmd="$cmd" - if [ "$docker_enabled" = "true" ]; then + if [ "$docker_enabled" = "true" ] && [ "$cmd_docker" != "false" ]; then if [ "$docker_compose" = "true" ]; then full_cmd="docker-compose -f $compose_file exec -T $docker_container $cmd" else