Skip to content

Comments

Add support for entering user credentials to access remote private repos#104

Open
ianthomas23 wants to merge 1 commit intoQuantStack:mainfrom
ianthomas23:askpass
Open

Add support for entering user credentials to access remote private repos#104
ianthomas23 wants to merge 1 commit intoQuantStack:mainfrom
ianthomas23:askpass

Conversation

@ianthomas23
Copy link
Member

This PR adds support for entering and using credentials (username and password) to authenticate https requests to allow git clone, git fetch and git push to remote private repositories on github. This only works for linux and macos builds, the wasm build will be done separately. Screencast of this in action:

credentials.mp4

This uses the private git2cpp-test-private repository, and authentication is performed using a fine-grained github Personal Access Token (PAT) which I paste into the terminal. Note that the PAT is not echoed to screen so that it cannot be seen by others, which is the same behaviour that occurs with normal git. Credentiials are not stored or cached at all at this stage, so have to be entered separately for each clone, fetch or push subcommand.

Most of the new functionality here is in the new user_credentials function that is a libgit2 callback to prompt the user for a username and password. Actually using a PAT means that the username is ignored, but it may not be ignored for other remotes than github. The format of the callback function follows libgit2 standard practice but calling our own input_prompt function.

The new tests use an environment variable GIT2CPP_TEST_PRIVATE_TOKEN. If this is not present then the relevant tests are skipped, if it is present those tests are run. This env var needs to be a fine-grained PAT for the git2cpp-test-private repo with appropriate read and write permissions - I will pass one the token to other maintainers here via private messages. Once you have it locally you can run the tests using it via

GIT2CPP_TEST_PRIVATE_TOKEN=<whatever-the-token-is> pytest -v

This env var could be set permanently in your bash_profile or similar, which isn't very secure as all other processes on your computer will be able to read it, but since it only allows access to a specific github repo used for test purposes only this cannot do much damage. The token expires in one year.

I have added GIT2CPP_TEST_PRIVATE_TOKEN as a repository secret so that CI can run all the tests.

@ianthomas23 ianthomas23 added the enhancement New feature or request label Feb 23, 2026
@@ -0,0 +1,74 @@
#include "ansi_code.hpp"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed this from output.cpp to input_output.cpp as it is now a mixture of input and output functions and scope classes (and the header file too).

class cursor_hider : noncopyable_nonmovable
{
public:
cursor_hider(bool hide = true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows nested scope objects to disable the cursor when doing a long git clone, but re-enable it for the username and password entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant