Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How can I override the home path during Repo() creation due to unsafe repository (REPO is owned by someone else) error #1429

Answered by Byron
avatar-lavventura asked this question in Q&A
Discussion options

I am using git version 2.35.2. I want to apply following solution How can I specify custom global gitconfig path? due to this error fatal: unsafe repository (REPO is owned by someone else) with ubuntu 20.04 (Related: actions/checkout#760).

HOME=/home/marco/.silly/ git commit -m "silly configuration"

Is it possible to do same work around during Repo createtion, where I can override the home path?

The way I create my repo in python:
repo = git.Repo(".", search_parent_directories=True) here could I send HOME as an env variable?

You must be logged in to vote

It should be possible to change the environment of the python process itself, which should affect spawned commands as well.

I'd be surprised though that changing the home affects that user that git sees when checking it if that is the intend, I could be missing something though.

This article has a few suggestions on how to workaround this issue.

Replies: 2 comments 1 reply

Comment options

It should be possible to change the environment of the python process itself, which should affect spawned commands as well.

I'd be surprised though that changing the home affects that user that git sees when checking it if that is the intend, I could be missing something though.

This article has a few suggestions on how to workaround this issue.

You must be logged in to vote
0 replies
Answer selected by avatar-lavventura
Comment options

@Byron When I run: check_output(["env", f"HOME={home_dir}", "git", "status"]), I was able to trick git, I have use solution here: https://stackoverflow.com/a/52227100/2402577. But I am not sure how this could be applied into git.Repo() call, might os.environ['HOME'] = 'my_path' be the solution.

You must be logged in to vote
1 reply
Comment options

Article was the solution, where I had to add the safe.path but trick git to add it into .gitconfig of another user who owns the repo. I had to do:

check_output(["env", f"HOME={home_dir}", "git", "config", "--global", "--add", "safe.directory", path])

which could also be done easily using GitPython:

os.environ['HOME'] = 'my_path' # this helped 
repo.config("--global", "--add", "safe.directory", path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #1428 on April 13, 2022 23:42.

AltStyle によって変換されたページ (->オリジナル) /