Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions oca_port/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import contextlib
import pathlib
import re
import os
import subprocess
from collections import abc

Expand All @@ -15,6 +16,11 @@
PO_FILE_REGEX = re.compile(r".*i18n/.+\.pot?$")


env = os.environ.copy()
extra_path = os.path.expanduser("~/.local/bin")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, why not adding ~/.local/bin to your user's $PATH environment variable? So pre-commit will be found automatically?

For instance, this is what pipx ensurepath command does in ~/.bashrc (but you could do the same in ~/.profile):

# Created by `pipx` on 2026-01-09 17:34:00
export PATH="$PATH:/home/user/.local/bin"

env["PATH"] = extra_path + os.pathsep + env.get("PATH", "")


class Branch:
def __init__(self, repo, name, default_remote=None, check_remote=True):
self.repo = repo
Expand Down Expand Up @@ -317,11 +323,11 @@ def run_pre_commit(repo, hook=None):
untracked_files = set(repo.untracked_files)
# First ensure that 'pre-commit' is initialized for the repository,
# then run it (without checking the return code on purpose)
subprocess.check_call("pre-commit install", shell=True)
subprocess.run("pre-commit install", env=env, shell=True, check=True)
if hook:
subprocess.run(f"pre-commit run {hook}", shell=True)
subprocess.run(f"pre-commit run {hook}", env=env, shell=True)
else:
subprocess.run("pre-commit run -a", shell=True)
subprocess.run("pre-commit run -a", env=env, shell=True)
new_untracked_files = set(repo.untracked_files)
changed_files = {diff.a_path for diff in repo.index.diff(None)}
updated_files = (new_untracked_files | changed_files) - untracked_files
Expand Down