1

I have a GUI application that uses the pythongit library to perform updates. When a user is authenticating with a SSH key to the repository the updates works smoothly, but when a username/password authentication is used, then a prompt will appear on the terminal where the application was started (leaving the user with the GUI interface open thinking it's frozen).

Is there a way to determine if the repo is using SSH or password authentication and then possibly manually prompt for a username/password first and passing it to the fetch call?

Here is the basic functionality:

def repo_pull(self, git_path):
    try:
        repo = Repo(git_path)
    except InvalidGitRepositoryError as igre:
        raise ValueError('Get the project as a Git repository (no archives)')

    commits_ahead = repo.iter_commits('origin/master..master')

    if sum(1 for c in commits_ahead) > 0:
        raise ValueError("Can't pull from git; local repository has unpushed commits!")

    origin = repo.remote()
    try:
        origin.fetch()
    except GitCommandError as gce:
        ,,,

1 Answer 1

1

I found a way to see if the remote is accessed with HTTPS or SSH

def _determine_authentication(self, repo):
    config_reader = repo.config_reader()
    config_reader.read()
    url = config_reader.get_value('remote "origin"', 'url')
    return 'pwd' if url.startswith('http') else 'ssh'
Sign up to request clarification or add additional context in comments.

2 Comments

'ssh' if '@' in url is a wrong test because an http(s) URL may contain @: https://[email protected]/path. HTTP(S) URLs start with http, so your check should be 'pwd' if url.startswith('http') else 'ssh'.
Note, however, that this will falsely indicate that [email protected]:path/to/repo.git is being accessed via http, when it's actually ssh with user httplogin. That's not fatal since the user could write ssh://[email protected]/path/to/repo.git instead, as his URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.