Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use environment variables when creating signatures #6706

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

u-quark
Copy link

@u-quark u-quark commented Dec 21, 2023

When creating an action signature (e.g. for a commit author and committer) read the following environment variables that can override the configuration options:

  • GIT_AUTHOR_NAME is the human-readable name in the "author" field.
  • GIT_AUTHOR_EMAIL is the email for the "author" field.
  • GIT_AUTHOR_DATE is the timestamp used for the "author" field.
  • GIT_COMMITTER_NAME sets the human name for the "committer" field.
  • GIT_COMMITTER_EMAIL is the email address for the "committer" field.
  • GIT_COMMITTER_DATE is used for the timestamp in the "committer" field.
  • EMAIL is the fallback email address in case the user.email configuration value isn't set. If this isn't set, Git falls back to the system user and host names.

This is taken from the git documentation chapter "10.8 Environment Variables":

https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

This PR adds support for reading these environment variables by adding two new functions git_signature_default_author and git_signature_default_committer and deprecates the git_signature_default function.

Fixes: #3751

Prior work:

@ethomson
Copy link
Member

Thank you for the PR - I agree that we need this functionality. I took a quick first pass on the changes and overall, this is an excellent PR. I will take a closer look 🔜 — thanks again.

@u-quark
Copy link
Author

u-quark commented Dec 24, 2023

Hi, thanks for looking into this!

I am also keen on getting this functionality merged! Please let me know if you want a different approach of some specific implementation on this PR, I don't mind changing it.

I am not sure I recreated 100% the CI build environment but I managed to compile with clang with similar features enabled on cmake so hopefully this time CI will pass.

Cheers.

src/libgit2/signature.h Outdated Show resolved Hide resolved
src/libgit2/signature.c Outdated Show resolved Hide resolved
src/util/date.c Outdated Show resolved Hide resolved
tests/libgit2/commit/signature.c Show resolved Hide resolved
@@ -56,11 +102,13 @@ GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const c
* based on that information. It will return GIT_ENOTFOUND if either the
* user.name or user.email are not set.
*
* @deprecated use git_signature_default_author or git_signature_default_committer instead
Copy link
Member

Choose a reason for hiding this comment

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

Let's not deprecate it per se - at least not yet - typically, we would compile that out of builds when DEPRECATE_HARD is defined. It's usually the thing that we do before its eventual removal. Instead, let's adjust the documentation to suggest that git_signature_default_author are probably what people actually want. We can deprecate in a future release if we think that's wise.

And it may be - but I think that there are likely a lot of people who are using this API at the moment. So let's give them some time to adjust.

@ethomson
Copy link
Member

A few minor tweaks requested - thanks for putting this together, I think that this is a really useful improvement. 🙏

When creating an action signature (e.g. for a commit author and
committer) read the following environment variables that can override
the configuration options:

 * `GIT_AUTHOR_NAME` is the human-readable name in the "author" field.
 * `GIT_AUTHOR_EMAIL` is the email for the "author" field.
 * `GIT_AUTHOR_DATE` is the timestamp used for the "author" field.
 * `GIT_COMMITTER_NAME` sets the human name for the "committer" field.
 * `GIT_COMMITTER_EMAIL` is the email address for the "committer" field.
 * `GIT_COMMITTER_DATE` is used for the timestamp in the "committer"
   field.
 * `EMAIL` is the fallback email address in case the user.email
   configuration value isn't set. If this isn't set, Git falls back to
   the system user and host names.

This is taken from the git documentation chapter "10.8 Environment
Variables":

https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

This PR adds support for reading these environment variables by adding
two new functions `git_signature_default_author` and
`git_signature_default_committer` and deprecates the
`git_signature_default` function.

Fixes: libgit2#3751

Prior work:
 * libgit2#4409
 * libgit2#5479
 * libgit2#6290
Also fix some comment formatting.
@u-quark
Copy link
Author

u-quark commented Jan 14, 2024

Thanks of the review @ethomson!

@csware
Copy link
Contributor

csware commented Feb 24, 2024

The usage of environment variables should always be opt-in in libgit2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function to parse author and committer information from environment
3 participants