From cddf70bcddb1b4a8dba922a86b5db05ce9965f5b Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Thu, 17 Apr 2025 16:19:22 +0200 Subject: [PATCH] change setuser mechanism rely on the fact the LC_IDENTIFICATION (and other LC_*) environment variables are forwarded from an ssh client to the server --- gitea.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gitea.py b/gitea.py index 815c22c..6183f1b 100644 --- a/gitea.py +++ b/gitea.py @@ -8,25 +8,36 @@ GITEA_URL = 'https://gitea.psi.ch/linse/%s.git' GET_GITEA_TOKEN = """#!/bin/bash if [ -z "$GITEA_TOKEN" ]; then - echo "" 1>&2 - echo "you try to push without setting GITEA_TOKEN" 1>&2 - echo "please use 'setuser ' to identify yourself" 1>&2 - echo "" 1>&2 - echo quit=1 + re='^([0-9a-f]{8:}) ([^ ]*) (.*)?$' + if [[ "$LC_IDENTIFICATION" =~ $re ]]; then + export GITEA_TOKEN=${BASH_REMATCH[1]} + export GIT_AUTHOR_NAME=${BASH_REMATCH[3]} + else + echo "" 1>&2 + echo "you try to push without setting GITEA_TOKEN" 1>&2 + echo "please use 'setuser ' to identify yourself" 1>&2 + echo "" 1>&2 + echo quit=1 + fi else if [ "$1" == "get" ]; then echo "connecting with gitea token for $GIT_AUTHOR_NAME" 1>&2 fi - echo username=_ + echo "username=_" echo "password=$GITEA_TOKEN" fi """ PRE_COMMIT_HOOK = """#!/bin/bash +re='^([0-9a-f]{8:}) ([^ ]*) (.*)?$' +if [[ "$LC_IDENTIFICATION" =~ $re ]]; then + export GIT_AUTHOR_EMAIL=${BASH_REMATCH[2]} + export GIT_AUTHOR_NAME=${BASH_REMATCH[3]} +fi if [ "$GIT_AUTHOR_NAME" == "PREVENT_DEFAULT" ]; then echo '' - echo 'You tried to commit without specified author' - echo "please execute 'setuser ' to identify yourself" + echo 'You try to commit without specified author' + echo "please execute 'setuser ' to identify yourself" echo 'or add the author with: git commit --author=' echo '' exit 1