0

Q+A (I'm posting this in case someone else goes down this niche rabbit hole - as it took me a while to figure this out).

Scenario: You've decided to run a unit-test which 'plays' with creating a local git repo using GitPython. Your tests run in Tox in a GitHub action which runs an Ubuntu docker image - which has correct .gitconfig file with user.name and user.email. You can even see this correct config if you use GitPython's GitConfigParser or just read the file at git.config.get_config_path.
With all the above looking good, you run your tests, which contain something like:

with open(os.path.join(remote_repo.working_dir, 'readme.md'), 'w') as file:
    file.write('# Remote\n')
remote_repo.git.add(A=True)
remote_repo.git.commit(m=commit_text)

in GH and get failures with something like:

          raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
  E           git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  E             cmdline: git commit -m Initial commit
  E             stderr: 'Author identity unknown
  E           
  E           *** Please tell me who you are.
  E           
  E           Run
  E           
  E             git config --global user.email "[email protected]"
  E             git config --global user.name "Your Name"
  E           
  E           to set your account's default identity.
  E           Omit --global to set the identity only in this repository.
  E           
  E           fatal: unable to auto-detect email address (got '**********.(none)')'

EDIT Answer moved the answers below.

3
  • 1
    Maybe just passenv = HOME ?
    – phd
    Commented Dec 18, 2022 at 19:41
  • @phd Excellent. Updating.
    – shaib
    Commented Dec 19, 2022 at 9:13
  • 1
    Please move Solution and Explanation to the answer. You can answer your own question.
    – phd
    Commented Dec 19, 2022 at 9:42

1 Answer 1

0

I tried so many things... but the last desperate attempt of calling remote_repo.git.config('--global', 'user.name', 'some user') failed with the message that '$HOME' wasn't set - which finally led me to the...

Solution: Add the following to tox.ini's testenv section [edited after comment]:

[testenv]
  passenv = HOME
  ...

Explanation: Tox doesn't set the HOME environment variable, and it appears GitPython's repo.git.commit command only reads the config if HOME is set.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.