Git hooks spam ImageMagick 'import' usage on every commit (pipx polyglot shebang misdetected as interpreter)

Abierto Apto para principiantes
#3,611 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, shell

Línea de trabajo

Comienza con las plantillas de los hooks post-commit y post-checkout o con el código de generación que contiene la sonda GRAPHIFY_PYTHON; después, compara ambas copias. Reproduce el problema con sh -x en un hook instalado, en un entorno con el comando import de ImageMagick, y verifica que la instalación del hook seguida de un commit o checkout no produzca ningún volcado de uso, mientras el grafo se sigue reconstruyendo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

The installed post-commit / post-checkout git hooks print ImageMagick's import usage dump on every commit and checkout when the graphify launcher uses a #!/bin/sh polyglot shebang (the pipx-installed layout). The graph still rebuilds correctly via the python3 fallback, so it's cosmetic — but it spams several dozen lines of Usage: import [options ...] into the output of every git commit.

Environment

  • graphify (pip package graphifyy) 0.4.12, installed via pipx
  • macOS (Apple Silicon), Homebrew ImageMagick present on PATH (provides a binary named import)

Root cause

The pipx launcher ~/.local/bin/graphify starts with a polyglot shebang that re-execs into the venv Python:

#!/bin/sh
'''exec' "/…/pipx/venvs/graphifyy/bin/python" "$0" "$@"
' '''
import sys
from graphify.__main__ import main

The hook detects the interpreter by reading the launcher's first line:

_SHEBANG=$(head -1 "$GRAPHIFY_BIN" | sed 's/^#![[:space:]]*//')

For this launcher that yields GRAPHIFY_PYTHON=/bin/sh. The hook then validates it with:

if [ -n "$GRAPHIFY_PYTHON" ] && ! "$GRAPHIFY_PYTHON" -c "import graphify" 2>/dev/null; then

which runs /bin/sh -c "import graphify". On any machine with ImageMagick on PATH, import is ImageMagick's screen-capture tool, so it prints its full usage text to stdout (the probe only redirects stderr). The check's exit code still works, so GRAPHIFY_PYTHON is reset and the python3 fallback runs — the graph rebuilds fine, but the usage dump already leaked to the terminal.

sh -x .git/hooks/post-commit trace:

+ GRAPHIFY_PYTHON=/bin/sh
+ /bin/sh -c 'import graphify'
Usage: import [options ...] [ file ]
...
+ GRAPHIFY_PYTHON=
+ python3 -c 'import graphify'   # fallback, works

Suggested fixes (either/both)

  1. Silence the probe's stdout too — it's only used for its exit status:

    ! "$GRAPHIFY_PYTHON" -c "import graphify" >/dev/null 2>&1
    

    (applies to the same probe in both post-commit and post-checkout)

  2. Don't trust a /bin/sh shebang as the interpreter — the launcher is a polyglot; reject shebangs whose basename isn't a python* before probing (or just skip straight to the python3/python fallback when it isn't).

Fix #1 alone removes the noise for any stray interpreter guess; #2 addresses the misdetection at its source.

Workaround

Add >/dev/null 2>&1 to the probe line in the installed .git/hooks/post-commit and .git/hooks/post-checkout, but graphify hook install regenerates them and reintroduces the noise.

Lenguaje dominante
Python
Estrellas
124k
Forks
11.9k
Merge medio
2 h 35 min
PR fusionados (30 d)
6

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Graphify-Labs/graphify

Todos los issues de Graphify-Labs/graphify

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.