1

How do I run this git command with gitpython(v2.1.*), please ?

git config --global --add safe.directory "some_dir"

Couldn't find in doc. I tried this:

repo = git.Repo.init(some_dir)
config = repo.config_writer()
config.set_value("user", "email", "[email protected]")
config.set_value("user", "name", "truc")
git_cmd = git.cmd.Git(some_dir)
git_cmd.config("--global", "--add", "safe.directory", some_dir)

But I get this error:

'error: could not lock config file /nonexistant/.gitconfig: No such file or directory'

I'm pretty sure this has something to do with user rights, because if I go to some_dir and directly execute the git command.

  1. as my user, it fails,
  2. as root, it works. But in my Python script config.set_value() commands are working fine for my user, so I guess there might be a way to add safe directory too.

1 Answer 1

1

Indeed an issue with user rights, I realised I did not need to do the update globally.

Nevertheless, correct gitpython syntax was:

config = repo.config_writer()
config.set_value("user", "email", "[email protected]")
config.set_value("user", "name", "truc")
config.set_value("safe", "directory", "some_dir")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.