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

Function to parse author and committer information from environment #3751

Open
joshtriplett opened this issue Apr 25, 2016 · 4 comments · May be fixed by #6706
Open

Function to parse author and committer information from environment #3751

joshtriplett opened this issue Apr 25, 2016 · 4 comments · May be fixed by #6706

Comments

@joshtriplett
Copy link
Contributor

git_signature_default parses the user.name and user.email values from git_config, but does not allow for other sources of that information. Per man git-commit-tree:

       author and
       committer information is taken from the following environment
       variables, if set:

           GIT_AUTHOR_NAME
           GIT_AUTHOR_EMAIL
           GIT_AUTHOR_DATE
           GIT_COMMITTER_NAME
           GIT_COMMITTER_EMAIL
           GIT_COMMITTER_DATE

       (nb "<", ">" and "\n"s are stripped)

       In case (some of) these environment variables are not set, the
       information is taken from the configuration items user.name and
       user.email, or, if not present, the environment variable EMAIL

While the existing behavior of git_signature_default should likely not change to take environment variables into account, I'd suggest adding a git_signature_author_env and git_signature_committer_env that do. Those would be the appropriate defaults to pass when creating a commit, for any program mimicking the git command-line tools.

cpoerschke added a commit to cpoerschke/libgit2 that referenced this issue Nov 12, 2017
(Function to parse author and committer information from environment)
paulroub added a commit to paulroub/libgit2 that referenced this issue Apr 1, 2020
Use GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL if available (or
GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL)

Fall back to EMAIL if GIT_AUTHOR_EMAIL/GIT_COMMITTER_EMAIL is not available

Use the default user info (user.name, user.email) as last resorts.

Return GIT_ENOTFOUND if we don't have enough info for a signature
paulroub added a commit to paulroub/libgit2 that referenced this issue Apr 2, 2020
Use GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL if available (or
GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL)

Fall back to EMAIL if GIT_AUTHOR_EMAIL/GIT_COMMITTER_EMAIL is not available

Use the default user info (user.name, user.email) as last resorts.

Return GIT_ENOTFOUND if we don't have enough info for a signature
paulroub pushed a commit to paulroub/libgit2 that referenced this issue Sep 8, 2021
Use GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL if available (or
GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL)

Fall back to EMAIL if GIT_AUTHOR_EMAIL/GIT_COMMITTER_EMAIL is not available

Use the default user info (user.name, user.email) as last resorts.

Return GIT_ENOTFOUND if we don't have enough info for a signature
@venlinz
Copy link

venlinz commented Apr 28, 2022

Is this issue still not resolved, I'd like to work on this issue seems achievable to me. Let me know.
Thanks for creating a great library for us. Thank you.

@ethomson
Copy link
Member

I think that it's not, you're welcome to it @venkatesh-coder

@venlinz
Copy link

venlinz commented Apr 28, 2022

Thanks @ethomson, I will try my best. I will ask questions if I need more clarification.

@venlinz
Copy link

venlinz commented Apr 29, 2022

as @joshtriplett mentioned, I created functions git_signature_author_env and git_signature_committer_env that gets environment variables mentioned in man page for git-commit and stores them as git_signature struct. I just want to clarify some things

  • there are functions like git_commit_create, git_commit__create_internal and git_commit__create_buffer_internal (first two functions are wrappers for git_commit__create_buffer_internal) that sets author and committer details. which function best fits to use git_signature_author_env and git_signatue_committer_env to change author and committer.
  • I think git_commit_create is right function because others part of the code might use git_commit__create_buffer_internal or git_commit__create_internal for other purposes the git_commit__create_buffer_internal function being the lowest level function which writes to commit buf.
  • can I use the git_signature_author_env and git_signature_committer_env to change the parameters author and committer that being passed to git_commit__create_internal in git_commit_create
    My assumptions might be wrong please help me.
    Thank you.

u-quark added a commit to u-quark/libgit2 that referenced this issue 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: libgit2#3751

Prior work:
 * libgit2#4409
 * libgit2#5479
 * libgit2#6290
@u-quark u-quark linked a pull request Dec 21, 2023 that will close this issue
u-quark added a commit to u-quark/libgit2 that referenced this issue Jan 14, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants