Skip to content

Unable to launch venv for pre-commit from GutHubDesktop #19520

Closed

Description

@Nniol

The problem

Hi,
I have a pre-commit hook and it works from the command line if I do
git add file1.py
git add file2.py
git commit -m "a message"

however if I run it from the desktop I get

Activating virtual environment...
.git/hooks/pre-commit: line 5: C:/Work/GitHubRepo/WatsonX/pilots/FK/orchestration/venv_fk_watsonx/Scripts/activate: No such file or directory
Failed to activate virtual environment. Commit aborted.

This is the same if Use the /c/Work path too

#!/bin/bash

echo "Activating virtual environment..."
#source /c/Work/GitHubRepo/WatsonX/pilots/FK/orchestration/venv_fk_watsonx/Scripts/activate
source C:/Work/GitHubRepo/WatsonX/pilots/FK/orchestration/venv_fk_watsonx/Scripts/activate

if [ $? -ne 0 ]; then
    echo "Failed to activate virtual environment. Commit aborted."
    exit 1
fi

echo "Running pybabel command as a pre-commit hook..."
pybabel init -D prompt -i locales/sv/prompt.pot -o locales/sv/LC_MESSAGES/prompt.po -l en -w 130
pybabel init -D prompt -i locales/en/prompt.pot -o locales/en/LC_MESSAGES/prompt.po -l en -w 130


if [ $? -ne 0 ]; then
    echo "pybabel command failed! Commit aborted."
    exit 1
fi

echo "Adding to commit"
git add locales/sv/LC_MESSAGES/prompt.po
git add locales/en/LC_MESSAGES/prompt.po

echo "pybabel command executed successfully. Proceeding with commit..."
exit 0

Release version

Version 3.4.8 (x64)

Operating system

Windows 11

Steps to reproduce the behavior

Use the pre-commit and it fails

Log files

No response

Screenshots

image

Additional context

No response

Pinned by niik

Activity

  1. added
    triage
    on Nov 8, 2024
  2. steveward commented on Nov 8, 2024

    @steveward
    Contributor

    @Nniol thanks for the issue. There are some known issues with hooks, since GitHub Desktop doesn't inherit the same environment. You can try running github . from the command line to open GitHub Desktop, which sometimes gets things working. Let me know if that helps.

  3. added
    more-info-needed
    and removed
    triage
    on Nov 8, 2024
  4. Nniol commented on Nov 11, 2024

    @Nniol
    Author

    @steveward
    running github . from the repo base dir on my drive made no difference, still got the same issue

  5. removed
    more-info-needed
    on Nov 11, 2024
  6. niik commented on Jan 14, 2026

    @niik
    Member

    Yesterday we shipped GitHub Desktop 3.5.5-beta1 to our beta channel with improved support for hooks related to committing.

    Screenshot showing the GitHub Desktop commit form as a pre-commit hook is running

    The support is experimental and currently limited to our beta channel. While we believe that this release resolved this issue we're looking for real-world feedback so if you have the ability we'd appreciate it if you could download our beta channel and give it a spin. Ensure the experimental hooks support it's enabled by going to Settings -> Git -> Hooks and making sure the "Load Git hook environment variables from shell" is ticked.

    Screenshot showing the hook settings dialog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions