A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/77958226/clone-ssh-git-repositories-using-python-3 below:

github - Clone ssh git repositories using python 3

I have this Python Script that clones a list of length n of repositories using ssh.

import pandas as pd
import time
import git
import sys
import os

counter = 0

#excel reader 
resources = pd.read_excel("C:\\Users\\camiMrtzCode\Documents\Desarrollos\\Proyecto\\Data\\Prueba.xlsx", sheet_name='Recursos', usecols='A,F')
#Se crea la lista de proj + Repos
uaAndRepo = []
for index, row in recursos.iterrows():
    uaAndRepo.append(row.to_list())

#Folder where the repos are going to be cloned
carpetaDescarga = "repositorios"

# SO Detection
if sys.platform == "win32":
    cmd = "rmdir " + carpetaDescarga + "/s /q"
else:
    cmd = "rm -rf " + carpetaDescarga

# Folder structure
if os.path.exists(carpetaDescarga):
    os.system(cmd)
os.makedirs(carpetaDescarga)

#Separate in individual lists to usea a conditional 
for i in uaAndRepo:
if i[0] == 'DDET':
    print("No clone")
elif i[0] == 'CDRT':
    print("No clone")
else:
    #Clonar repos
    print("##################################")
    print("     ClONE")
    print("##################################")
    print("\n")
    counter+=1
    nuevoDirectorio = carpetaDescarga + "/" + i[0] + str(counter)
    repo = git.Repo.clone_from(i[1], nuevoDirectorio, branch='develop')
    print("clone ends")
    time.sleep(3)

So when I run the code the first iteration works but when starts with another iteration to clone the next repo I get this error

##################################
 CLONACION DE REPOSITORIO
##################################


Termina la clonacion
##################################
 CLONACION DE REPOSITORIO
##################################


Traceback (most recent call last):
File "c:\Users\camiMrtzCode\Documents\Desarrollos\Proyecto\Scrips\Descarga\mainDownload.py", line 41, in 
<module>
repo = git.Repo.clone_from(i[2], nuevoDirectorio, branch='develop')
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File 
"C:\Users\camiMrtzCode\AppData\Local\Programs\Python\Python312\Lib\site- 
packages\git\repo\base.py", line 1405, in clone_from
return cls._clone(
       ^^^^^^^^^^^
File "C:\Users\camiMrtzCode\AppData\Local\Programs\Python\Python312\Lib\site-packages\git\repo\base.py", line 1302, in _clone
finalize_process(proc, stderr=stderr)
File "C:\Users\camiMrtzCode\AppData\Local\Programs\Python\Python312\Lib\site-packages\git\util.py", line 483, in finalize_process
proc.wait(**kwargs)
File "C:\Users\camiMrtzCode\AppData\Local\Programs\Python\Python312\Lib\site-packages\git\cmd.py", line 657, in wait
raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git clone -v --branch=develop -- ssh://*****[email protected]:camiMrtzCode/planillas-api.git repositorios/camiMrtzCode/camiMrtzCode
stderr: 'Cloning into 'repositorios/camiMrtzCode/camiMrtzCode...
error: unable to write symref for HEAD: Permission denied
fatal: unable to update HEAD

Is not a access or permissions issue, because the first iteration works and clone perfectly the repo, but when the second repo is being cloned the code breaks and send me the error. I don't know if it is just working with one how can I do it to work n times.

Please help, thanks!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4