Skip to content

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

Open
ianthomas23 wants to merge 4 commits intomainfrom
askpass
Open

Add support for entering user credentials to access remote private repos#116
ianthomas23 wants to merge 4 commits intomainfrom
askpass

Conversation

@ianthomas23
Copy link
Member

@ianthomas23 ianthomas23 commented Mar 6, 2026

This is PR #104 resubmitted from a branch on this upstream repo rather than a branch on my fork, so that it has access to the secrets defined here. Comments from previous PR reproduced (see that PR for screencast):

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.

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 Mar 6, 2026
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 79.24528% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.25%. Comparing base (e0f7ab9) to head (66aaa13).

Files with missing lines Patch % Lines
src/utils/input_output.cpp 72.72% 9 Missing ⚠️
src/utils/credentials.cpp 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #116      +/-   ##
==========================================
+ Coverage   86.83%   87.25%   +0.42%     
==========================================
  Files          60       60              
  Lines        2340     2378      +38     
  Branches      275      282       +7     
==========================================
+ Hits         2032     2075      +43     
+ Misses        308      303       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ianthomas23
Copy link
Member Author

OK, this is good to go now.

Once this is merged, any PRs submitted from this repo will have access to the secret and will all of the remote tests. PRs submitted from forks of this repo will not have access to the secret and those tests will be skipped.

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