1

I am trying to clone a project from the private git repository git clone gitolite@10.10.10.55:/Intel/BareRepos/lteue.git using the Python script. The problem with my script is I need to enter the password manually every time for cloning the project from local repository.

Is there any pythonic way to clone the project without entering any password manually?

This is the script which I had written.

import os

path = path/to/save/cloned/project

os.chdir(path)

os.system("git clone gitolite@10.10.10.55:/Intel/BareRepos/lteue.git")#...Clonning
halfer
  • 19,824
  • 17
  • 99
  • 186
user8339266
  • 11
  • 1
  • 2
  • https://stackoverflow.com/a/12467358/7976758 – phd Jul 20 '17 at 15:54
  • Possible duplicate of [Gitolite git clone requires ssh password](https://stackoverflow.com/questions/12467293/gitolite-git-clone-requires-ssh-password) – LangeHaare Jul 20 '17 at 16:05

3 Answers3

1

The best thing to do it use public/private keys. However, I don't know gitolite at all. (You may want to add that into the tags.)

Note, I would not recommend doing the following, unless you know no one unauthorized will see your script. This is bad security practice, etc.

If you really want this to be in Python, I would use subprocess.Popen.

from subprocess import Popen, PIPE

password = 'rather_secret_string'

proc = Popen(['git', 'clone', 'gitolite@10.10.10.55:/Intel/BareRepos/lteue.git'], stdin=PIPE)

proc.communicate(password)
  • This doesn't work. Git probably requires some delay before accepting input or it is using some other mechanism to take input – tejasvi88 Jul 27 '21 at 12:33
0

I would use subprocess to do this.

So you use Popen() to create a process and then you can communicate with it. You do need to use PIPE to get your password to the input.

from subprocess import Popen, PIPE
process = Popen(["git", "clone", "gitolite@10.10.10.55:/Intel/BareRepos/lteue.git"], stdin=PIPE)

process.communicate('password that I send')

Something like this will probably work.

You can also use Pexpect but I am not familiar with that library.

Tristan
  • 2,000
  • 17
  • 32
0

I don't know why the above answers didn't work for me. But I come up with the new solution which will work for sure and it is very simple.

Here is my complete code:

import os
import sys
import shutil

path        =   "/path/to/store/your/cloned/project" 
clone       =   "git clone gitolite@10.10.10.55:/Intel/BareRepos/lteue.git" 

os.system("sshpass -p your_password ssh user_name@your_localhost")
os.chdir(path) # Specifying the path where the cloned project has to be copied
os.system(clone) # Cloning

print "\n CLONED SUCCESSFULLY.! \n"
Manje
  • 411
  • 4
  • 7