Skip to content

Instantly share code, notes, and snippets.

@maxisandoval37
Last active March 31, 2026 21:26
Show Gist options
  • Select an option

  • Save maxisandoval37/a9bbe29fd33321601fd64a74be0fb9a4 to your computer and use it in GitHub Desktop.

Select an option

Save maxisandoval37/a9bbe29fd33321601fd64a74be0fb9a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
MSG_FILE="${1:-}"
[[ -z "$MSG_FILE" || ! -f "$MSG_FILE" ]] && exit 0
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
[[ -z "$REPO_ROOT" ]] && exit 0
to_windows_path() {
local p="$1"
if command -v cygpath >/dev/null 2>&1; then
cygpath -w "$p"
elif [[ "$p" =~ ^/mnt/([a-zA-Z])/(.*)$ ]]; then
printf '%s:\%s\n' "${BASH_REMATCH[1]^^}" "${BASH_REMATCH[2]//\//\\}"
elif [[ "$p" =~ ^/([a-zA-Z])/(.*)$ ]]; then
printf '%s:\%s\n' "${BASH_REMATCH[1]^^}" "${BASH_REMATCH[2]//\//\\}"
else
printf '%s\n' "$p"
fi
}
resolve_commitg_exe() {
local win_user_home=""
if [[ "$REPO_ROOT" =~ ^(/mnt/[a-zA-Z]/Users/[^/]+) ]]; then
win_user_home="${BASH_REMATCH[1]}"
elif [[ "$REPO_ROOT" =~ ^(/c/Users/[^/]+) ]]; then
win_user_home="${BASH_REMATCH[1]}"
fi
local candidates=(
"$win_user_home/.dotnet/tools/commitg.exe"
"$REPO_ROOT/.git/hooks/commitg.exe"
)
for candidate in "${candidates[@]}"; do
[[ -f "$candidate" ]] && { echo "$candidate"; return 0; }
done
return 1
}
# 1) Camino simple: terminal / PATH
if command -v commitg >/dev/null 2>&1; then
commitg validate --repo "$REPO_ROOT" --file "$MSG_FILE"
exit $?
fi
# 2) Fallback VS 2022: exe Windows + paths Windows
COMMITG_EXE="$(resolve_commitg_exe || true)"
[[ -n "${COMMITG_EXE:-}" ]] || exit 0
MSG_FILE_ABS="$(cd "$(dirname "$MSG_FILE")" && pwd)/$(basename "$MSG_FILE")"
"$COMMITG_EXE" validate \
--repo "$(to_windows_path "$REPO_ROOT")" \
--file "$(to_windows_path "$MSG_FILE_ABS")"
#!/usr/bin/env bash
set -euo pipefail
MSG_FILE="${1:-}"
[[ -z "$MSG_FILE" || ! -f "$MSG_FILE" ]] && exit 0
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
[[ -z "$REPO_ROOT" ]] && exit 0
to_windows_path() {
local p="$1"
if command -v cygpath >/dev/null 2>&1; then
cygpath -w "$p"
elif [[ "$p" =~ ^/mnt/([a-zA-Z])/(.*)$ ]]; then
printf '%s:\%s\n' "${BASH_REMATCH[1]^^}" "${BASH_REMATCH[2]//\//\\}"
elif [[ "$p" =~ ^/([a-zA-Z])/(.*)$ ]]; then
printf '%s:\%s\n' "${BASH_REMATCH[1]^^}" "${BASH_REMATCH[2]//\//\\}"
else
printf '%s\n' "$p"
fi
}
resolve_commitg_exe() {
local win_user_home=""
if [[ "$REPO_ROOT" =~ ^(/mnt/[a-zA-Z]/Users/[^/]+) ]]; then
win_user_home="${BASH_REMATCH[1]}"
elif [[ "$REPO_ROOT" =~ ^(/c/Users/[^/]+) ]]; then
win_user_home="${BASH_REMATCH[1]}"
fi
local candidates=(
"$win_user_home/.dotnet/tools/commitg.exe"
"$REPO_ROOT/.git/hooks/commitg.exe"
)
for candidate in "${candidates[@]}"; do
[[ -f "$candidate" ]] && { echo "$candidate"; return 0; }
done
return 1
}
extract_wi() {
local file="$1"
if grep -Eq '#[0-9]+' "$file"; then
grep -Eo '#[0-9]+' "$file" | head -n1 | tr -d '#'
return 0
fi
if grep -Eqi 'WI:\s*[0-9]+' "$file"; then
grep -Eoi 'WI:\s*[0-9]+' "$file" | head -n1 | tr -dc '0-9'
return 0
fi
if grep -Eqi '^(Closes|Fixes|Resolves)\s+#[0-9]+' "$file"; then
grep -Eoi '^(Closes|Fixes|Resolves)\s+#[0-9]+' "$file" | head -n1 | grep -Eo '[0-9]+'
return 0
fi
return 1
}
WI_ID="$(extract_wi "$MSG_FILE" || true)"
[[ -n "$WI_ID" ]] || exit 0
# 1) Camino simple: terminal / PATH
if command -v commitg >/dev/null 2>&1; then
commitg generate --repo "$REPO_ROOT" --staged --wi "$WI_ID" --out "$MSG_FILE" || exit 0
exit 0
fi
# 2) Fallback VS 2022: exe Windows + paths Windows
COMMITG_EXE="$(resolve_commitg_exe || true)"
[[ -n "${COMMITG_EXE:-}" ]] || exit 0
MSG_FILE_ABS="$(cd "$(dirname "$MSG_FILE")" && pwd)/$(basename "$MSG_FILE")"
"$COMMITG_EXE" generate \
--repo "$(to_windows_path "$REPO_ROOT")" \
--staged \
--wi "$WI_ID" \
--out "$(to_windows_path "$MSG_FILE_ABS")" || exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment