fix gitea.py

This commit is contained in:
2025-04-08 09:45:38 +02:00
parent c2747e884d
commit 90776bfeef
2 changed files with 17 additions and 16 deletions

View File

@ -80,15 +80,14 @@ def change_to_gitea(doit, *repos):
dirty = True dirty = True
if write_when_new(doit, '.git/hooks/pre-commit', PRE_COMMIT_HOOK): if write_when_new(doit, '.git/hooks/pre-commit', PRE_COMMIT_HOOK):
dirty = True dirty = True
if doit:
dothis = False dothis = False
try: try:
if parser.get('credential', 'helper') != str(gitdir / hooks / 'get_gitea_token'): if parser.get('credential', 'helper') != str(gitdir / hooks / 'get_gitea_token'):
dothis = True dothis = True
print('need to change gitea credential helper') print('need to change gitea credential helper')
except Exception: except Exception as e:
dothis = True dothis = True
print('missing gitea credential helper') print('missing gitea credential helper', e)
try: try:
if parser.get('remote "origin"', 'url') != GITEA_URL % repo: if parser.get('remote "origin"', 'url') != GITEA_URL % repo:
dothis = True dothis = True
@ -98,6 +97,7 @@ def change_to_gitea(doit, *repos):
print('missing remote url') print('missing remote url')
if dothis: if dothis:
dirty = True dirty = True
if doit:
os.system(f'git config credential.helper "{os.getcwd()}/.git/hooks/get_gitea_token"') os.system(f'git config credential.helper "{os.getcwd()}/.git/hooks/get_gitea_token"')
os.system(f'git remote set-url origin {GITEA_URL}') os.system(f'git remote set-url origin {GITEA_URL}')
finally: finally:

View File

@ -19,6 +19,7 @@ from pathlib import Path
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from ipaddress import IPv4Interface from ipaddress import IPv4Interface
from os.path import getmtime from os.path import getmtime
from gitea import change_to_gitea
def exit(): def exit():