Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing GitPython from asking for credentials when trying to clone a non-existent remote repo

In the program fragment below, I clone an existing repo from a remote location and it works correctly.

Then I try to clone a non-existent repo, and this time the call to git.Repo.clone_from() requests a name and a password from the keyboard.

Blocking while waiting for keyboard input is highly undesirable in my application, and so if the repo doesn't exist, I want the call to git.Repo.clone_from() to throw an exception instead.

Is there any way to cause that to happen, or to somehow detect whether or not there exists a git repo at an existing URL before I even try to clone it?

import git, shutil

DIRECTORY = '/tmp/clone'


def clone(url):
    print(url)
    shutil.rmtree(DIRECTORY, ignore_errors=True)
    git.Repo.clone_from(url=url, to_path=DIRECTORY, b='master')


clone('https://github.com/ManiacalLabs/BiblioPixelAnimations.git/')
clone('https://github.com/ManiacalLabs/NONEXISTENT.git/')
like image 992
Tom Swirly Avatar asked Nov 29 '25 01:11

Tom Swirly


1 Answers

Putting an empty username and password should do the trick

clone('https://:@github.com/ManiacalLabs/BiblioPixelAnimations.git/')
clone('https://:@github.com/ManiacalLabs/NONEXISTENT.git/')

Note there is :@ before github.com.

like image 116
Shreyash S Sarnayak Avatar answered Dec 01 '25 15:12

Shreyash S Sarnayak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!