2012-10-31 50 views
8

Próbuję znaleźć sposób, aby pobrać repozytorium git za pomocą gitPython. Do tej pory to jest to, co wziąłem z oficjalnych dokumentów here.Jak mogę pobrać zdalne repozytorium za pomocą GitPython?

test_remote = repo.create_remote('test', '[email protected]:repo.git') 
repo.delete_remote(test_remote) # create and delete remotes 
origin = repo.remotes.origin # get default remote by name 
origin.refs      # local remote references 
o = origin.rename('new_origin') # rename remotes 
o.fetch()      # fetch, pull and push from and to the remote 
o.pull() 
o.push() 

Faktem jest, że chcę, aby uzyskać dostęp do repo.remotes.origin zrobić pull withouth zmiana nazwy to pochodzenie (origin.rename) W jaki sposób można to osiągnąć? Dzięki.

Odpowiedz

15

udało mi to przez coraz nazwę repo bezpośrednio:

repo = git.Repo('repo_name') 
o = repo.remotes.origin 
o.pull() 
+0

Nazwa 'repo_name' nie jest w rzeczywistości nazwą repozytorium, ale ścieżką do systemu plików do bazy repozytorium git. –

0

W przyjętym odpowiedź mówi, że możliwe jest użycie repo.remotes.origin.pull(), ale wadą jest to, że ukrywa prawdziwe komunikaty o błędach w jego własnym błędów generycznych. Na przykład, gdy rozdzielczość DNS nie działa, wtedy repo.remotes.origin.pull() pojawi się następujący komunikat o błędzie:

git.exc.GitCommandError: 'Error when fetching: fatal: Could not read from remote repository. 
' returned with exit code 2 

Z drugiej strony using git commands with GitPython jak repo.git.pull() pokazuje rzeczywisty błąd:

git.exc.GitCommandError: 'git pull' returned with exit code 1 
stderr: 'ssh: Could not resolve hostname github.com: Name or service not known 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists.' 
0

nadziei szukasz w tym celu:

import git 
g = git.Git('git-repo') 
g.pull('origin','branch-name') 

Wyciąga ostatnie zatwierdzenia dla danego repozytorium i oddziału.

Powiązane problemy