1

i want execute

git remote add -f origin <repo>

with dulwich. however, i couldn't find something in this direction.

Knows somebody a solution or an alternative in gitpython?

Thanks for ideas.

ikreb
  • 2,133
  • 1
  • 16
  • 35
  • 1
    Don't the [dulwich docs on remote repos](https://www.dulwich.io/docs/tutorial/remote.html) show you what to do? – Daniel Roseman Jan 02 '16 at 15:05
  • My code doesn't work. I get the error socket.gaierror: [Errno -2] Name or service not known – ikreb Jan 04 '16 at 10:46
  • from dulwich.repo import Repo from dulwich.server import DictBackend, TCPGitServer repo = dulwich.repo.Repo.init('remote', mkdir=True) backend = DictBackend({'/': repo}) dul_server = TCPGitServer(backend, 'git://server.com/file.git', 0) threading.Thread(target=dul_server.serve).start() server_address, server_port = dul_server.socket.getsockname() client = dulwich.client.TCPGitClient(server_address.encode('ascii'), server_port) – ikreb Jan 04 '16 at 10:47

1 Answers1

2

In Dulwich master, you can use the dulwich.porcelain.remote_add method:

from dulwich import porcelain
porcelain.remote_add('origin', 'http://github.com/git/git')

In older versions (that don't have porcelain.remote_add) you can use something like:

from dulwich.repo import Repo
c = Repo('.').get_config()
c.set(('remote "origin"', ), "url", "http://github.com/git/git") 
c.write_to_path()
jelmer
  • 2,405
  • 14
  • 27